Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikaysaxena committed Dec 10, 2023
2 parents 499bd2f + d8f662c commit 41b50cc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 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": "qHDT1vTWgUFNwrbA+eJsPwPUHDbwkrQXM94Eao40W8M=",
"shasum": "KXUWUpOnKM55BwS0UbSTDZfeL2XpDMOOidcAPNAmKVE=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
23 changes: 18 additions & 5 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 { 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';
Expand Down Expand Up @@ -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.',
),
]),
},
}),
Expand Down Expand Up @@ -98,8 +101,15 @@ 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'),
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?'),
]),
},
Expand All @@ -117,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}`),
]),
},
});
Expand All @@ -135,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}`),
]),
},
});
Expand Down
11 changes: 10 additions & 1 deletion server/src/privateKeyTxn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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({
Expand Down

0 comments on commit 41b50cc

Please sign in to comment.