Skip to content

Commit 6e2d4f7

Browse files
committed
removing stuff from toolbox and wallet store
1 parent 04584c4 commit 6e2d4f7

File tree

11 files changed

+122
-77
lines changed

11 files changed

+122
-77
lines changed

app/console/history/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,13 @@ export default function ConsoleHistoryPage() {
140140
type: 'address'
141141
});
142142
}
143-
if (toolboxStore.wrappedNativeTokenAddress && toolboxStore.wrappedNativeTokenAddress !== '') {
143+
// Get wrapped native token address from L1 store
144+
if (selectedL1?.wrappedTokenAddress && selectedL1.wrappedTokenAddress !== '') {
144145
items.push({
145146
id: 'tb-wrapped-native',
146147
title: 'Wrapped Native Token',
147148
description: 'Token Contract',
148-
address: toolboxStore.wrappedNativeTokenAddress,
149+
address: selectedL1.wrappedTokenAddress,
149150
chainId,
150151
type: 'address'
151152
});

components/toolbox/console/ictt/setup/DeployTokenHome.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import ERC20TokenHome from "@/contracts/icm-contracts/compiled/ERC20TokenHome.json";
44
import NativeTokenHome from "@/contracts/icm-contracts/compiled/NativeTokenHome.json";
55
import { useToolboxStore, useViemChainStore } from "@/components/toolbox/stores/toolboxStore";
6+
import { useWrappedNativeToken } from "@/components/toolbox/stores/l1ListStore";
67
import { useWalletStore } from "@/components/toolbox/stores/walletStore";
78
import { useState, useEffect } from "react";
89
import { Button } from "@/components/toolbox/components/Button";
@@ -22,12 +23,12 @@ export default function DeployTokenHome() {
2223
const [criticalError, setCriticalError] = useState<Error | null>(null);
2324
const {
2425
exampleErc20Address,
25-
wrappedNativeTokenAddress,
2626
setErc20TokenHomeAddress,
2727
erc20TokenHomeAddress,
2828
setNativeTokenHomeAddress,
2929
nativeTokenHomeAddress
3030
} = useToolboxStore();
31+
const wrappedNativeTokenAddress = useWrappedNativeToken();
3132
const selectedL1 = useSelectedL1()();
3233
const { coreWalletClient, walletEVMAddress, walletChainId } = useWalletStore();
3334
const { notify } = useConsoleNotifications();

components/toolbox/console/ictt/setup/DeployWrappedNative.tsx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"use client";
22

33
import WrappedNativeToken from "@/contracts/icm-contracts/compiled/WrappedNativeToken.json";
4-
import { useToolboxStore, useViemChainStore, useWrappedNativeToken, useSetWrappedNativeToken } from "@/components/toolbox/stores/toolboxStore";
5-
import { useWalletStore, useNativeCurrencyInfo } from "@/components/toolbox/stores/walletStore";
4+
import { useToolboxStore, useViemChainStore } from "@/components/toolbox/stores/toolboxStore";
5+
import { useWrappedNativeToken, useSetWrappedNativeToken } from "@/components/toolbox/stores/l1ListStore";
6+
import { useWalletStore } from "@/components/toolbox/stores/walletStore";
7+
import { useNativeCurrencyInfo, useSetNativeCurrencyInfo } from "@/components/toolbox/stores/l1ListStore";
68
import { useState, useEffect } from "react";
79
import { Button } from "@/components/toolbox/components/Button";
810
import { Success } from "@/components/toolbox/components/Success";
@@ -34,14 +36,14 @@ const metadata: ConsoleToolMetadata = {
3436
function DeployWrappedNative({ onSuccess }: BaseConsoleToolProps) {
3537
const [criticalError, setCriticalError] = useState<Error | null>(null);
3638

37-
const { wrappedNativeTokenAddress: wrappedNativeTokenAddressStore, setWrappedNativeTokenAddress } = useToolboxStore();
3839
const setWrappedNativeToken = useSetWrappedNativeToken();
3940
const selectedL1 = useSelectedL1()();
4041
const [wrappedNativeTokenAddress, setLocalWrappedNativeTokenAddress] = useState<string>('');
4142
const [hasPredeployedToken, setHasPredeployedToken] = useState(false);
4243
const [isCheckingToken, setIsCheckingToken] = useState(false);
4344
const { coreWalletClient } = useConnectedWallet();
44-
const { walletEVMAddress, walletChainId, setNativeCurrencyInfo } = useWalletStore();
45+
const { walletEVMAddress, walletChainId } = useWalletStore();
46+
const setNativeCurrencyInfo = useSetNativeCurrencyInfo();
4547
const { notify } = useConsoleNotifications();
4648
const viemChain = useViemChainStore();
4749
const [isDeploying, setIsDeploying] = useState(false);
@@ -70,17 +72,15 @@ function DeployWrappedNative({ onSuccess }: BaseConsoleToolProps) {
7072

7173
// Cache native currency info if not already cached
7274
if (!cachedNativeCurrency && viemChain.nativeCurrency) {
73-
setNativeCurrencyInfo(chainIdStr, viemChain.nativeCurrency);
75+
setNativeCurrencyInfo(walletChainId, viemChain.nativeCurrency);
7476
}
7577

7678
// Check cache first for wrapped token
7779
let tokenAddress = cachedWrappedToken || '';
7880

7981
// If not in cache, check other sources
8082
if (!tokenAddress) {
81-
if (wrappedNativeTokenAddressStore) {
82-
tokenAddress = wrappedNativeTokenAddressStore;
83-
} else if (selectedL1?.wrappedTokenAddress) {
83+
if (selectedL1?.wrappedTokenAddress) {
8484
tokenAddress = selectedL1.wrappedTokenAddress;
8585
} else {
8686
// Check if pre-deployed wrapped native token exists
@@ -106,8 +106,8 @@ function DeployWrappedNative({ onSuccess }: BaseConsoleToolProps) {
106106
setLocalWrappedNativeTokenAddress(tokenAddress);
107107

108108
// If we detected pre-deployed token and nothing in store, save it
109-
if (tokenAddress === PREDEPLOYED_WRAPPED_NATIVE_ADDRESS && !wrappedNativeTokenAddressStore && !selectedL1?.wrappedTokenAddress) {
110-
setWrappedNativeTokenAddress(PREDEPLOYED_WRAPPED_NATIVE_ADDRESS);
109+
if (tokenAddress === PREDEPLOYED_WRAPPED_NATIVE_ADDRESS && !selectedL1?.wrappedTokenAddress) {
110+
setWrappedNativeToken(PREDEPLOYED_WRAPPED_NATIVE_ADDRESS);
111111
}
112112
} catch (error) {
113113
console.error('Error checking token:', error);
@@ -117,7 +117,7 @@ function DeployWrappedNative({ onSuccess }: BaseConsoleToolProps) {
117117
}
118118

119119
checkToken();
120-
}, [viemChain, walletEVMAddress, wrappedNativeTokenAddressStore, selectedL1, walletChainId, cachedWrappedToken, cachedNativeCurrency, setNativeCurrencyInfo]);
120+
}, [viemChain, walletEVMAddress, selectedL1, walletChainId, cachedWrappedToken, cachedNativeCurrency, setNativeCurrencyInfo]);
121121

122122
async function handleDeploy() {
123123
setIsDeploying(true);
@@ -146,10 +146,8 @@ function DeployWrappedNative({ onSuccess }: BaseConsoleToolProps) {
146146
throw new Error('No contract address in receipt');
147147
}
148148

149-
setWrappedNativeTokenAddress(receipt.contractAddress);
150-
setLocalWrappedNativeTokenAddress(receipt.contractAddress);
151-
// Also update the cached wrapped native token for consistency
152149
setWrappedNativeToken(receipt.contractAddress);
150+
setLocalWrappedNativeTokenAddress(receipt.contractAddress);
153151
} catch (error) {
154152
setCriticalError(error instanceof Error ? error : new Error(String(error)));
155153
} finally {

components/toolbox/console/ictt/setup/wrappedNativeToken/DisplayNativeBalance.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

3-
import { useWalletStore, useNativeCurrencyInfo, useL1Balance, useL1Loading } from "@/components/toolbox/stores/walletStore";
3+
import { useWalletStore, useL1Balance, useL1Loading } from "@/components/toolbox/stores/walletStore";
4+
import { useNativeCurrencyInfo, useSetNativeCurrencyInfo } from "@/components/toolbox/stores/l1ListStore";
45
import { useViemChainStore } from "@/components/toolbox/stores/toolboxStore";
56
import { useEffect } from "react";
67

@@ -9,7 +10,8 @@ interface DisplayNativeBalanceProps {
910
}
1011

1112
export default function DisplayNativeBalance({ onError }: DisplayNativeBalanceProps) {
12-
const { walletChainId, setNativeCurrencyInfo } = useWalletStore();
13+
const { walletChainId } = useWalletStore();
14+
const setNativeCurrencyInfo = useSetNativeCurrencyInfo();
1315
const viemChain = useViemChainStore();
1416

1517
// Get cached values from wallet store
@@ -26,9 +28,9 @@ export default function DisplayNativeBalance({ onError }: DisplayNativeBalancePr
2628
// Cache native currency info if not already cached
2729
useEffect(() => {
2830
if (!cachedNativeCurrency && viemChain?.nativeCurrency) {
29-
setNativeCurrencyInfo(chainIdStr, viemChain.nativeCurrency);
31+
setNativeCurrencyInfo(walletChainId, viemChain.nativeCurrency);
3032
}
31-
}, [cachedNativeCurrency, viemChain?.nativeCurrency, chainIdStr, setNativeCurrencyInfo]);
33+
}, [cachedNativeCurrency, viemChain?.nativeCurrency, walletChainId, setNativeCurrencyInfo]);
3234

3335
if (isLoading) {
3436
return (

components/toolbox/console/ictt/setup/wrappedNativeToken/DisplayWrappedBalance.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"use client";
22

3-
import { useWalletStore, useNativeCurrencyInfo } from "@/components/toolbox/stores/walletStore";
4-
import { useViemChainStore, useWrappedNativeToken as useWrappedNativeTokenAddress, useSetWrappedNativeToken } from "@/components/toolbox/stores/toolboxStore";
3+
import { useWalletStore } from "@/components/toolbox/stores/walletStore";
4+
import { useNativeCurrencyInfo, useSetNativeCurrencyInfo } from "@/components/toolbox/stores/l1ListStore";
5+
import { useViemChainStore } from "@/components/toolbox/stores/toolboxStore";
6+
import { useWrappedNativeToken as useWrappedNativeTokenAddress, useSetWrappedNativeToken } from "@/components/toolbox/stores/l1ListStore";
57
import { useWrappedNativeToken } from "@/components/toolbox/hooks/useWrappedNativeToken";
68
import { balanceService } from "@/components/toolbox/services/balanceService";
79
import { useState, useEffect } from "react";
@@ -12,7 +14,8 @@ interface DisplayWrappedBalanceProps {
1214
}
1315

1416
export default function DisplayWrappedBalance({ wrappedNativeTokenAddress, onError }: DisplayWrappedBalanceProps) {
15-
const { walletEVMAddress, walletChainId, setNativeCurrencyInfo } = useWalletStore();
17+
const { walletEVMAddress, walletChainId } = useWalletStore();
18+
const setNativeCurrencyInfo = useSetNativeCurrencyInfo();
1619
const viemChain = useViemChainStore();
1720
const setWrappedNativeToken = useSetWrappedNativeToken();
1821
const wrappedNativeToken = useWrappedNativeToken();
@@ -39,7 +42,7 @@ export default function DisplayWrappedBalance({ wrappedNativeTokenAddress, onErr
3942

4043
// Cache native currency info if not already cached
4144
if (!cachedNativeCurrency && viemChain?.nativeCurrency) {
42-
setNativeCurrencyInfo(chainIdStr, viemChain.nativeCurrency);
45+
setNativeCurrencyInfo(walletChainId, viemChain.nativeCurrency);
4346
}
4447

4548
// Cache the token address if we found one

components/toolbox/console/ictt/setup/wrappedNativeToken/UnwrapNativeToken.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"use client";
22

3-
import { useWalletStore, useNativeCurrencyInfo } from "@/components/toolbox/stores/walletStore";
4-
import { useViemChainStore, useWrappedNativeToken as useWrappedNativeTokenAddress, useSetWrappedNativeToken } from "@/components/toolbox/stores/toolboxStore";
3+
import { useWalletStore } from "@/components/toolbox/stores/walletStore";
4+
import { useNativeCurrencyInfo, useSetNativeCurrencyInfo } from "@/components/toolbox/stores/l1ListStore";
5+
import { useViemChainStore } from "@/components/toolbox/stores/toolboxStore";
6+
import { useWrappedNativeToken as useWrappedNativeTokenAddress, useSetWrappedNativeToken } from "@/components/toolbox/stores/l1ListStore";
57
import { useWrappedNativeToken } from "@/components/toolbox/hooks/useWrappedNativeToken";
68
import { useState, useEffect } from "react";
79
import { Button } from "@/components/toolbox/components/Button";
@@ -13,7 +15,8 @@ interface UnwrapNativeTokenProps {
1315
}
1416

1517
export default function UnwrapNativeToken({ wrappedNativeTokenAddress, onError }: UnwrapNativeTokenProps) {
16-
const { walletEVMAddress, walletChainId, setNativeCurrencyInfo } = useWalletStore();
18+
const { walletEVMAddress, walletChainId } = useWalletStore();
19+
const setNativeCurrencyInfo = useSetNativeCurrencyInfo();
1720
const viemChain = useViemChainStore();
1821
const setWrappedNativeToken = useSetWrappedNativeToken();
1922
const wrappedNativeToken = useWrappedNativeToken();
@@ -38,7 +41,7 @@ export default function UnwrapNativeToken({ wrappedNativeTokenAddress, onError }
3841

3942
// Cache native currency info if not already cached
4043
if (!cachedNativeCurrency && viemChain.nativeCurrency) {
41-
setNativeCurrencyInfo(chainIdStr, viemChain.nativeCurrency);
44+
setNativeCurrencyInfo(walletChainId, viemChain.nativeCurrency);
4245
}
4346

4447
// Cache the token address if we found one

components/toolbox/console/ictt/setup/wrappedNativeToken/WrapNativeToken.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"use client";
22

3-
import { useWalletStore, useNativeCurrencyInfo } from "@/components/toolbox/stores/walletStore";
4-
import { useViemChainStore, useWrappedNativeToken as useWrappedNativeTokenAddress, useSetWrappedNativeToken } from "@/components/toolbox/stores/toolboxStore";
3+
import { useWalletStore } from "@/components/toolbox/stores/walletStore";
4+
import { useNativeCurrencyInfo, useSetNativeCurrencyInfo } from "@/components/toolbox/stores/l1ListStore";
5+
import { useViemChainStore } from "@/components/toolbox/stores/toolboxStore";
6+
import { useWrappedNativeToken as useWrappedNativeTokenAddress, useSetWrappedNativeToken } from "@/components/toolbox/stores/l1ListStore";
57
import { useWrappedNativeToken } from "@/components/toolbox/hooks/useWrappedNativeToken";
68
import { useState, useEffect } from "react";
79
import { Button } from "@/components/toolbox/components/Button";
@@ -13,7 +15,8 @@ interface WrapNativeTokenProps {
1315
}
1416

1517
export default function WrapNativeToken({ wrappedNativeTokenAddress, onError }: WrapNativeTokenProps) {
16-
const { walletEVMAddress, walletChainId, setNativeCurrencyInfo } = useWalletStore();
18+
const { walletEVMAddress, walletChainId } = useWalletStore();
19+
const setNativeCurrencyInfo = useSetNativeCurrencyInfo();
1720
const viemChain = useViemChainStore();
1821
const setWrappedNativeToken = useSetWrappedNativeToken();
1922
const wrappedNativeToken = useWrappedNativeToken();
@@ -37,7 +40,7 @@ export default function WrapNativeToken({ wrappedNativeTokenAddress, onError }:
3740

3841
// Cache native currency info if not already cached
3942
if (!cachedNativeCurrency && viemChain.nativeCurrency) {
40-
setNativeCurrencyInfo(chainIdStr, viemChain.nativeCurrency);
43+
setNativeCurrencyInfo(walletChainId, viemChain.nativeCurrency);
4144
}
4245

4346
// Cache the token address if we found one

components/toolbox/hooks/useWrappedNativeToken.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useMemo } from 'react';
22
import { useWalletStore } from '../stores/walletStore';
3-
import { useViemChainStore, useWrappedNativeToken as useWrappedNativeTokenAddress } from '../stores/toolboxStore';
3+
import { useViemChainStore } from '../stores/toolboxStore';
4+
import { useWrappedNativeToken as useWrappedNativeTokenAddress } from '../stores/l1ListStore';
45
import { http, createPublicClient, parseEther, formatEther } from 'viem';
56
import WrappedNativeToken from '@/contracts/icm-contracts/compiled/WrappedNativeToken.json';
67
import useConsoleNotifications from '@/hooks/useConsoleNotifications';

components/toolbox/stores/l1ListStore.ts

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ export type L1ListItem = {
2222
hasBuilderHubFaucet?: boolean;
2323
dripAmount?: number;
2424
features?: string[];
25+
// Native currency cache - extended info beyond just coinName
26+
nativeCurrency?: {
27+
name: string;
28+
symbol: string;
29+
decimals: number;
30+
};
2531
};
2632

2733
const l1ListInitialStateFuji = {
@@ -132,9 +138,22 @@ export const getL1ListStore = (isTestnet: boolean) => {
132138
if (!testnetStoreSingleton) {
133139
testnetStoreSingleton = create(
134140
persist(
135-
combine(l1ListInitialStateFuji, (set) => ({
141+
combine(l1ListInitialStateFuji, (set, get) => ({
136142
addL1: (l1: L1ListItem) => set((state) => ({ l1List: [...state.l1List, l1] })),
137143
removeL1: (l1Id: string) => set((state) => ({ l1List: state.l1List.filter((l) => l.id !== l1Id) })),
144+
setNativeCurrencyInfo: (chainId: number, info: { name: string; symbol: string; decimals: number }) => {
145+
set((state) => ({
146+
l1List: state.l1List.map((l1) =>
147+
l1.evmChainId === chainId
148+
? { ...l1, nativeCurrency: info }
149+
: l1
150+
)
151+
}));
152+
},
153+
getNativeCurrencyInfo: (chainId: number) => {
154+
const l1 = get().l1List.find((l1) => l1.evmChainId === chainId);
155+
return l1?.nativeCurrency;
156+
},
138157
reset: () => {
139158
window?.localStorage.removeItem(`${STORE_VERSION}-l1-list-store-testnet`);
140159
},
@@ -151,9 +170,22 @@ export const getL1ListStore = (isTestnet: boolean) => {
151170
if (!mainnetStoreSingleton) {
152171
mainnetStoreSingleton = create(
153172
persist(
154-
combine(l1ListInitialStateMainnet, (set) => ({
173+
combine(l1ListInitialStateMainnet, (set, get) => ({
155174
addL1: (l1: L1ListItem) => set((state) => ({ l1List: [...state.l1List, l1] })),
156175
removeL1: (l1Id: string) => set((state) => ({ l1List: state.l1List.filter((l) => l.id !== l1Id) })),
176+
setNativeCurrencyInfo: (chainId: number, info: { name: string; symbol: string; decimals: number }) => {
177+
set((state) => ({
178+
l1List: state.l1List.map((l1) =>
179+
l1.evmChainId === chainId
180+
? { ...l1, nativeCurrency: info }
181+
: l1
182+
)
183+
}));
184+
},
185+
getNativeCurrencyInfo: (chainId: number) => {
186+
const l1 = get().l1List.find((l1) => l1.evmChainId === chainId);
187+
return l1?.nativeCurrency;
188+
},
157189
reset: () => {
158190
window?.localStorage.removeItem(`${STORE_VERSION}-l1-list-store-mainnet`);
159191
},
@@ -212,3 +244,43 @@ export function useL1ByChainId(chainId: string) {
212244
[chainId, l1ListStore]
213245
);
214246
}
247+
248+
// Native currency hooks for L1 store
249+
export const useSetNativeCurrencyInfo = () => {
250+
const l1ListStore = useL1ListStore();
251+
252+
return (chainId: number, info: { name: string; symbol: string; decimals: number }) => {
253+
l1ListStore.getState().setNativeCurrencyInfo(chainId, info);
254+
};
255+
};
256+
257+
export const useNativeCurrencyInfo = (chainId?: number) => {
258+
const { walletChainId } = useWalletStore();
259+
const l1ListStore = useL1ListStore();
260+
const effectiveChainId = chainId || walletChainId;
261+
262+
return useMemo(() => {
263+
return l1ListStore.getState().getNativeCurrencyInfo(effectiveChainId);
264+
}, [l1ListStore, effectiveChainId]);
265+
};
266+
267+
// Wrapped native token hooks
268+
export const useWrappedNativeToken = () => {
269+
const selectedL1 = useSelectedL1()();
270+
return selectedL1?.wrappedTokenAddress || "";
271+
};
272+
273+
export const useSetWrappedNativeToken = () => {
274+
const { walletChainId } = useWalletStore();
275+
const l1ListStore = useL1ListStore();
276+
277+
return (address: string) => {
278+
const currentL1List = l1ListStore.getState().l1List;
279+
const updatedL1List = currentL1List.map((l1: L1ListItem) =>
280+
l1.evmChainId === walletChainId
281+
? { ...l1, wrappedTokenAddress: address }
282+
: l1
283+
);
284+
l1ListStore.setState({ l1List: updatedL1List });
285+
};
286+
};

0 commit comments

Comments
 (0)