Skip to content

Commit

Permalink
toggle chain fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey committed Dec 8, 2022
1 parent c895430 commit ab3db35
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions packages/bridge-ui/src/components/form/SelectChain.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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());
};
</script>

<div class="flex items-center justify-between w-full p-8 py-6 text-lg">
Expand Down

0 comments on commit ab3db35

Please sign in to comment.