diff --git a/packages/bridge-ui/src/components/ChainDropdown.svelte b/packages/bridge-ui/src/components/ChainDropdown.svelte
index 7bf0edf1a42..73667a67a6f 100644
--- a/packages/bridge-ui/src/components/ChainDropdown.svelte
+++ b/packages/bridge-ui/src/components/ChainDropdown.svelte
@@ -2,7 +2,7 @@
import { _ } from "svelte-i18n";
import ChevDown from "./icons/ChevDown.svelte";
- import { fromChain } from "../store/chain";
+ import { fromChain, toChain } from "../store/chain";
import MetaMask from "./icons/MetaMask.svelte";
import { switchEthereumChain } from "../utils/switchEthereumChain";
import { ethereum } from "../store/ethereum";
@@ -15,6 +15,12 @@
const provider = new ethers.providers.Web3Provider(window.ethereum);
await provider.send("eth_requestAccounts", []);
+ fromChain.set(chain);
+ if (chain === CHAIN_MAINNET) {
+ toChain.set(CHAIN_TKO);
+ } else {
+ toChain.set(CHAIN_MAINNET);
+ }
signer.set(provider.getSigner());
};
@@ -45,7 +51,7 @@
>
{CHAIN_MAINNET.name}
-
+
@@ -57,7 +63,7 @@
>
{CHAIN_TKO.name}
-
+
diff --git a/packages/bridge-ui/src/components/form/SelectChain.svelte b/packages/bridge-ui/src/components/form/SelectChain.svelte
index c003fbe66d5..aaedec2282a 100644
--- a/packages/bridge-ui/src/components/form/SelectChain.svelte
+++ b/packages/bridge-ui/src/components/form/SelectChain.svelte
@@ -2,15 +2,25 @@
import ArrowRight from "../icons/ArrowRight.svelte";
import { fromChain, toChain } from "../../store/chain";
import { CHAIN_MAINNET, CHAIN_TKO } from "../../domain/chain";
+ import { ethereum } from "../../store/ethereum";
+ import { signer } from "../../store/signer";
+ import { switchEthereumChain } from "../../utils/switchEthereumChain";
+ import { ethers } from "ethers";
- function toggleChains() {
- fromChain.update((val) =>
- val === CHAIN_MAINNET ? CHAIN_TKO : CHAIN_MAINNET
- );
- toChain.update((val) =>
- val === CHAIN_MAINNET ? CHAIN_TKO : CHAIN_MAINNET
- );
- }
+ const toggleChains = async () => {
+ const chain = $fromChain === CHAIN_MAINNET ? CHAIN_TKO : CHAIN_MAINNET;
+ await switchEthereumChain($ethereum, chain);
+ const provider = new ethers.providers.Web3Provider(window.ethereum);
+ await provider.send("eth_requestAccounts", []);
+
+ fromChain.set(chain);
+ if (chain === CHAIN_MAINNET) {
+ toChain.set(CHAIN_TKO);
+ } else {
+ toChain.set(CHAIN_MAINNET);
+ }
+ signer.set(provider.getSigner());
+ };