Skip to content

Commit

Permalink
added create ac confirmatipon
Browse files Browse the repository at this point in the history
Signed-off-by: aritroCoder <[email protected]>
  • Loading branch information
aritroCoder committed Dec 8, 2023
1 parent 11982ba commit de3b9b3
Show file tree
Hide file tree
Showing 8 changed files with 1,309 additions and 632 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/MetaMask/template-snap-monorepo.git"
},
"source": {
"shasum": "q6hmbBEKkaIZ/GkjyIgbDrKYX/rKOUrIigbA/CI8iFg=",
"shasum": "LQvf026KRPLH0VZTgNsE74WSjPtEBWHpizt0DMeKS8M=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
65 changes: 58 additions & 7 deletions packages/snap/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { OnRpcRequestHandler } from '@metamask/snaps-types';
import { panel, text } from '@metamask/snaps-ui';
import { heading, panel, text } from '@metamask/snaps-ui';

import createAccount from './utils/aptos/CreateAccount';
import transferCoin from './utils/aptos/TransferCoin';
Expand All @@ -25,7 +25,10 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
origin: string;
request: {
method: string;
params: any;
params: {
to: string;
amount: number;
};
};
}) => {
switch (request.method) {
Expand All @@ -45,20 +48,68 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
});
break;
case 'getAccount': {
const accountDetails = await createAccount();
const accountDetails: {
accountAddress: string;
transactionHash: string;
} = await createAccount();
return snap.request({
method: 'snap_dialog',
params: {
type: 'alert',
content: panel([
heading('Account Details'),
text(`Address: **${accountDetails.accountAddress}**`),
]),
},
});
return { accountDetails };
break;
}
case 'transferCoin': {
const { to, amount } = request.params;
console.log('this is to', to);
const result = await snap.request({
method: 'snap_dialog',
params: {
type: 'confirmation',
content: panel([
heading('Transfer Coin'),
text(`To: **${to}**`),
text(`Amount: **${amount}**`),
text('Are you sure you want to transfer?'),
]),
},
});
if (result !== true) {
return { txHash: null };
break;
}
const txHash = await transferCoin(to, amount);
return { txHash };
return snap.request({
method: 'snap_dialog',
params: {
type: 'alert',
content: panel([
heading('Amount transferred successfully.'),
text(`To: **${to}**`),
text(`Amount: **${amount}**`),
text(`Transaction Hash: **${txHash}**`),
]),
},
});
break;
}
case 'fundMe': {
const txHash = await fundMe();
return { txHash };
const txHash: string = await fundMe();
return snap.request({
method: 'snap_dialog',
params: {
type: 'alert',
content: panel([
heading('Funded 1 APT successfully.'),
text(`Transaction Hash: **${txHash}**`),
]),
},
});
break;
}
case 'txnHistory': {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified server/.yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions server/src/aes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'aes256';
11 changes: 11 additions & 0 deletions server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es2017",
"outDir": "dist",
"paths": {
"@/*": ["src/*"]
},
"esModuleInterop": true,
"moduleResolution": "nodenext"
}
}
Loading

0 comments on commit de3b9b3

Please sign in to comment.