1
1
import { clearIntervalAsync , setIntervalAsync } from 'set-interval-async' ;
2
+ import { chainId , connected , selectedAccount } from 'svelte-web3' ;
2
3
import { get } from 'svelte/store' ;
3
4
4
5
import { updateWithdrawStateStore , withdrawStateStore } from '../stores' ;
5
6
import { pollAccount } from './polls' ;
6
7
8
+
9
+ import { selectedNetwork } from '$lib/evm-toolkit' ;
10
+ import { NotificationType , showNotification } from '$lib/notification' ;
11
+ import { disconnectWallet } from '.' ;
12
+
7
13
export async function subscribeBalance ( ) {
8
14
await unsubscribeBalance ( ) ;
9
15
const $withdrawStateStore = get ( withdrawStateStore ) ;
@@ -28,3 +34,28 @@ export async function unsubscribeBalance() {
28
34
balancePollingHandle : undefined ,
29
35
} ) ;
30
36
}
37
+
38
+ let connectedNetworkInterval : NodeJS . Timeout | null = null ;
39
+ export async function subscribeConnectedNetwork ( ) {
40
+ connectedNetworkInterval = setInterval ( async ( ) => {
41
+ if ( get ( connected ) || get ( selectedAccount ) ) {
42
+ if ( BigInt ( get ( chainId ) ) !== BigInt ( get ( selectedNetwork ) ?. chainID ) ) {
43
+ try {
44
+ await disconnectWallet ( ) ;
45
+ } catch ( e ) {
46
+ showNotification ( {
47
+ type : NotificationType . Error ,
48
+ message : e ,
49
+ } ) ;
50
+ console . error ( e ) ;
51
+ }
52
+ }
53
+ }
54
+ } , 1000 ) ;
55
+ }
56
+
57
+ export async function unsubscribeConnectedNetwork ( ) {
58
+ if ( connectedNetworkInterval ) {
59
+ clearInterval ( connectedNetworkInterval ) ;
60
+ }
61
+ }
0 commit comments