Skip to content

Commit

Permalink
Merge pull request #21 from nightly-labs/cleanup
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
NorbertBodziony authored Nov 28, 2024
2 parents 2de8d7f + 5fb869d commit 0b381a1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 28 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/nightly-labs/aptos-snap"
},
"source": {
"shasum": "2vmlVMaaQQEP6iTlvUw7JAQobmuO/1QmLezdak5ajfU=",
"shasum": "uq662wuJJ9H2BT977RirjHRL/ioOK1V5HN03KqXOIgE=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
11 changes: 0 additions & 11 deletions packages/snap/src/connection.ts

This file was deleted.

19 changes: 8 additions & 11 deletions packages/snap/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
NetworkInfo,
} from '@aptos-labs/wallet-standard';
import type { OnRpcRequestHandler } from '@metamask/snaps-sdk';
import { Address, Bold, Box, Text } from '@metamask/snaps-sdk/jsx';
import { Bold, Box, Text } from '@metamask/snaps-sdk/jsx';
import { getAccount } from './account';
import { decodeAptosTransaction } from './aptos';

Expand All @@ -24,8 +24,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
}) => {
// Get the state
const state = await getState();
console.log({ state });
console.log({ request });
switch (request.method) {
case 'connect': {
const account = await getAccount();
Expand Down Expand Up @@ -95,7 +93,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
}
case 'signAndSubmitTransaction': {
const account = await getAccount();

const result = await snap.request({
method: 'snap_dialog',
params: {
Expand All @@ -113,13 +110,13 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
),
},
});
const signAndSubmitTransactionInput = decodeAptosTransaction(
(request.params as any).payload,
);
const signature = account.signTransactionWithAuthenticator(
signAndSubmitTransactionInput,
);
if (result === true) {
const signAndSubmitTransactionInput = decodeAptosTransaction(
(request.params as any).payload,
);
const signature = account.signTransactionWithAuthenticator(
signAndSubmitTransactionInput,
);
return signature.bcsToHex().toString();
} else {
throw new Error('User rejected the request.');
Expand Down Expand Up @@ -148,8 +145,8 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
),
},
});
const signature = account.sign(signMessageParams.message);
if (result === true) {
const signature = account.sign(signMessageParams.message);
return signature.bcsToHex().toString();
} else {
throw new Error('User rejected the request.');
Expand Down
8 changes: 3 additions & 5 deletions packages/snap/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export async function getState(): Promise<SnapState> {
encrypted: false,
},
});
console.log({ snapState });
// Check if the state is null
if (snapState === null) {
// Update the state with default values
const result = await snap.request({
// Ignore the error if the state is not updated
await snap.request({
method: 'snap_manageState',
params: {
operation: ManageStateOperation.UpdateState,
Expand All @@ -22,15 +22,14 @@ export async function getState(): Promise<SnapState> {
newState: DEFAULT_SNAP_STATE,
},
});
console.log({ result });
return DEFAULT_SNAP_STATE;
}
// @ts-ignore
return snapState as SnapState;
}

export async function updateState(newState: SnapState) {
const result = await snap.request({
return await snap.request({
method: 'snap_manageState',
params: {
operation: ManageStateOperation.UpdateState,
Expand All @@ -39,7 +38,6 @@ export async function updateState(newState: SnapState) {
newState: newState,
},
});
console.log({ result });
}

export const isAptosSignAndSubmitTransactionInput = (
Expand Down

0 comments on commit 0b381a1

Please sign in to comment.