Skip to content

Commit

Permalink
fix(bridge): use metamask wagmi connector (#2080)
Browse files Browse the repository at this point in the history
* fix(bridge): use metamask wagmi connector

* Update packages/bridge-ui/src/components/buttons/Connect.svelte

Co-authored-by: dave | d1onys1us <[email protected]>

Co-authored-by: dave | d1onys1us <[email protected]>
Co-authored-by: Daniel Wang <[email protected]>
  • Loading branch information
3 people authored Dec 30, 2022
1 parent 6c080cb commit 0d74845
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
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
35 changes: 22 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,27 @@
}
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 {
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

0 comments on commit 0d74845

Please sign in to comment.