Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bridge): use metamask wagmi connector #2080

Merged
merged 4 commits into from
Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/bridge-ui/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import {
configureChains,
createClient,
InjectedConnector,
} from "@wagmi/core";
import { publicProvider } from "@wagmi/core/providers/public";
import { jsonRpcProvider } from "@wagmi/core/providers/jsonRpc";
import { CoinbaseWalletConnector } from "@wagmi/core/connectors/coinbaseWallet";
import { WalletConnectConnector } from "@wagmi/core/connectors/walletConnect";
import { MetaMaskConnector } from '@wagmi/core/connectors/metaMask'

import Home from "./pages/home/Home.svelte";
import { setupI18n } from "./i18n";
Expand Down Expand Up @@ -85,7 +85,7 @@
$wagmiClient = createClient({
provider,
connectors: [
new InjectedConnector({
new MetaMaskConnector({
chains: wagmiChains,
}),
new CoinbaseWalletConnector({
Expand Down
36 changes: 23 additions & 13 deletions packages/bridge-ui/src/components/buttons/Connect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
fetchSigner,
watchAccount,
watchNetwork,
ConnectorNotFoundError
} from "@wagmi/core";

import { CHAIN_MAINNET, CHAIN_TKO } from "../../domain/chain";
Expand Down Expand Up @@ -47,19 +48,28 @@
}

async function connectWithConnector(connector: Connector) {
const { chain } = await wagmiConnect({ connector });
await setSigner();
await changeChain(chain.id);
unwatchNetwork = watchNetwork(
async (network) => await changeChain(network.chain.id)
);
unwatchAccount = watchAccount(async () => {
const s = await setSigner();
transactions.set(
await $transactioner.GetAllByAddress(await s.getAddress())
);
});
successToast("Connected");
try {

dantaik marked this conversation as resolved.
Show resolved Hide resolved
const { chain } = await wagmiConnect({ connector });
await setSigner();
await changeChain(chain.id);
unwatchNetwork = watchNetwork(
async (network) => await changeChain(network.chain.id)
);
unwatchAccount = watchAccount(async () => {
const s = await setSigner();
transactions.set(
await $transactioner.GetAllByAddress(await s.getAddress())
);
});
successToast("Connected");
} catch(error) {
if(error instanceof ConnectorNotFoundError) {
errorToast(`${connector.name} not installed`);
} else {
errorToast(`Error while connecting to wallet`);
}
}
}

const iconMap = {
Expand Down