Skip to content

Commit

Permalink
fix: use InjectedConnector in binance dapp browser (#2297)
Browse files Browse the repository at this point in the history
* feat: update binance wallet

* chore: changeset

---------

Co-authored-by: zane-x <[email protected]>
Co-authored-by: Daniel Sinclair <[email protected]>
  • Loading branch information
3 people authored Jan 23, 2025
1 parent 0cb1977 commit f89eb92
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 45 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-tigers-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rainbow-me/rainbowkit": patch
---

Improved support for the Binance Wallet dApp browser
1 change: 1 addition & 0 deletions packages/rainbowkit/src/types/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type WalletProviderFlags =
| 'isBifrost'
| 'isBitKeep'
| 'isBitski'
| 'isBinance'
| 'isBlockWallet'
| 'isBraveWallet'
| 'isCoinbaseWallet'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,81 @@
import { isAndroid } from '../../../utils/isMobile';
import type { DefaultWalletOptions, Wallet } from '../../Wallet';
import {
getInjectedConnector,
hasInjectedProvider,
} from '../../getInjectedConnector';
import { getWalletConnectConnector } from '../../getWalletConnectConnector';

export type BinanceWalletOptions = DefaultWalletOptions;

export const binanceWallet = ({
projectId,
walletConnectParameters,
}: BinanceWalletOptions): Wallet => ({
id: 'binance',
name: 'Binance Wallet',
iconUrl: async () => (await import('./binanceWallet.svg')).default,
iconBackground: '#000000',
downloadUrls: {
android: 'https://play.google.com/store/apps/details?id=com.binance.dev',
ios: 'https://apps.apple.com/us/app/id1436799971',
mobile: 'https://www.binance.com/en/download',
qrCode: 'https://www.binance.com/en/web3wallet',
},
mobile: {
getUri: (uri: string) => {
return isAndroid()
? uri
: `bnc://app.binance.com/cedefi/wc?uri=${encodeURIComponent(uri)}`;
},
},
qrCode: {
getUri: (uri: string) => uri,
instructions: {
learnMoreUrl: 'https://www.binance.com/en/web3wallet',
steps: [
{
description: 'wallet_connectors.binance.qr_code.step1.description',
step: 'install',
title: 'wallet_connectors.binance.qr_code.step1.title',
},
{
description: 'wallet_connectors.binance.qr_code.step2.description',
step: 'create',
title: 'wallet_connectors.binance.qr_code.step2.title',
},
{
description: 'wallet_connectors.binance.qr_code.step3.description',
step: 'scan',
title: 'wallet_connectors.binance.qr_code.step3.title',
},
],
}: BinanceWalletOptions): Wallet => {
const isBinanceInjected = hasInjectedProvider({
flag: 'isBinance',
});
const shouldUseWalletConnect = !isBinanceInjected;

return {
id: 'binance',
name: 'Binance Wallet',
rdns: 'com.binance.wallet',
iconUrl: async () => (await import('./binanceWallet.svg')).default,
iconBackground: '#000000',
installed: !shouldUseWalletConnect ? isBinanceInjected : undefined,
downloadUrls: {
android: 'https://play.google.com/store/apps/details?id=com.binance.dev',
ios: 'https://apps.apple.com/us/app/id1436799971',
mobile: 'https://www.binance.com/en/download',
qrCode: 'https://www.binance.com/en/web3wallet',
},
},
createConnector: getWalletConnectConnector({
projectId,
walletConnectParameters,
}),
});
mobile: shouldUseWalletConnect
? {
getUri: (uri: string) => {
return isAndroid()
? uri
: `bnc://app.binance.com/cedefi/wc?uri=${encodeURIComponent(
uri,
)}`;
},
}
: undefined,
qrCode: shouldUseWalletConnect
? {
getUri: (uri: string) => uri,
instructions: {
learnMoreUrl: 'https://www.binance.com/en/web3wallet',
steps: [
{
description:
'wallet_connectors.binance.qr_code.step1.description',
step: 'install',
title: 'wallet_connectors.binance.qr_code.step1.title',
},
{
description:
'wallet_connectors.binance.qr_code.step2.description',
step: 'create',
title: 'wallet_connectors.binance.qr_code.step2.title',
},
{
description:
'wallet_connectors.binance.qr_code.step3.description',
step: 'scan',
title: 'wallet_connectors.binance.qr_code.step3.title',
},
],
},
}
: undefined,
createConnector: shouldUseWalletConnect
? getWalletConnectConnector({
projectId,
walletConnectParameters,
})
: getInjectedConnector({
flag: 'isBinance',
}),
};
};

0 comments on commit f89eb92

Please sign in to comment.