From 71315736eb308062b5d7559f357e069daa0e8e0c Mon Sep 17 00:00:00 2001 From: Halil Beycan <50718965+BeycanDeveloper@users.noreply.github.com> Date: Sun, 15 Sep 2024 18:55:13 +0800 Subject: [PATCH 1/4] fixed isWebview method for mobile browsers --- packages/utils/src/index.ts | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 0e38dab..3e4ffe8 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -236,27 +236,18 @@ export const isWebview = (): boolean => { return false } - const navigator = window.navigator - /* eslint-disable */ - if (window.WebViewJavascriptBridge) { - return true - } - - if (window.webkit && window.webkit.messageHandlers) { - return true - } - - if (navigator.userAgent.match(/WebView/i)) { - return true - } - + const navigator = window.navigator + const userAgent = navigator.userAgent + const normalizedUserAgent = userAgent.toLowerCase() const standalone = navigator.standalone - const userAgent = navigator.userAgent.toLowerCase() - const safari = /safari/.test(userAgent) - const ios = /iphone|ipod|ipad/.test(userAgent) - - return ios ? !standalone && !safari : userAgent.includes('wv') + const isIos = /ip(ad|hone|od)/.test(normalizedUserAgent) + || navigator.platform === 'MacIntel' + && navigator.maxTouchPoints > 1 + const isAndroid = /android/.test(normalizedUserAgent) + const isSafari = /safari/.test(normalizedUserAgent) + return (isAndroid && /; wv\)/.test(normalizedUserAgent)) + || (isIos && !standalone && !isSafari) /* eslint-enable */ } From 0eb4ce51b00174d477bf40c10f208a4cc62a4016 Mon Sep 17 00:00:00 2001 From: Halil Beycan <50718965+BeycanDeveloper@users.noreply.github.com> Date: Tue, 1 Oct 2024 12:29:06 +0800 Subject: [PATCH 2/4] fixed walletconnect multiple connection problem --- packages/networks/evm-chains/package.json | 2 +- .../src/browser/adapters/WalletConnect.ts | 109 ++++++++++++------ 2 files changed, 74 insertions(+), 37 deletions(-) diff --git a/packages/networks/evm-chains/package.json b/packages/networks/evm-chains/package.json index 765b798..1e9d6ae 100644 --- a/packages/networks/evm-chains/package.json +++ b/packages/networks/evm-chains/package.json @@ -1,6 +1,6 @@ { "name": "@multiplechain/evm-chains", - "version": "0.4.6", + "version": "0.4.7", "type": "module", "main": "dist/index.cjs", "module": "dist/index.es.js", diff --git a/packages/networks/evm-chains/src/browser/adapters/WalletConnect.ts b/packages/networks/evm-chains/src/browser/adapters/WalletConnect.ts index 7b3cb01..3e342bf 100644 --- a/packages/networks/evm-chains/src/browser/adapters/WalletConnect.ts +++ b/packages/networks/evm-chains/src/browser/adapters/WalletConnect.ts @@ -1,12 +1,65 @@ import icons from './icons' +import { networks } from '../../index' import type { EIP1193Provider } from './EIP6963' -import type { Provider } from '../../services/Provider' +import type { EvmNetworkConfigInterface, Provider } from '../../services/Provider' import { EthereumProvider } from '@walletconnect/ethereum-provider' import { ErrorTypeEnum, WalletPlatformEnum } from '@multiplechain/types' import type { WalletConnectConfig, WalletAdapterInterface } from '@multiplechain/types' let isConnected = false let walletProvider: EIP1193Provider | undefined +let connector: InstanceType | undefined + +const initConnector = async ( + config: WalletConnectConfig, + network: EvmNetworkConfigInterface +): Promise> => { + if (connector !== undefined) { + return connector + } + + const otherNetworkIds = networks + .getAll() + .map((x) => x.id) + .filter((id) => id !== network.id) + + const chains: [number, ...number[]] = [network.id, ...otherNetworkIds] + + connector = await EthereumProvider.init({ + chains, + projectId: config.projectId, + relayUrl: 'wss://relay.walletconnect.com', + optionalChains: chains, + showQrModal: true, + qrModalOptions: { + themeMode: config.themeMode, + themeVariables: { + '--wcm-z-index': '999999999999' + }, + explorerExcludedWalletIds: 'ALL', + explorerRecommendedWalletIds: [ + 'c57ca95b47569778a828d19178114f4db188b89b763c899ba0be274e97267d96', + '4622a2b2d6af1c9844944291e5e7351a6aa24cd7b23099efac1b2fd875da31a0', + '1ae92b26df02f0abca6304df07debccd18262fdf5fe82daa81593582dac9a369', + '0b415a746fb9ee99cce155c2ceca0c6f6061b1dbca2d722b3ba16381d0562150', + '971e689d0a5be527bac79629b4ee9b925e82208e5168b733496a09c0faed0709', + 'c03dfee351b6fcc421b4494ea33b9d4b92a984f87aa76d1663bb28705e95034a', + 'ecc4036f814562b41a5268adc86270fba1365471402006302e70169465b7ac18', + 'ef333840daf915aafdc4a004525502d6d49d77bd9c65e0642dbaefb3c2893bef', + 'bc949c5d968ae81310268bf9193f9c9fb7bb4e1283e1284af8f2bd4992535fd6', + '74f8092562bd79675e276d8b2062a83601a4106d30202f2d509195e30e19673d', + 'afbd95522f4041c71dd4f1a065f971fd32372865b416f95a0b1db759ae33f2a7', + '20459438007b75f4f4acb98bf29aa3b800550309646d375da5fd4aac6c2a2c66', + '8837dd9413b1d9b585ee937d27a816590248386d9dbf59f5cd3422dbbb65683e', + 'c286eebc742a537cd1d6818363e9dc53b21759a1e8e5d9b263d0c03ec7703576', + '38f5d18bd8522c244bdd70cb4a68e0e718865155811c043f052fb9f1c51de662', + '85db431492aa2e8672e93f4ea7acf10c88b97b867b0d373107af63dc4880f041' + ] + } + }) + + return connector +} const WalletConnect: WalletAdapterInterface = { id: 'walletconnect', @@ -18,6 +71,19 @@ const WalletConnect: WalletAdapterInterface = { isConnected: () => isConnected, disconnect: () => { isConnected = false + Object.keys(localStorage) + .filter((x) => { + return ( + x.startsWith('wc@2') || + x.startsWith('@w3m') || + x.startsWith('W3M') || + x.startsWith('-walletlink') + ) + }) + .forEach((x) => { + localStorage.removeItem(x) + }) + indexedDB.deleteDatabase('WALLET_CONNECT_V2_INDEXED_DB') }, connect: async ( @@ -40,44 +106,15 @@ const WalletConnect: WalletAdapterInterface = { const network = provider.network // @ts-expect-error allow number index rpcIdMapping[network.id] = network.rpcUrl - - const connector = await EthereumProvider.init({ - projectId: config.projectId, - relayUrl: 'wss://relay.walletconnect.com', - optionalChains: [network.id], - rpcMap: rpcIdMapping, - chains: [network.id], - showQrModal: true, - qrModalOptions: { - themeMode: config.themeMode, - themeVariables: { - '--wcm-z-index': '999999999999' - }, - explorerExcludedWalletIds: 'ALL', - explorerRecommendedWalletIds: [ - 'c57ca95b47569778a828d19178114f4db188b89b763c899ba0be274e97267d96', - '4622a2b2d6af1c9844944291e5e7351a6aa24cd7b23099efac1b2fd875da31a0', - '1ae92b26df02f0abca6304df07debccd18262fdf5fe82daa81593582dac9a369', - '0b415a746fb9ee99cce155c2ceca0c6f6061b1dbca2d722b3ba16381d0562150', - '971e689d0a5be527bac79629b4ee9b925e82208e5168b733496a09c0faed0709', - 'c03dfee351b6fcc421b4494ea33b9d4b92a984f87aa76d1663bb28705e95034a', - 'ecc4036f814562b41a5268adc86270fba1365471402006302e70169465b7ac18', - 'ef333840daf915aafdc4a004525502d6d49d77bd9c65e0642dbaefb3c2893bef', - 'bc949c5d968ae81310268bf9193f9c9fb7bb4e1283e1284af8f2bd4992535fd6', - '74f8092562bd79675e276d8b2062a83601a4106d30202f2d509195e30e19673d', - 'afbd95522f4041c71dd4f1a065f971fd32372865b416f95a0b1db759ae33f2a7', - '20459438007b75f4f4acb98bf29aa3b800550309646d375da5fd4aac6c2a2c66', - '8837dd9413b1d9b585ee937d27a816590248386d9dbf59f5cd3422dbbb65683e', - 'c286eebc742a537cd1d6818363e9dc53b21759a1e8e5d9b263d0c03ec7703576', - '38f5d18bd8522c244bdd70cb4a68e0e718865155811c043f052fb9f1c51de662', - '85db431492aa2e8672e93f4ea7acf10c88b97b867b0d373107af63dc4880f041' - ] - } - }) + const connector = await initConnector(config, network) return await new Promise((resolve, reject) => { connector - .enable() + .connect({ + rpcMap: rpcIdMapping, + chains: [network.id], + optionalChains: [network.id] + }) .then(() => { isConnected = true resolve((walletProvider = connector as EIP1193Provider)) From 7767acdda64bff62d5e3abbb6dbcc7ad182c1841 Mon Sep 17 00:00:00 2001 From: Halil Beycan <50718965+BeycanDeveloper@users.noreply.github.com> Date: Tue, 1 Oct 2024 12:29:28 +0800 Subject: [PATCH 3/4] updated nft transfer id --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 07ea7f4..b393ef9 100644 --- a/.env.example +++ b/.env.example @@ -16,7 +16,7 @@ EVM_NFT_BALANCE_TEST_AMOUNT=2 EVM_TRANSFER_TEST_AMOUNT=0.01 EVM_TOKEN_TRANSFER_TEST_AMOUNT=1 EVM_TOKEN_APPROVE_TEST_AMOUNT=100 -EVM_NFT_TRANSFER_ID=7 +EVM_NFT_TRANSFER_ID=49 EVM_BALANCE_TEST_ADDRESS='0x760A4d3D03928D1e8541A7644B34370c1b79aa9F' EVM_SENDER_PRIVATE_KEY='0x14bd9af4e87981b37b7b2e8a0d1d249b7fcdb7a3bc579c4c31488842d372c0e9' From fd432a134db6467d214477422f282963ca963da4 Mon Sep 17 00:00:00 2001 From: Halil Beycan <50718965+BeycanDeveloper@users.noreply.github.com> Date: Tue, 1 Oct 2024 12:36:26 +0800 Subject: [PATCH 4/4] updated nft transfer id --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index b393ef9..6f82cfe 100644 --- a/.env.example +++ b/.env.example @@ -16,7 +16,7 @@ EVM_NFT_BALANCE_TEST_AMOUNT=2 EVM_TRANSFER_TEST_AMOUNT=0.01 EVM_TOKEN_TRANSFER_TEST_AMOUNT=1 EVM_TOKEN_APPROVE_TEST_AMOUNT=100 -EVM_NFT_TRANSFER_ID=49 +EVM_NFT_TRANSFER_ID=11 EVM_BALANCE_TEST_ADDRESS='0x760A4d3D03928D1e8541A7644B34370c1b79aa9F' EVM_SENDER_PRIVATE_KEY='0x14bd9af4e87981b37b7b2e8a0d1d249b7fcdb7a3bc579c4c31488842d372c0e9'