From 7317367ec59e94859580ca612cd1b55221f31ad4 Mon Sep 17 00:00:00 2001 From: tomiir Date: Mon, 10 Jun 2024 11:59:56 -0600 Subject: [PATCH] chore: use walletconnect.org (#2360) Co-authored-by: Enes --- apps/laboratory/src/utils/ChainsUtil.ts | 2 +- apps/laboratory/src/utils/SignatureUtil.ts | 4 +-- packages/common/src/utils/ConstantsUtil.ts | 5 +++- packages/core/src/utils/CoreHelperUtil.ts | 24 +++-------------- packages/solana/src/client.ts | 2 +- packages/solana/src/utils/chains.ts | 4 ++- .../src/utils/scaffold/SolanaConstantsUtil.ts | 3 ++- .../src/utils/scaffold/SolanaHelpersUtils.ts | 3 ++- packages/wallet/src/W3mFrame.ts | 3 ++- packages/wallet/src/W3mFrameHelpers.ts | 26 ------------------- 10 files changed, 20 insertions(+), 56 deletions(-) diff --git a/apps/laboratory/src/utils/ChainsUtil.ts b/apps/laboratory/src/utils/ChainsUtil.ts index e09c857366..1a30960a73 100644 --- a/apps/laboratory/src/utils/ChainsUtil.ts +++ b/apps/laboratory/src/utils/ChainsUtil.ts @@ -109,7 +109,7 @@ export const solana = { name: 'Solana', currency: 'SOL', explorerUrl: 'https://solscan.io', - rpcUrl: 'https://rpc.walletconnect.com/v1' + rpcUrl: 'https://rpc.walletconnect.org/v1' } export const solanaTestnet = { diff --git a/apps/laboratory/src/utils/SignatureUtil.ts b/apps/laboratory/src/utils/SignatureUtil.ts index 940a80e54e..21eb8f110b 100644 --- a/apps/laboratory/src/utils/SignatureUtil.ts +++ b/apps/laboratory/src/utils/SignatureUtil.ts @@ -1,10 +1,8 @@ import { createPublicClient, http } from 'viem' function getTransport({ chainId }: { chainId: number }) { - const RPC_URL = 'https://rpc.walletconnect.com' - return http( - `${RPC_URL}/v1/?chainId=eip155:${chainId}&projectId=${process.env['NEXT_PUBLIC_PROJECT_ID']}` + `https://rpc.walletconnect.org/v1/?chainId=eip155:${chainId}&projectId=${process.env['NEXT_PUBLIC_PROJECT_ID']}` ) } diff --git a/packages/common/src/utils/ConstantsUtil.ts b/packages/common/src/utils/ConstantsUtil.ts index 6e084fb703..18a8b6dc39 100644 --- a/packages/common/src/utils/ConstantsUtil.ts +++ b/packages/common/src/utils/ConstantsUtil.ts @@ -1,4 +1,7 @@ export const ConstantsUtil = { WC_NAME_SUFFIX: '.wcn.id', - WC_NAMES_ALLOWED_DOMAINS: ['walletconnect.com'] + WC_NAMES_ALLOWED_DOMAINS: ['walletconnect.com'], + BLOCKCHAIN_API_RPC_URL: 'https://rpc.walletconnect.org', + PULSE_API_URL: 'https://pulse.walletconnect.org', + W3M_API_URL: 'https://api.web3modal.org' } diff --git a/packages/core/src/utils/CoreHelperUtil.ts b/packages/core/src/utils/CoreHelperUtil.ts index 917802d227..ca5e16575b 100644 --- a/packages/core/src/utils/CoreHelperUtil.ts +++ b/packages/core/src/utils/CoreHelperUtil.ts @@ -1,4 +1,5 @@ import type { Balance } from '@web3modal/common' +import { ConstantsUtil as CommonConstants } from '@web3modal/common' import { ConstantsUtil } from './ConstantsUtil.js' import type { CaipAddress, LinkingRecord, CaipNetwork } from './TypeUtil.js' @@ -174,33 +175,16 @@ export const CoreHelperUtil = { } }, - isRestrictedRegion() { - try { - const { timeZone } = new Intl.DateTimeFormat().resolvedOptions() - const capTimeZone = timeZone.toUpperCase() - - return ConstantsUtil.RESTRICTED_TIMEZONES.includes(capTimeZone) - } catch { - return false - } - }, - getApiUrl() { - return CoreHelperUtil.isRestrictedRegion() - ? 'https://api.web3modal.org' - : 'https://api.web3modal.com' + return CommonConstants.W3M_API_URL }, getBlockchainApiUrl() { - return CoreHelperUtil.isRestrictedRegion() - ? 'https://rpc.walletconnect.org' - : 'https://rpc.walletconnect.com' + return CommonConstants.BLOCKCHAIN_API_RPC_URL }, getAnalyticsUrl() { - return CoreHelperUtil.isRestrictedRegion() - ? 'https://pulse.walletconnect.org' - : 'https://pulse.walletconnect.com' + return CommonConstants.PULSE_API_URL }, getUUID() { diff --git a/packages/solana/src/client.ts b/packages/solana/src/client.ts index 11c8789de6..cea5a8e0a8 100644 --- a/packages/solana/src/client.ts +++ b/packages/solana/src/client.ts @@ -208,7 +208,7 @@ export class Web3Modal extends Web3ModalScaffold { this.walletAdapters = createWalletAdapters(chain?.chainId) this.WalletConnectConnector = new WalletConnectConnector({ - relayerRegion: 'wss://relay.walletconnect.com', + relayerRegion: 'wss://relay.walletconnect.org', metadata, chains, qrcode: true diff --git a/packages/solana/src/utils/chains.ts b/packages/solana/src/utils/chains.ts index c7da8759ef..1f2ce6000c 100644 --- a/packages/solana/src/utils/chains.ts +++ b/packages/solana/src/utils/chains.ts @@ -1,9 +1,11 @@ +import { ConstantsUtil } from '@web3modal/common' + export const solana = { chainId: '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp', name: 'Solana', currency: 'SOL', explorerUrl: 'https://solscan.io', - rpcUrl: 'https://rpc.walletconnect.com/v1' + rpcUrl: `${ConstantsUtil.BLOCKCHAIN_API_RPC_URL}/v1` } export const solanaTestnet = { diff --git a/packages/solana/src/utils/scaffold/SolanaConstantsUtil.ts b/packages/solana/src/utils/scaffold/SolanaConstantsUtil.ts index b5237da076..946d413220 100644 --- a/packages/solana/src/utils/scaffold/SolanaConstantsUtil.ts +++ b/packages/solana/src/utils/scaffold/SolanaConstantsUtil.ts @@ -1,4 +1,5 @@ import { PublicKey } from '@solana/web3.js' +import { ConstantsUtil } from '@web3modal/common' /** * Request methods to the solana RPC. @@ -30,6 +31,6 @@ export const SolConstantsUtil = { name: 'Solana', currency: 'SOL', explorerUrl: 'https://solscan.io', - rpcUrl: 'https://rpc.walletconnect.com/v1' + rpcUrl: `${ConstantsUtil.BLOCKCHAIN_API_RPC_URL}/v1` } } diff --git a/packages/solana/src/utils/scaffold/SolanaHelpersUtils.ts b/packages/solana/src/utils/scaffold/SolanaHelpersUtils.ts index 687fb2df17..c16ee8eccf 100644 --- a/packages/solana/src/utils/scaffold/SolanaHelpersUtils.ts +++ b/packages/solana/src/utils/scaffold/SolanaHelpersUtils.ts @@ -1,4 +1,5 @@ import { PresetsUtil } from '@web3modal/scaffold-utils' +import { ConstantsUtil } from '@web3modal/common' import { SolConstantsUtil } from './SolanaConstantsUtil.js' @@ -7,7 +8,7 @@ import type { Chain, Provider } from './SolanaTypesUtil.js' export const SolHelpersUtil = { detectRpcUrl(chain: Chain, projectId: string) { - if (chain.rpcUrl.includes('rpc.walletconnect.com/')) { + if (chain.rpcUrl.includes(new URL(ConstantsUtil.BLOCKCHAIN_API_RPC_URL).hostname)) { return `${chain.rpcUrl}?chainId=solana:${chain.chainId}&projectId=${projectId}` } diff --git a/packages/wallet/src/W3mFrame.ts b/packages/wallet/src/W3mFrame.ts index 7a4ee06bda..c2917c04ab 100644 --- a/packages/wallet/src/W3mFrame.ts +++ b/packages/wallet/src/W3mFrame.ts @@ -2,6 +2,7 @@ import { SECURE_SITE_SDK, W3mFrameConstants } from './W3mFrameConstants.js' import { W3mFrameSchema } from './W3mFrameSchema.js' import { W3mFrameHelpers } from './W3mFrameHelpers.js' import type { W3mFrameTypes } from './W3mFrameTypes.js' +import { ConstantsUtil } from '@web3modal/common' // -- Sdk -------------------------------------------------------------------- export class W3mFrame { @@ -9,7 +10,7 @@ export class W3mFrame { private projectId: string - private rpcUrl = W3mFrameHelpers.getBlockchainApiUrl() + private rpcUrl = ConstantsUtil.BLOCKCHAIN_API_RPC_URL public frameLoadPromise: Promise diff --git a/packages/wallet/src/W3mFrameHelpers.ts b/packages/wallet/src/W3mFrameHelpers.ts index 40eeb71071..6e1f61bc43 100644 --- a/packages/wallet/src/W3mFrameHelpers.ts +++ b/packages/wallet/src/W3mFrameHelpers.ts @@ -7,35 +7,9 @@ import { import type { W3mFrameTypes } from './W3mFrameTypes.js' import { RegexUtil } from './RegexUtil.js' -const RESTRICTED_TIMEZONES = [ - 'ASIA/SHANGHAI', - 'ASIA/URUMQI', - 'ASIA/CHONGQING', - 'ASIA/HARBIN', - 'ASIA/KASHGAR', - 'ASIA/MACAU', - 'ASIA/HONG_KONG', - 'ASIA/MACAO', - 'ASIA/BEIJING', - 'ASIA/HARBIN' -] - const EMAIL_MINIMUM_TIMEOUT = 30 * 1000 export const W3mFrameHelpers = { - getBlockchainApiUrl() { - try { - const { timeZone } = new Intl.DateTimeFormat().resolvedOptions() - const capTimeZone = timeZone.toUpperCase() - - return RESTRICTED_TIMEZONES.includes(capTimeZone) - ? 'https://rpc.walletconnect.org' - : 'https://rpc.walletconnect.com' - } catch { - return false - } - }, - checkIfAllowedToTriggerEmail() { const lastEmailLoginTime = W3mFrameStorage.get(W3mFrameConstants.LAST_EMAIL_LOGIN_TIME) if (lastEmailLoginTime) {