From 9a112783d2ff64090ed88b27ff75e2331d4dd24f Mon Sep 17 00:00:00 2001 From: nabarun Date: Thu, 1 Aug 2024 10:17:11 +0000 Subject: [PATCH] Send namespaces object with correct accounts sequence while pairing with dApps (#8) Part of [laconicd testnet validator enrollment](https://www.notion.so/laconicd-testnet-validator-enrollment-6fc1d3cafcc64fef8c5ed3affa27c675) Co-authored-by: Shreerang Kale Reviewed-on: https://git.vdb.to/cerc-io/laconic-wallet-web/pulls/8 --- src/components/Accounts.tsx | 1 - src/components/PairingModal.tsx | 4 +--- src/utils/wallet-connect/helpers.ts | 32 ++++------------------------- 3 files changed, 5 insertions(+), 32 deletions(-) diff --git a/src/components/Accounts.tsx b/src/components/Accounts.tsx index 29de844..a1c292c 100644 --- a/src/components/Accounts.tsx +++ b/src/components/Accounts.tsx @@ -60,7 +60,6 @@ const Accounts = () => { networksData, selectedNetwork!, accounts, - currentIndex, ); if (!updatedNamespaces) { diff --git a/src/components/PairingModal.tsx b/src/components/PairingModal.tsx index ec08b81..5fbec48 100644 --- a/src/components/PairingModal.tsx +++ b/src/components/PairingModal.tsx @@ -19,7 +19,7 @@ const PairingModal = ({ setModalVisible, setToastVisible, }: PairingModalProps) => { - const { accounts, currentIndex } = useAccounts(); + const { accounts } = useAccounts(); const { selectedNetwork, networksData } = useNetworks(); const [isLoading, setIsLoading] = useState(false); const [chainError, setChainError] = useState(''); @@ -101,7 +101,6 @@ const PairingModal = ({ networksData, selectedNetwork!, accounts, - currentIndex, ); setSupportedNamespaces(nameSpaces); } catch (err) { @@ -127,7 +126,6 @@ const PairingModal = ({ networksData, selectedNetwork, accounts, - currentIndex, setCurrentProposal, setModalVisible, web3wallet diff --git a/src/utils/wallet-connect/helpers.ts b/src/utils/wallet-connect/helpers.ts index a732cc2..034cd39 100644 --- a/src/utils/wallet-connect/helpers.ts +++ b/src/utils/wallet-connect/helpers.ts @@ -40,7 +40,6 @@ export const getNamespaces = async ( networksData: NetworksDataState[], selectedNetwork: NetworksDataState, accounts: Account[], - currentIndex: number, ) => { const namespaceChainId = `${selectedNetwork.namespace}:${selectedNetwork.chainId}`; @@ -101,23 +100,6 @@ export const getNamespaces = async ( const requiredAddressesArray = await Promise.all(requiredAddressesPromise); const requiredAddresses = requiredAddressesArray.flat(); - let sortedAccounts = requiredAddresses; - - // If selected network is included in chains requested from dApp, - // Put selected account as first account - if (walletConnectChains.includes(namespaceChainId)) { - const currentAddresses = requiredAddresses.filter(address => - address.includes(namespaceChainId), - ); - sortedAccounts = [ - currentAddresses[currentIndex], - ...currentAddresses.filter((address, index) => index !== currentIndex), - ...requiredAddresses.filter( - address => !currentAddresses.includes(address), - ), - ]; - } - // construct namespace object const newNamespaces = { eip155: { @@ -133,7 +115,7 @@ export const getNamespaces = async ( ...(optionalNamespaces.eip155?.events ?? []), ...(requiredNamespaces.eip155?.events ?? []), ], - accounts: sortedAccounts.filter(account => account.includes(EIP155)), + accounts: requiredAddresses.filter(account => account.includes(EIP155)), }, cosmos: { chains: walletConnectChains.filter(chain => chain.includes(COSMOS)), @@ -147,18 +129,12 @@ export const getNamespaces = async ( ...(optionalNamespaces.cosmos?.events ?? []), ...(requiredNamespaces.cosmos?.events ?? []), ], - accounts: sortedAccounts.filter(account => account.includes(COSMOS)), + accounts: requiredAddresses.filter(account => account.includes(COSMOS)), }, }; return newNamespaces; } else { - // Set selected account as the first account in supported namespaces - const sortedAccounts = [ - accounts[currentIndex], - ...accounts.filter((account, index) => index !== currentIndex), - ]; - switch (selectedNetwork.namespace) { case EIP155: return { @@ -175,7 +151,7 @@ export const getNamespaces = async ( ...(optionalNamespaces.eip155?.events ?? []), ...(requiredNamespaces.eip155?.events ?? []), ], - accounts: sortedAccounts.map(ethAccount => { + accounts: accounts.map(ethAccount => { return `${namespaceChainId}:${ethAccount.address}`; }), }, @@ -200,7 +176,7 @@ export const getNamespaces = async ( ...(optionalNamespaces.cosmos?.events ?? []), ...(requiredNamespaces.cosmos?.events ?? []), ], - accounts: sortedAccounts.map(cosmosAccount => { + accounts: accounts.map(cosmosAccount => { return `${namespaceChainId}:${cosmosAccount.address}`; }), },