-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle wallet referrer in widget
- Loading branch information
1 parent
5db6a46
commit ca9cb65
Showing
4 changed files
with
52 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { MetaState } from '../store/meta'; | ||
import type { WalletType } from '@rango-dev/wallets-shared'; | ||
|
||
import { useWallets } from '@rango-dev/wallets-react'; | ||
import { useEffect, useRef } from 'react'; | ||
|
||
type forceAutoConnectParams = { | ||
loadingStatus: MetaState['loadingStatus']; | ||
walletType?: WalletType; | ||
}; | ||
|
||
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]); | ||
} |