-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a016dd
commit 5fc13a2
Showing
4 changed files
with
48 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { MetaState } from '../store/meta'; | ||
import type { WalletTypes } from '@rango-dev/wallets-shared'; | ||
|
||
import { useWallets } from '@rango-dev/wallets-react'; | ||
import { useEffect, useRef } from 'react'; | ||
|
||
type forceAutoConnectParams = { | ||
loadingStatus: MetaState['loadingStatus']; | ||
walletType: WalletTypes; | ||
}; | ||
|
||
export function useForceAutoConnect(params: forceAutoConnectParams): void { | ||
const { loadingStatus, walletType } = params; | ||
const { connect, state } = useWallets(); | ||
const initiated = useRef(false); | ||
|
||
const walletState = state(walletType); | ||
|
||
useEffect(() => { | ||
const shouldTryConnect = | ||
loadingStatus === 'success' && | ||
walletType && | ||
walletState && | ||
walletState.installed && | ||
!walletState.connecting && | ||
!walletState.connected; | ||
|
||
if (shouldTryConnect && !initiated.current) { | ||
initiated.current = true; | ||
connect(walletType) | ||
.then() | ||
.catch((error: any) => { | ||
console.error(error); | ||
}); | ||
} | ||
}, [walletState, loadingStatus]); | ||
} |
This file was deleted.
Oops, something went wrong.
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