Skip to content

Commit 7c1d1cd

Browse files
1.33.0-0.1.1: [feature] Adds display options for wallets (#654)
* 1.33.0-0.1.1: [feature] Adds display options for wallets * Make mobile/desktop optional properties
1 parent 82843bd commit 7c1d1cd

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bnc-onboard",
3-
"version": "1.33.0-0.0.1",
3+
"version": "1.33.0-0.1.1",
44
"description": "Onboard users to web3 by allowing them to select a wallet, get that wallet ready to transact and have access to synced wallet state.",
55
"keywords": [
66
"ethereum",

src/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ export interface CommonWalletOptions {
183183
iconSrc?: string
184184
svg?: string
185185
networkId?: number
186+
display?: { mobile?: boolean; desktop?: boolean }
186187
}
187188

188189
export interface SdkWalletOptions extends CommonWalletOptions {

src/modules/select/index.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,26 @@ function select(
4646
networkId: number,
4747
isMobile: boolean
4848
) {
49-
const defaultWalletNames = isMobile
50-
? mobileDefaultWalletNames
51-
: desktopDefaultWalletNames
52-
5349
if (wallets) {
50+
const hideWallet = (wallet: WalletInitOptions) =>
51+
wallet?.display &&
52+
wallet?.display[isMobile ? 'mobile' : 'desktop'] === false
53+
5454
// For backwards compatibility if a user is still using 'detectedwallet' in the onboard wallet select array
5555
// it will be filtered out so there are no duplicates
5656
wallets = wallets.filter(
5757
wallet =>
58-
'walletName' in wallet ? wallet.walletName !== 'detectedwallet' : true // It is not a WalletInitOption but rather a WalletModule so let it through
58+
'walletName' in wallet
59+
? wallet.walletName !== 'detectedwallet' && !hideWallet(wallet)
60+
: true // It is not a WalletInitOption but rather a WalletModule so let it through
5961
)
6062

6163
// If we detect an injected wallet then place the detected wallet
62-
// at the beginning of the list e.g. the of the wallet select modal
64+
// at the beginning of the list e.g. the top of the wallet select modal
6365
if (injectedWalletDetected()) {
6466
wallets.unshift({ walletName: 'detectedwallet' })
6567
}
68+
6669
return Promise.all(
6770
wallets.map(wallet => {
6871
// If this is a wallet init object then load the built-in wallet module
@@ -87,6 +90,10 @@ function select(
8790
)
8891
}
8992

93+
const defaultWalletNames = isMobile
94+
? mobileDefaultWalletNames
95+
: desktopDefaultWalletNames
96+
9097
return Promise.all(
9198
defaultWalletNames
9299
// Include the detected wallet only if an injected wallet is detected

src/validation.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,15 @@ export function validateWalletInit(
661661
): void | never {
662662
validateType({ name: 'walletInit', value: walletInit, type: 'object' })
663663

664-
const { walletName, preferred, label, iconSrc, svg, ...otherParams } =
665-
walletInit
664+
const {
665+
walletName,
666+
preferred,
667+
label,
668+
iconSrc,
669+
svg,
670+
display,
671+
...otherParams
672+
} = walletInit
666673

667674
invalidParams(
668675
otherParams,
@@ -698,10 +705,17 @@ export function validateWalletInit(
698705
'webUri',
699706
'xsUri',
700707
'blockedPopupRedirect',
701-
'customNetwork'
708+
'customNetwork',
709+
'display'
702710
],
703711
'walletInitObject'
704712
)
713+
validateType({
714+
name: 'walletInit.display',
715+
value: display,
716+
type: 'object',
717+
optional: true
718+
})
705719

706720
validateType({
707721
name: 'walletInit.walletName',

0 commit comments

Comments
 (0)