From 60482f0b1d97aca22242e5282056f10c3a53014e Mon Sep 17 00:00:00 2001 From: Joe S Date: Thu, 7 Sep 2023 20:28:02 -0400 Subject: [PATCH] Caching and optimizations --- packages/snap/package.json | 2 +- packages/snap/snap.manifest.json | 4 +- packages/snap/src/index.ts | 13 +- packages/snap/src/state.ts | 21 +++ packages/ui/src/components/Balance.svelte | 42 +++-- packages/ui/src/components/Header.svelte | 2 +- packages/ui/src/components/Menu.svelte | 2 +- packages/ui/src/components/Transfer.svelte | 63 ++++--- packages/ui/src/routes/+layout.svelte | 96 ++++++---- packages/ui/src/routes/+page.svelte | 21 ++- packages/ui/src/routes/address/+layout.svelte | 57 ------ .../{dashboard => balances}/+page.svelte | 32 +--- .../ui/src/routes/dashboard/+layout.svelte | 57 ------ .../ui/src/routes/settings/+layout.svelte | 36 ---- .../ui/src/routes/transactions/+layout.svelte | 57 ------ packages/ui/src/store/balances.ts | 42 ++++- packages/ui/src/store/chains.ts | 8 + packages/ui/src/store/directory.ts | 168 ++++++++++++++++++ packages/ui/src/utils/general.ts | 3 + packages/ui/src/utils/snap.ts | 22 ++- packages/ui/static/app.css | 39 ---- 21 files changed, 428 insertions(+), 359 deletions(-) delete mode 100644 packages/ui/src/routes/address/+layout.svelte rename packages/ui/src/routes/{dashboard => balances}/+page.svelte (60%) delete mode 100644 packages/ui/src/routes/dashboard/+layout.svelte delete mode 100644 packages/ui/src/routes/settings/+layout.svelte delete mode 100644 packages/ui/src/routes/transactions/+layout.svelte create mode 100644 packages/ui/src/store/directory.ts diff --git a/packages/snap/package.json b/packages/snap/package.json index 395ebde..9a7180f 100644 --- a/packages/snap/package.json +++ b/packages/snap/package.json @@ -1,6 +1,6 @@ { "name": "@cosmsnap/snap", - "version": "0.1.7", + "version": "0.1.8", "description": "The Cosmos extension for your Metamask wallet.", "repository": { "type": "git", diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index a444060..3e9615e 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -1,5 +1,5 @@ { - "version": "0.1.7", + "version": "0.1.8", "description": "Cosmos Extension that adds Cosmos support to Metamask.", "proposedName": "Cosmos Extension", "repository": { @@ -7,7 +7,7 @@ "url": "https://github.com/cosmos/snap.git" }, "source": { - "shasum": "vTr7wXctqn/NZmTVkjwj2nJYkPM9GEYvrnRAswshDxY=", + "shasum": "KNST9WGZQuCvwWjJ/CJ4LcwpRIurasP4f6muX+8Sugk=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/snap/src/index.ts b/packages/snap/src/index.ts index a33e40c..a5ad1d1 100644 --- a/packages/snap/src/index.ts +++ b/packages/snap/src/index.ts @@ -107,7 +107,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ }); return { - data: res, + data: chains.chains, success: true, statusCode: 201, }; @@ -615,6 +615,17 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ statusCode: 200, }; + case "getPublicKey": + let key = await ChainState.getPublicKey(); + + return { + data: { + public_key: key + }, + success: true, + statusCode: 200, + }; + default: throw new Error("Method not found."); } diff --git a/packages/snap/src/state.ts b/packages/snap/src/state.ts index e04fc7c..946902d 100644 --- a/packages/snap/src/state.ts +++ b/packages/snap/src/state.ts @@ -69,6 +69,27 @@ export class ChainState { chain_id, }; } + /** + * Gets the public key for this wallet. + * + * @returns The public key in hex string. + * @throws If an error occurs. + */ + public static async getPublicKey(): Promise { + // get signer info + let node = await snap.request({ + method: "snap_getBip44Entropy", + params: { + coinType: DEFAULT_SLIP44, + }, + }); + + if (typeof node.publicKey === "undefined") { + throw Error("Public key from node is undefined"); + } + + return node.publicKey; + } /** * Gets all Cosmos chains from Metamask snap state. * diff --git a/packages/ui/src/components/Balance.svelte b/packages/ui/src/components/Balance.svelte index 0933e21..ceee4c8 100644 --- a/packages/ui/src/components/Balance.svelte +++ b/packages/ui/src/components/Balance.svelte @@ -1,18 +1,29 @@ - @@ -38,7 +49,7 @@ ${dollarAmount}
- {tokenAmount} {tokenDenom.toUpperCase()} + {tokenAmount} {tokenDenom.substring(1).toUpperCase()}
@@ -48,13 +59,20 @@
{chainAddress}
- content_copy + {#if copied} + + {:else} + + {/if} \ No newline at end of file diff --git a/packages/ui/src/components/Header.svelte b/packages/ui/src/components/Header.svelte index 653e869..afaf5ed 100644 --- a/packages/ui/src/components/Header.svelte +++ b/packages/ui/src/components/Header.svelte @@ -11,7 +11,7 @@ {#if connected}