Skip to content

Commit 8a1d6d9

Browse files
feat: add chain switch (#135)
* chore: update dependencies for @iexec/dataprotector, @iexec/web3mail, and @iexec/web3telegram * feat: add ChainSelector component and integrate chain switching functionality * feat: include chainId in userStore to enable refresh on chain update * feat: add whitelist addresses to supported chains and refactor related functions * feat: refactor chain switching logic and update GrantAccessModal to use dynamic whitelist addresses * refactor: remove unnecessary console.log statements in AddProtectedData and ProtectedDataList components * feat: implement useChainChangeRedirect hook and integrate it into SendMessage and ProtectedData components * refactor: improve code quality --------- Co-authored-by: paypes <[email protected]>
1 parent d7a1e96 commit 8a1d6d9

20 files changed

+408
-103
lines changed

package-lock.json

Lines changed: 79 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
"@fontsource/space-grotesk": "^5.2.5",
2323
"@fontsource/space-mono": "^5.2.5",
2424
"@graphql-codegen/introspection": "^4.0.3",
25-
"@iexec/dataprotector": "^2.0.0-beta.18",
26-
"@iexec/web3mail": "^1.4.0",
27-
"@iexec/web3telegram": "^0.1.0-alpha.3",
25+
"@iexec/dataprotector": "^2.0.0-beta.19",
26+
"@iexec/web3mail": "^1.5.0",
27+
"@iexec/web3telegram": "^0.1.0-alpha.4",
2828
"@radix-ui/react-dialog": "^1.1.6",
2929
"@radix-ui/react-label": "^2.1.2",
3030
"@radix-ui/react-select": "^2.1.6",

src/assets/chain-icons/arbitrum.svg

Lines changed: 21 additions & 0 deletions
Loading
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { switchChain } from '@wagmi/core';
2+
import useUserStore from '@/stores/useUser.store.ts';
3+
import { getSupportedChains } from '@/utils/chain.utils.ts';
4+
import { wagmiAdapter } from '@/utils/wagmiConfig.ts';
5+
import {
6+
Select,
7+
SelectContent,
8+
SelectItem,
9+
SelectTrigger,
10+
SelectValue,
11+
} from '../ui/select.tsx';
12+
13+
export function ChainSelector({ className }: { className?: string }) {
14+
const { chainId } = useUserStore();
15+
const handleChainChange = async (value: string) => {
16+
const chainId = Number(value);
17+
await switchChain(wagmiAdapter.wagmiConfig, { chainId });
18+
};
19+
20+
const filteredChains = getSupportedChains();
21+
22+
return (
23+
<Select
24+
value={chainId?.toString()}
25+
onValueChange={handleChainChange}
26+
defaultValue="-1"
27+
>
28+
<SelectTrigger className={className}>
29+
<SelectValue placeholder="Select Chain" />
30+
</SelectTrigger>
31+
<SelectContent className="border-grey-600">
32+
{filteredChains.map((chain) => (
33+
<SelectItem key={chain.id} value={chain.id.toString()}>
34+
<img src={chain.icon} className="size-4" alt="" /> {chain.name}
35+
</SelectItem>
36+
))}
37+
</SelectContent>
38+
</Select>
39+
);
40+
}

src/components/navBar/NavBar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import iExecLogo from '../../assets/iexec-logo.svg';
77
import { Button } from '../ui/button.tsx';
88
import { Label } from '../ui/label.tsx';
99
import { Switch } from '../ui/switch.tsx';
10+
import { ChainSelector } from './ChainSelector.tsx';
1011
import { navigationItems } from './navigationItems.tsx';
1112

1213
export function NavBar() {
@@ -46,8 +47,9 @@ export function NavBar() {
4647
WEB3 Messaging
4748
</div>
4849
</Link>
50+
<ChainSelector className="border-grey-600 mt-4 w-full" />
4951

50-
<div className="left-navbar text-grey-400 mt-10 flex grow flex-col gap-10">
52+
<div className="left-navbar text-grey-400 mt-6 flex grow flex-col gap-10">
5153
<div className="mt-0.5 grow">
5254
{navigationItems.map((item, index) => (
5355
<NavLink

0 commit comments

Comments
 (0)