From 9f1e296c39b87a6f1d2d6306627bfd1ecb3e566e Mon Sep 17 00:00:00 2001 From: aritroCoder Date: Sun, 10 Dec 2023 20:52:48 +0530 Subject: [PATCH 1/2] fixed txn bug on some addrs Signed-off-by: aritroCoder --- packages/snap/snap.manifest.json | 2 +- packages/snap/src/index.ts | 9 +++++++++ server/src/privateKeyTxn.ts | 11 ++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index 850bd6d..8cb3f6a 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/template-snap-monorepo.git" }, "source": { - "shasum": "qHDT1vTWgUFNwrbA+eJsPwPUHDbwkrQXM94Eao40W8M=", + "shasum": "YoKmyYOilAOCHHWdD7rLvEGM89tjQvAjitssnyIRFMU=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/snap/src/index.ts b/packages/snap/src/index.ts index 0cf0a0f..4fb8791 100644 --- a/packages/snap/src/index.ts +++ b/packages/snap/src/index.ts @@ -60,6 +60,9 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ content: panel([ heading('Account Details'), text(`Address: **${accountDetails.accountAddress}**`), + text( + 'If you have created your account in devnet/testnet, we have already funded some Aptos to your account.', + ), ]), }, }), @@ -100,6 +103,12 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ heading('Transfer Coin'), text(`To: **${to}**`), text(`Amount: **${amount}**`), + panel([ + heading('Gas fee insights'), + text('Average price per gas unit: **0.000001 APT**'), + text('Max price per gas unit: **0.0000015 APT**'), + text('Max gas limit: **200**(upto **0.0003 APT**)'), + ]), text('Are you sure you want to transfer?'), ]), }, diff --git a/server/src/privateKeyTxn.ts b/server/src/privateKeyTxn.ts index cb09c5f..b5e7a03 100644 --- a/server/src/privateKeyTxn.ts +++ b/server/src/privateKeyTxn.ts @@ -13,6 +13,15 @@ function decryptPhrase(encryptedPhrase: string, key: string): string { return originalText; } +function padHexString(input: string): string { + let hexString = input.startsWith('0x') ? input.slice(2) : input; + const length = 64; + while (hexString.length < length) { + hexString = '0' + hexString; + } + return '0x' + hexString; +} + export async function privateKeyTxn(request: Request) { const aptos = new Aptos(); @@ -28,7 +37,7 @@ export async function privateKeyTxn(request: Request) { const txn = await aptos.transferCoinTransaction({ sender: account, - recipient, + recipient: padHexString(recipient), amount, }); const txn1 = await aptos.signAndSubmitTransaction({ From d8f662c9d868fab1ecf397020d1a7c38e43432e3 Mon Sep 17 00:00:00 2001 From: aritroCoder Date: Sun, 10 Dec 2023 21:03:49 +0530 Subject: [PATCH 2/2] added copy capability in snap Signed-off-by: aritroCoder --- packages/snap/snap.manifest.json | 2 +- packages/snap/src/index.ts | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index 8cb3f6a..5823801 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/template-snap-monorepo.git" }, "source": { - "shasum": "YoKmyYOilAOCHHWdD7rLvEGM89tjQvAjitssnyIRFMU=", + "shasum": "KXUWUpOnKM55BwS0UbSTDZfeL2XpDMOOidcAPNAmKVE=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/snap/src/index.ts b/packages/snap/src/index.ts index 4fb8791..281846b 100644 --- a/packages/snap/src/index.ts +++ b/packages/snap/src/index.ts @@ -1,5 +1,5 @@ import type { OnRpcRequestHandler } from '@metamask/snaps-types'; -import { heading, panel, text } from '@metamask/snaps-ui'; +import { copyable, heading, panel, text } from '@metamask/snaps-ui'; import createAccount from './utils/aptos/CreateAccount'; import transferCoin from './utils/aptos/TransferCoin'; @@ -101,7 +101,8 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ type: 'confirmation', content: panel([ heading('Transfer Coin'), - text(`To: **${to}**`), + text(`To:`), + copyable(`${to}`), text(`Amount: **${amount}**`), panel([ heading('Gas fee insights'), @@ -126,9 +127,11 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ type: 'alert', content: panel([ heading('Amount transferred successfully.'), - text(`To: **${to}**`), + text(`To:`), + copyable(`${to}`), text(`Amount: **${amount}**`), - text(`Transaction Hash: **${txHash.hash}**`), + text(`Transaction Hash:`), + copyable(`${txHash.hash}`), ]), }, }); @@ -144,7 +147,8 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ type: 'alert', content: panel([ heading('Funded 1 APT successfully.'), - text(`Transaction Hash: **${txHash}**`), + text(`Transaction Hash:`), + copyable(`${txHash}`), ]), }, });