-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Lazy instantiation of adapters
- Loading branch information
Showing
8 changed files
with
159 additions
and
150 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 |
---|---|---|
@@ -1,21 +1,31 @@ | ||
import type { Wallet } from '@ant-design/web3-common'; | ||
import { WalletReadyState } from '@solana/wallet-adapter-base'; | ||
|
||
import type { | ||
AdapterWalletFactory as AdapterWalletFactoryType, | ||
WalletConnectWalletFactory as WalletConnectWalletFactoryType, | ||
AdapterWallet, | ||
MetaMaskSnapWalletFactory as MetaMaskSnapWalletFactoryType, | ||
StandardWallet, | ||
WalletConnectWallet, | ||
WalletFactory as WalletFactoryType, | ||
} from './wallets/types'; | ||
|
||
export const hasWalletReady = (readyState?: WalletReadyState) => | ||
readyState === WalletReadyState.Installed || readyState === WalletReadyState.Loadable; | ||
|
||
export const isWalletConnectFactory = ( | ||
export const isMetaMaskSnapWalletFactory = ( | ||
factory: WalletFactoryType, | ||
): factory is WalletConnectWalletFactoryType => | ||
!!(factory as WalletConnectWalletFactoryType).isWalletConnect; | ||
): factory is MetaMaskSnapWalletFactoryType => { | ||
return (factory as MetaMaskSnapWalletFactoryType).isMetaMaskSnap === true; | ||
}; | ||
|
||
export const isAdapterWalletFactory = ( | ||
factory: WalletFactoryType, | ||
): factory is AdapterWalletFactoryType => { | ||
return (factory as AdapterWalletFactoryType).adapter !== undefined; | ||
export const isStandardWallet = (wallet: Wallet): wallet is StandardWallet => { | ||
return (wallet as StandardWallet).isStandardWallet === true; | ||
}; | ||
|
||
export const isAdapterWallet = (wallet: Wallet): wallet is AdapterWallet => { | ||
return (wallet as AdapterWallet).adapter !== undefined; | ||
}; | ||
|
||
export const isWalletConnectWallet = (wallet: Wallet): wallet is WalletConnectWallet => { | ||
return (wallet as WalletConnectWallet).isWalletConnect !== undefined; | ||
}; |
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
Oops, something went wrong.