11import { BinanceW3WParameters , getWagmiConnectorV2 } from '@binance/w3w-wagmi-connector-v2' ;
22import { isMobile , isTMA } from '@/core/base/utils/mobile' ;
33import { binanceWalletConfig } from '@/core/configs/binanceWallet' ;
4+ import { isBinanceInstalled , getBinanceAppLink } from '@/core/utils/binance' ;
45import { EvmWallet } from '../types' ;
56import { getEvmInjectedProvider } from '../../utils/getEvmInjectedProvider' ;
67import { sleep } from '@/core/utils/common' ;
@@ -10,42 +11,22 @@ export interface BinanceWalletOptions extends Partial<EvmWallet> {
1011 connectorOptions ?: BinanceW3WParameters ;
1112}
1213
13- /**
14- * Detect if running inside the Binance App in-app browser.
15- * The Binance App sets window.isBinance = true.
16- */
17- function isInBinanceApp ( ) : boolean {
18- if ( typeof window === 'undefined' ) return false ;
19- return Boolean ( window . isBinance ) ;
20- }
21-
22- /**
23- * Detect if the Binance Web3 Wallet browser extension is installed.
24- * The extension injects window.binancew3w.
25- */
26- function isBinanceExtensionInstalled ( ) : boolean {
27- if ( typeof window === 'undefined' ) return false ;
28- return Boolean ( window . binancew3w ) ;
29- }
30-
3114/**
3215 * Get the Binance EVM provider.
3316 * Priority: window.ethereum.isBinance > window.binancew3w.ethereum
3417 */
3518function getBinanceProvider ( ) : any {
3619 if ( typeof window === 'undefined' ) return undefined ;
37- // Standard EIP-1193: injected by Binance App or extension via window.ethereum
3820 const injectedProvider = getEvmInjectedProvider ( 'isBinance' ) ;
3921 if ( injectedProvider ) return injectedProvider ;
40- // Fallback: standalone provider from extension
4122 return window . binancew3w ?. ethereum ;
4223}
4324
4425/**
45- * Returns true if any Binance wallet source is available.
26+ * Returns true if any Binance EVM wallet source is available.
4627 */
47- function isBinanceInstalled ( ) : boolean {
48- return isInBinanceApp ( ) || isBinanceExtensionInstalled ( ) || Boolean ( getBinanceProvider ( ) ) ;
28+ function isBinanceEvmInstalled ( ) : boolean {
29+ return isBinanceInstalled ( ) || Boolean ( getBinanceProvider ( ) ) ;
4930}
5031
5132export function binanceWallet ( props : BinanceWalletOptions = { } ) : EvmWallet {
@@ -84,9 +65,9 @@ export function binanceWallet(props: BinanceWalletOptions = {}): EvmWallet {
8465 {
8566 platforms : [ 'browser-pc' ] ,
8667 connectType : 'default' as const ,
87- isInstalled : isBinanceInstalled ,
68+ isInstalled : isBinanceEvmInstalled ,
8869 getCreateConnectorFn ( ) {
89- if ( isBinanceInstalled ( ) ) {
70+ if ( isBinanceEvmInstalled ( ) ) {
9071 return injected ( {
9172 shimDisconnect : true ,
9273 target : {
@@ -109,16 +90,9 @@ export function binanceWallet(props: BinanceWalletOptions = {}): EvmWallet {
10990 {
11091 platforms : [ 'browser-android' , 'browser-ios' ] ,
11192 connectType : 'default' as const ,
112- isInstalled : isBinanceInstalled ,
93+ isInstalled : isBinanceEvmInstalled ,
11394 getAppLink ( ) {
114- const url = window . location . href ;
115- const base = 'bnc://app.binance.com/mp/app' ;
116- const appId = 'yFK5FCqYprrXDiVFbhyRx7' ;
117- const startPagePath = window . btoa ( '/pages/browser/index' ) ;
118- const startPageQuery = window . btoa ( `url=${ url } ` ) ;
119- const deeplink = `${ base } ?appId=${ appId } &startPagePath=${ startPagePath } &startPageQuery=${ startPageQuery } ` ;
120- const dp = window . btoa ( deeplink ) ;
121- return `https://app.binance.com/en/download?_dp=${ dp } ` ;
95+ return getBinanceAppLink ( ) ;
12296 } ,
12397 getCreateConnectorFn ( ) {
12498 let isReady = false ;
0 commit comments