From 1025bff5618d1aabee7c758bbfacc7baac031882 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 12 Jan 2024 05:25:55 +0200 Subject: [PATCH] test: wallet connect --- src/web3/providers/WagmiProvider.tsx | 19 +++++++++++-------- src/web3/store/walletSlice.ts | 22 ++++++++++------------ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/web3/providers/WagmiProvider.tsx b/src/web3/providers/WagmiProvider.tsx index bbd3b1c..7fc2ca3 100644 --- a/src/web3/providers/WagmiProvider.tsx +++ b/src/web3/providers/WagmiProvider.tsx @@ -6,7 +6,7 @@ import { watchAccount, } from '@wagmi/core'; import React, { useEffect, useMemo, useState } from 'react'; -import { Chain, fallback, Hex, http, Transport } from 'viem'; +import { fallback, Hex, http, Transport } from 'viem'; import { mainnet } from 'viem/chains'; import { CreateConnectorFn, WagmiProvider as BaseWagmiProvider } from 'wagmi'; import { StoreApi, UseBoundStore } from 'zustand'; @@ -102,13 +102,16 @@ export function WagmiProvider({ ...Object.values(chains), ]; - const chainsArrayFlags: Record = {}; - const chainsArrayUnique: Chain[] = []; - for (let i = 0; i < chainsArray.length; i++) { - if (chainsArrayFlags[chainsArray[i].id]) continue; - chainsArrayFlags[chainsArray[i].id] = true; - chainsArrayUnique.push(chainsArray[i]); - } + // const chainsArrayFlags: Record = {}; + // const chainsArrayUnique: Chain[] = []; + // for (let i = 0; i < chainsArray.length; i++) { + // if (chainsArrayFlags[chainsArray[i].id]) continue; + // chainsArrayFlags[chainsArray[i].id] = true; + // chainsArrayUnique.push(chainsArray[i]); + // } + const chainsArrayUnique = [ + ...new Map(chainsArray.map((item) => [item['id'], item])).values(), + ]; return createConfig({ chains: [chainsArray[0], ...chainsArrayUnique], diff --git a/src/web3/store/walletSlice.ts b/src/web3/store/walletSlice.ts index 4ed8890..13a3ba2 100644 --- a/src/web3/store/walletSlice.ts +++ b/src/web3/store/walletSlice.ts @@ -8,7 +8,7 @@ import { getPublicClient, switchChain, } from '@wagmi/core'; -import { Draft, produce } from 'immer'; +import { produce } from 'immer'; import { Account, Chain, @@ -360,17 +360,15 @@ export function createWalletSlice({ const config = get().wagmiConfig; if (config) { - set((state) => - produce(state, (draft) => { - draft.wagmiConfig = { - ...draft.wagmiConfig, - state: { - ...draft.wagmiConfig?.state, - chainId: account?.chainId || get().defaultChainId || mainnet.id, - }, - } as Draft; - }), - ); + set({ + wagmiConfig: { + ...config, + state: { + ...config.state, + chainId: account?.chainId || get().defaultChainId || mainnet.id, + }, + }, + }); } if (