Skip to content

Commit

Permalink
Merge pull request #35 from leapwallet/main
Browse files Browse the repository at this point in the history
Fixed vote message and unknown transaction type UI
  • Loading branch information
leapsamvel authored Aug 28, 2023
2 parents 80d8327 + d88c549 commit fdbf2b7
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/cosmos-snap-provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@leapwallet/cosmos-snap-provider",
"version": "0.1.13",
"version": "0.1.14",
"repository": {
"url": "[email protected]:leapwallet/cosmos-metamask-snap.git"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@leapwallet/metamask-cosmos-snap",
"version": "0.1.13",
"description": "Leapwallet cosmos snap for metamask",
"version": "0.1.14",
"description": "Securely manage keys, connect to Cosmos dapps, and sign transactions.",
"repository": {
"type": "git",
"url": "https://github.com/leapwallet/cosmos-metamask-snap.git"
Expand Down
8 changes: 4 additions & 4 deletions packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"version": "0.1.9",
"description": "Leap wallet sample snap",
"proposedName": "Leap Wallet",
"version": "0.1.13",
"description": "Securely manage keys, connect to Cosmos dapps, and sign transactions.",
"proposedName": "Leap Cosmos Wallet",
"repository": {
"type": "git",
"url": "https://github.com/leapwallet/cosmos-metamask-snap.git"
},
"source": {
"shasum": "7qf7sR/MdDhBsxskH0ugQJ7QUOCt1jp1Z7fLv8xcSo8=",
"shasum": "GS2ctQz5+vyTkeLbo78/qycmuYesidCeNNYqPdZkbGo=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
52 changes: 49 additions & 3 deletions packages/snap/src/helpers/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
ParsedMessage,
ParsedMessageType,
Token,
CosmosGovVoteOption,
} from '@leapwallet/parser-parfait';

import {
convertObjectCasingFromCamelToSnake,
DirectSignDocDecoder,
Expand All @@ -17,6 +19,44 @@ import DENOMS from '../constants/denoms';

const messageParser = new MessageParser();

export const convertVoteOptionToString = (
voteOption: CosmosGovVoteOption | number | null,
): string => {
switch (voteOption) {
case 1:
return 'Yes';
case 2:
return 'Abstain';
case 3:
return 'No';
case 4:
return 'No with Veto';
case CosmosGovVoteOption.YES:
return 'Yes';
case CosmosGovVoteOption.ABSTAIN:
return 'Abstain';
case CosmosGovVoteOption.NO:
return 'No';
case CosmosGovVoteOption.NO_WITH_VETO:
return 'No with Veto';
case CosmosGovVoteOption.UNSPECIFIED:
return 'Unspecified';
default:
return 'Unspecified';
}
};

export const getProposalId = (proposalId: any) => {
if (typeof proposalId === 'string') {
return proposalId;
}

if (typeof proposalId === 'object') {
return proposalId.low;
}
return proposalId;
};

export const formatBigNumber = (n: BigNumber) => {
if (isNaN(n?.toNumber())) {
return '-';
Expand Down Expand Up @@ -83,7 +123,7 @@ export const getSimpleType = (type: string | undefined) => {
return parts[parts.length - 1] ?? '';
};

export const getMessageDetails = (message: ParsedMessage): string => {
export const getMessageDetails = (message: ParsedMessage, raw: any): string => {
switch (message.__type) {
case ParsedMessageType.AuthzExec:
return `${sliceAddress(
Expand Down Expand Up @@ -169,7 +209,9 @@ export const getMessageDetails = (message: ParsedMessage): string => {
message.initialDeposit,
)}`;
case ParsedMessageType.GovVote:
return `Vote ${message.option} on proposal ${message.proposalId}`;
return `Vote ${convertVoteOptionToString(
message.option || raw?.option,
)} on proposal ${getProposalId(message?.proposalId)}`;
case ParsedMessageType.GovDeposit:
return `Deposit ${tokensToString(message?.amount ?? [])} on proposal ${
message.proposalId
Expand Down Expand Up @@ -320,8 +362,12 @@ const parser = {
copyable(`${origin}`),
heading(''),
];

parsedMessages.forEach((msg) => {
return panels.push(heading(`${getMessageDetails(msg.parsed)}`));
const panelMsg = getMessageDetails(msg.parsed, msg.raw);
if (panelMsg !== 'Unknown Transaction Type') {
panels.push(heading(`${getMessageDetails(msg.parsed, msg.raw)}`));
}
});

if (parsedMessages) {
Expand Down

0 comments on commit fdbf2b7

Please sign in to comment.