From 653b362e5c82d6023f0fdcbba66522d92a98c09c Mon Sep 17 00:00:00 2001 From: Radu Mojic Date: Thu, 12 Oct 2023 16:51:54 +0300 Subject: [PATCH] fix: check for the whole chain identifier ( namespace + ":" + reference ) (#300) --- dapps/react-dapp-v2/src/constants/default.ts | 1 + .../react-wallet-v2/src/components/ChainDataMini.tsx | 4 ++-- wallets/react-wallet-v2/src/data/MultiversxData.ts | 10 ++++++---- wallets/react-wallet-v2/src/data/chainsUtil.ts | 8 +++++--- .../react-wallet-v2/src/views/SessionProposalModal.tsx | 10 +++++++--- .../src/views/SessionSignMultiversxModal.tsx | 2 +- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/dapps/react-dapp-v2/src/constants/default.ts b/dapps/react-dapp-v2/src/constants/default.ts index 6ac925a..6f04577 100644 --- a/dapps/react-dapp-v2/src/constants/default.ts +++ b/dapps/react-dapp-v2/src/constants/default.ts @@ -125,6 +125,7 @@ export enum DEFAULT_MULTIVERSX_METHODS { MULTIVERSX_SIGN_MESSAGE = "mvx_signMessage", MULTIVERSX_SIGN_LOGIN_TOKEN = "mvx_signLoginToken", MULTIVERSX_SIGN_NATIVE_AUTH_TOKEN = "mvx_signNativeAuthToken", + MULTIVERSX_CANCEL_ACTION = "mvx_cancelAction" } export enum DEFAULT_MULTIVERSX_EVENTS {} diff --git a/wallets/react-wallet-v2/src/components/ChainDataMini.tsx b/wallets/react-wallet-v2/src/components/ChainDataMini.tsx index 3a63c9e..bef86a8 100644 --- a/wallets/react-wallet-v2/src/components/ChainDataMini.tsx +++ b/wallets/react-wallet-v2/src/components/ChainDataMini.tsx @@ -12,13 +12,13 @@ import { Card, Row, styled, Image, Avatar } from '@nextui-org/react' import { ReactNode, useMemo } from 'react' interface Props { - chainId?: string | number + chainId?: string // namespace + ":" + reference } // const StyledLogo = styled(Image, {}) export default function ChainDataMini({ chainId }: Props) { - const chainData = useMemo(() => getChainData(chainId!), [chainId]) + const chainData = useMemo(() => getChainData(chainId), [chainId]) console.log(chainData) if (!chainData) return <> diff --git a/wallets/react-wallet-v2/src/data/MultiversxData.ts b/wallets/react-wallet-v2/src/data/MultiversxData.ts index db069e9..b1f153d 100644 --- a/wallets/react-wallet-v2/src/data/MultiversxData.ts +++ b/wallets/react-wallet-v2/src/data/MultiversxData.ts @@ -13,7 +13,7 @@ export const MULTIVERSX_MAINNET_CHAINS = { logo: '/chain-logos/multiversx-1.svg', rgb: '43, 45, 46', rpc: '', - namespace: 'mutiversx' + namespace: 'mvx' } } @@ -24,7 +24,7 @@ export const MULTIVERSX_TEST_CHAINS = { logo: '/chain-logos/multiversx-1.svg', rgb: '43, 45, 46', rpc: '', - namespace: 'mutiversx' + namespace: 'mvx' } // Keep only one Test Chain visible // 'mvx:T': { @@ -32,7 +32,8 @@ export const MULTIVERSX_TEST_CHAINS = { // name: 'MultiversX Testnet', // logo: '/chain-logos/multiversx-1.svg', // rgb: '43, 45, 46', - // rpc: '' + // rpc: '', + // namespace: 'mvx' // } } @@ -46,5 +47,6 @@ export const MULTIVERSX_SIGNING_METHODS = { MULTIVERSX_SIGN_TRANSACTIONS: 'mvx_signTransactions', MULTIVERSX_SIGN_MESSAGE: 'mvx_signMessage', MULTIVERSX_SIGN_LOGIN_TOKEN: 'mvx_signLoginToken', - MULTIVERSX_SIGN_NATIVE_AUTH_TOKEN: 'mvx_signNativeAuthToken' + MULTIVERSX_SIGN_NATIVE_AUTH_TOKEN: 'mvx_signNativeAuthToken', + MULTIVERSX_CANCEL_ACTION: 'mvx_cancelAction' } diff --git a/wallets/react-wallet-v2/src/data/chainsUtil.ts b/wallets/react-wallet-v2/src/data/chainsUtil.ts index 732bf26..e3cc0af 100644 --- a/wallets/react-wallet-v2/src/data/chainsUtil.ts +++ b/wallets/react-wallet-v2/src/data/chainsUtil.ts @@ -20,8 +20,10 @@ export const ALL_CHAINS = { ...TRON_CHAINS } -export function getChainData(chainId: string | number) { +export function getChainData(chainId?: string) { if (!chainId) return - chainId = chainId.toString().includes(':') ? chainId.toString().split(':')[1] : chainId - return Object.values(ALL_CHAINS).find(chain => chain.chainId == chainId) + const [namespace, reference] = chainId.toString().split(':') + return Object.values(ALL_CHAINS).find( + chain => chain.chainId == reference && chain.namespace === namespace + ) } diff --git a/wallets/react-wallet-v2/src/views/SessionProposalModal.tsx b/wallets/react-wallet-v2/src/views/SessionProposalModal.tsx index c75c94c..180daec 100644 --- a/wallets/react-wallet-v2/src/views/SessionProposalModal.tsx +++ b/wallets/react-wallet-v2/src/views/SessionProposalModal.tsx @@ -102,7 +102,7 @@ export default function SessionProposalModal() { events: [], accounts: kadenaChains.map(chain => `${chain}:${kadenaAddresses[0]}`).flat() }, - multiversx: { + mvx: { chains: multiversxChains, methods: multiversxMethods, events: [], @@ -198,7 +198,7 @@ export default function SessionProposalModal() { return cosmosAddresses[0] case 'kadena': return kadenaAddresses[0] - case 'multiversx': + case 'mvx': return multiversxAddresses[0] case 'near': return nearAddresses[0] @@ -324,9 +324,13 @@ export default function SessionProposalModal() { {supportedChains.length && supportedChains.map((chain, i) => { + if (!chain) { + return <> + } + return ( - + ) })} diff --git a/wallets/react-wallet-v2/src/views/SessionSignMultiversxModal.tsx b/wallets/react-wallet-v2/src/views/SessionSignMultiversxModal.tsx index e50c673..be4ca6f 100644 --- a/wallets/react-wallet-v2/src/views/SessionSignMultiversxModal.tsx +++ b/wallets/react-wallet-v2/src/views/SessionSignMultiversxModal.tsx @@ -67,7 +67,7 @@ export default function SessionSignMultiversxModal() { return (