Skip to content

Commit

Permalink
fix: singMessage missing method parameter (#139)
Browse files Browse the repository at this point in the history
* fix missing method parameter in signMessage

* improve singMessage UX

* update manifest
  • Loading branch information
BeroBurny authored Apr 7, 2022
1 parent 494b554 commit 1ad693c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/Chainsafe/filsnap.git"
},
"source": {
"shasum": "E+ju1JT5w6Rn0WnCVAvJT4eivkI9ntxDBRgi7I997ps=",
"shasum": "EPeb4AxmyJ5Srkka/uIIvNbnIC5n6BnxLlEIl0ZEI+0=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
24 changes: 15 additions & 9 deletions packages/snap/src/rpc/signMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {getKeyPair} from "../filecoin/account";
import {showConfirmationDialog} from "../util/confirmation";
import {LotusRpcApi} from "../filecoin/types";
import {MessageRequest, SignMessageResponse, SignRawMessageResponse} from "@chainsafe/filsnap-types";
import {messageCreator} from "../util/messageCreator";

export async function signMessage(
wallet: Wallet, api: LotusRpcApi, messageRequest: MessageRequest
Expand All @@ -16,14 +17,15 @@ export async function signMessage(
const gfc = messageRequest.gasfeecap && messageRequest.gasfeecap !== "0" ? messageRequest.gasfeecap : "0";
const nonce = messageRequest.nonce ?? Number(await api.mpoolGetNonce(keypair.address));
const params = messageRequest.params || "";
const method = messageRequest.method || 0;

// create message object
const message: Message = {
from: keypair.address,
gasfeecap: gfc,
gaslimit: gl,
gaspremium: gp,
method: 0, // code for basic transaction
method,
nonce,
params,
to: messageRequest.to,
Expand All @@ -41,15 +43,19 @@ export async function signMessage(
const confirmation = await showConfirmationDialog(
wallet,
{
description: `It will be signed with address: ${message.from}`,
prompt: `Do you want to sign this message?`,
textAreaContent: `from: ${message.from}\n` +
`to: ${message.to}\n` +
`value: ${message.value}\n` +
params ? `params: ${params}\n` : '' +
`gas limit: ${message.gaslimit}\n` +
`gas fee cap: ${message.gasfeecap}\n` +
`gas premium: ${message.gaspremium}\n` +
`with account ${keypair.address}?`
textAreaContent: messageCreator(
[
{message: 'to:', value: message.to},
{message: 'value:', value: message.value !== '0' && message.value},
{message: 'method:', value: message.method},
{message: 'params:', value: message.params},
{message: 'gas limit:', value: message.gaslimit},
{message: 'gas fee cap:', value: message.gasfeecap},
{message: 'gas premium:', value: message.gaspremium},
]
)
},
);

Expand Down
9 changes: 9 additions & 0 deletions packages/snap/src/util/messageCreator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
interface Message {
message: string;
value: unknown | undefined;
}

export const messageCreator = (messages: Message[]): string => messages
.filter(({ value }) => !!value)
.map(({ message, value,}) => message + ' ' + value)
.join('\n');
1 change: 1 addition & 0 deletions packages/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export interface MessageRequest {
gasfeecap?: string;
gaspremium?: string;
nonce?: number;
method?: number;
params?: string;
}

Expand Down

0 comments on commit 1ad693c

Please sign in to comment.