From 83d10887c806d327fca6dae84cc28cde93c78e01 Mon Sep 17 00:00:00 2001 From: Stanley Yuen <102275989+stanleyyconsensys@users.noreply.github.com> Date: Thu, 7 Mar 2024 12:46:16 +0800 Subject: [PATCH] fixing current network (#213) Co-authored-by: Mario Christopher --- packages/starknet-snap/snap.manifest.json | 2 +- packages/starknet-snap/src/index.ts | 16 +++++++++++----- yarn.lock | 6 +++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/starknet-snap/snap.manifest.json b/packages/starknet-snap/snap.manifest.json index 7e09be3c..94e61857 100644 --- a/packages/starknet-snap/snap.manifest.json +++ b/packages/starknet-snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/ConsenSys/starknet-snap.git" }, "source": { - "shasum": "SeitYNVUTrRF2Nay0C/ln9CEIwk77t5cHHbCVuTh/Ec=", + "shasum": "lLTHMW/oau9o6LzRE+2n+2qHCooLpe1RSJJPR/6UOEU=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/starknet-snap/src/index.ts b/packages/starknet-snap/src/index.ts index a7a8b150..f710527d 100644 --- a/packages/starknet-snap/src/index.ts +++ b/packages/starknet-snap/src/index.ts @@ -12,7 +12,7 @@ import { addErc20Token } from './addErc20Token'; import { getStoredErc20Tokens } from './getStoredErc20Tokens'; import { estimateFee } from './estimateFee'; import { getStoredUserAccounts } from './getStoredUserAccounts'; -import { SnapState } from './types/snapState'; +import { AccContract, SnapState } from './types/snapState'; import { extractPrivateKey } from './extractPrivateKey'; import { extractPublicKey } from './extractPublicKey'; import { addNetwork } from './addNetwork'; @@ -263,9 +263,16 @@ export const onHomePage: OnHomePageHandler = async () => { }, }); - if (state && state.accContracts.length > 0) { - const userAddress = state.accContracts[0].address; - const chainId = state.accContracts[0].chainId; + let accContract: AccContract; + if (state.currentNetwork) { + accContract = state.accContracts.find(n => n.chainId == state.currentNetwork.chainId); + } else { + accContract = state.accContracts[0]; + } + + if (accContract) { + const userAddress = accContract.address; + const chainId = accContract.chainId; const network = getNetworkFromChainId(state, chainId); panelItems.push(row('Address', address(`${userAddress}`))); panelItems.push(row('Network', text(`${network.name}`))); @@ -301,7 +308,6 @@ export const onHomePage: OnHomePageHandler = async () => { ), ); } - return { content: panel(panelItems), }; diff --git a/yarn.lock b/yarn.lock index ba6ec621..bdf372de 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3154,8 +3154,8 @@ __metadata: linkType: hard "@consensys/starknet-snap@file:../starknet-snap::locator=wallet-ui%40workspace%3Apackages%2Fwallet-ui": - version: 2.4.0 - resolution: "@consensys/starknet-snap@file:../starknet-snap#../starknet-snap::hash=bdd60c&locator=wallet-ui%40workspace%3Apackages%2Fwallet-ui" + version: 2.5.1 + resolution: "@consensys/starknet-snap@file:../starknet-snap#../starknet-snap::hash=f43351&locator=wallet-ui%40workspace%3Apackages%2Fwallet-ui" dependencies: "@metamask/snaps-sdk": 3.0.1 async-mutex: ^0.3.2 @@ -3163,7 +3163,7 @@ __metadata: ethers: ^5.5.1 starknet: ^5.14.0 starknet_v4.22.0: "npm:starknet@4.22.0" - checksum: ddbcecfa69dd0bbe71fc654e022e279de1d453a4eb5d9286b962adfd72eb967a52882b5d9d6009e4c02528adf21584a5545daa6f1c12874c2162f27cb331fb24 + checksum: f6c425fa95f59effaa3cb47e30e5f5a339fb47e9cd5b0337f229213642436efb5fe8dc6b4df4de75a9b4e4524793145c78914514ff2d11bd055f365c2ce180d5 languageName: node linkType: hard