Skip to content

Commit

Permalink
feat: Export a method to check whether a provider exists (#267)
Browse files Browse the repository at this point in the history
* feat: Remove debug code

* fix: Fix type error

* feat: Remove unused packages

* feat: Update demo

* feat: Export a method to check whether a provider exists
  • Loading branch information
wenty22 authored Jan 13, 2025
1 parent dbd2041 commit 9ee1fa9
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-owls-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-real/walletkit': patch
---

Export a method to check whether a provider exists
3 changes: 3 additions & 0 deletions packages/walletkit/src/evm/wallets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ export * from './bitgetWallet';
export * from './safe';
export * from './codexFieldWallet';
export * from './uxuyWallet';

// utils
export * from './utils';
14 changes: 12 additions & 2 deletions packages/walletkit/src/evm/wallets/utils.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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));
}
3 changes: 3 additions & 0 deletions packages/walletkit/src/solana/wallets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ export * from './types';
export * from './trustWallet';
export * from './phantomWallet';
// export * from './walletConnect';

// utils
export * from './utils';
6 changes: 4 additions & 2 deletions packages/walletkit/src/solana/wallets/utils.ts
Original file line number Diff line number Diff line change
@@ -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));
}
6 changes: 4 additions & 2 deletions packages/walletkit/src/tron/wallets/utils.ts
Original file line number Diff line number Diff line change
@@ -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));
}

0 comments on commit 9ee1fa9

Please sign in to comment.