diff --git a/.changeset/fifty-owls-kiss.md b/.changeset/fifty-owls-kiss.md new file mode 100644 index 0000000..e947516 --- /dev/null +++ b/.changeset/fifty-owls-kiss.md @@ -0,0 +1,5 @@ +--- +'@node-real/walletkit': patch +--- + +Export a method to check whether a provider exists diff --git a/packages/walletkit/src/evm/wallets/index.ts b/packages/walletkit/src/evm/wallets/index.ts index 11762d5..7307ce9 100644 --- a/packages/walletkit/src/evm/wallets/index.ts +++ b/packages/walletkit/src/evm/wallets/index.ts @@ -14,3 +14,6 @@ export * from './bitgetWallet'; export * from './safe'; export * from './codexFieldWallet'; export * from './uxuyWallet'; + +// utils +export * from './utils'; diff --git a/packages/walletkit/src/evm/wallets/utils.ts b/packages/walletkit/src/evm/wallets/utils.ts index 14e15f6..5771903 100644 --- a/packages/walletkit/src/evm/wallets/utils.ts +++ b/packages/walletkit/src/evm/wallets/utils.ts @@ -1,4 +1,14 @@ -export function getEvmInjectedProvider(flag: string): any { +export type EvmFlagType = + | 'isBinance' + | 'isBitEthereum' + | 'isCoinbaseWallet' + | 'isMathWallet' + | 'isMetaMask' + | 'isOkxWallet' + | 'isTokenPocket' + | 'isTrust'; + +export function getEvmInjectedProvider(flag: EvmFlagType): any { if (typeof window === 'undefined' || typeof window.ethereum === 'undefined') return; const providers = window.ethereum.providers; @@ -9,6 +19,6 @@ export function getEvmInjectedProvider(flag: string): any { : undefined; } -export function hasEvmInjectedProvider(flag: string): boolean { +export function hasEvmInjectedProvider(flag: EvmFlagType): boolean { return Boolean(getEvmInjectedProvider(flag)); } diff --git a/packages/walletkit/src/solana/wallets/index.ts b/packages/walletkit/src/solana/wallets/index.ts index 7fc1b14..25029cf 100644 --- a/packages/walletkit/src/solana/wallets/index.ts +++ b/packages/walletkit/src/solana/wallets/index.ts @@ -5,3 +5,6 @@ export * from './types'; export * from './trustWallet'; export * from './phantomWallet'; // export * from './walletConnect'; + +// utils +export * from './utils'; diff --git a/packages/walletkit/src/solana/wallets/utils.ts b/packages/walletkit/src/solana/wallets/utils.ts index 1213e91..15bbf52 100644 --- a/packages/walletkit/src/solana/wallets/utils.ts +++ b/packages/walletkit/src/solana/wallets/utils.ts @@ -1,9 +1,11 @@ -export function getSolanaInjectedProvider(flag: string): any { +export type SolanaFlagType = 'isPhantom' | 'isTrust'; + +export function getSolanaInjectedProvider(flag: SolanaFlagType): any { if (typeof window === 'undefined' || typeof window.solana === 'undefined') return; return window.solana[flag] ? window.solana : undefined; } -export function hasSolanaInjectedProvider(flag: string): boolean { +export function hasSolanaInjectedProvider(flag: SolanaFlagType): boolean { return Boolean(getSolanaInjectedProvider(flag)); } diff --git a/packages/walletkit/src/tron/wallets/utils.ts b/packages/walletkit/src/tron/wallets/utils.ts index 0432171..d7d830b 100644 --- a/packages/walletkit/src/tron/wallets/utils.ts +++ b/packages/walletkit/src/tron/wallets/utils.ts @@ -1,9 +1,11 @@ -export function getTronInjectedProvider(flag: string): any { +export type TronFlagType = 'isTronLink'; + +export function getTronInjectedProvider(flag: TronFlagType): any { if (typeof window === 'undefined' || typeof window.tron === 'undefined') return; return window.tron[flag] ? window.tron : undefined; } -export function hasTronInjectedProvider(flag: string): boolean { +export function hasTronInjectedProvider(flag: TronFlagType): boolean { return Boolean(getTronInjectedProvider(flag)); }