Skip to content

Commit

Permalink
Add CallSc component for smart contract calls and update confirmation…
Browse files Browse the repository at this point in the history
… dialog
  • Loading branch information
Ben-Rey committed Nov 13, 2024
1 parent 9bf4a52 commit 84505c1
Show file tree
Hide file tree
Showing 3 changed files with 64 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/massalabs/metamask-massa.git"
},
"source": {
"shasum": "GWlYHiEuClZPjO9VXkNBTjjYkIW7nDLSKLL15ADEYvg=",
"shasum": "AbWGAAPhnQAeiVM5K22HpNLXDInm9vR/BkmmqoLjVhA=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
53 changes: 53 additions & 0 deletions packages/snap/src/components/CallSc.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { toMAS } from '@massalabs/massa-web3';
import {
SnapComponent,
Container,
Box,
Heading,
Text,
Section,
Bold,
Copyable,
} from '@metamask/snaps-sdk/jsx';

type CallScProps = {
fee: string;
functionName: string;
at: string;
args: number[];
coins: string;
};

export const CallSc: SnapComponent<CallScProps> = (params: CallScProps) => {
return (
<Container>
<Box>
<Heading>Do you want to call the following smart contract?</Heading>
<Section>
<Text>
<Bold>Contract: </Bold>
</Text>
<Copyable value={params.at} />
</Section>
<Section>
<Text>
<Bold>Function: </Bold>
{params.functionName}
</Text>
<Text>
<Bold>Coins: </Bold>
{toMAS(params.coins).toString()} MAS
</Text>
<Text>
<Bold>Fee: </Bold>
{toMAS(params.fee).toString()} MAS
</Text>
<Text>
<Bold>Arguments: </Bold>
{params.args.toString()}
</Text>
</Section>
</Box>
</Container>
);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ICallData } from '@massalabs/massa-web3';
import { panel, text } from '@metamask/snaps-sdk';
import { CallSc } from '../components/CallSc';

import { getClient } from '../accounts/clients';
import { getHDAccount } from '../accounts/hd-deriver';
Expand Down Expand Up @@ -78,14 +78,15 @@ export const callSmartContract: Handler<
method: 'snap_dialog',
params: {
type: 'confirmation',
content: panel([
text('Do you want to call the following smart contract?'),
text(`**Contract:** ${params.at}`),
text(`**Function:** ${params.functionName}`),
text(`**Fee:** ${params.fee}`),
text(`**args:** ${params.args ? JSON.stringify(params.args) : '[]'}`),
text(`**coins:** ${params.coins}`),
]),
content: (
<CallSc
fee={params.fee}
functionName={params.functionName}
at={params.at}
args={params.args}
coins={params.coins}
/>
),
},
});

Expand Down

0 comments on commit 84505c1

Please sign in to comment.