-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bridge-ui): return true if the token address is found on dest cha…
…in to send correct gas limit (#14446)
- Loading branch information
1 parent
0e6fe65
commit f7cc97e
Showing
6 changed files
with
35 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,5 @@ | ||
import { get } from 'svelte/store'; | ||
import { switchNetwork as wagmiSwitchNetwork } from 'wagmi/actions'; | ||
|
||
import { srcChain } from '../store/chain'; | ||
import { Deferred } from './Deferred'; | ||
|
||
export async function switchNetwork(chainId: number) { | ||
const prevChainId = get(srcChain)?.id; | ||
|
||
if (prevChainId === chainId) return; | ||
|
||
await wagmiSwitchNetwork({ chainId }); | ||
|
||
// What are we doing here? we have a watcher waiting for network changes. | ||
// When this happens this watcher is called and takes care of setting | ||
// the signer and chains in the store. We are actually waiting here | ||
// for these stores to change due to some race conditions in the UI. | ||
// There will be a better design around this in alpha-4: fewer stores | ||
// and '$:' tags. They're evil. | ||
const deferred = new Deferred<void>(); | ||
|
||
// This will prevent an unlikely infinite loop | ||
const starting = Date.now(); | ||
const timeout = 5000; // TODO: config? | ||
|
||
const waitForNetworkChange = () => { | ||
const srcChainId = get(srcChain)?.id; | ||
|
||
if (srcChainId && srcChainId !== prevChainId) { | ||
// We have finally set the chain in the store. We're done here. | ||
deferred.resolve(); | ||
} else if (Date.now() > starting + timeout) { | ||
// Wait, what??? | ||
deferred.reject(new Error('timeout switching network')); | ||
} else { | ||
setTimeout(waitForNetworkChange, 300); // TODO: config those 300? | ||
} | ||
}; | ||
|
||
waitForNetworkChange(); | ||
|
||
return deferred.promise; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters