Skip to content

Commit 76c47c9

Browse files
Merge pull request #705 from blocknative/release/1.35.0
Release: 1.35.0 - Master
2 parents ffb8744 + f1859f1 commit 76c47c9

File tree

9 files changed

+280
-157
lines changed

9 files changed

+280
-157
lines changed

.circleci/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2
22
jobs:
33
test:
44
docker:
5-
- image: circleci/node:10.18.1-browsers
5+
- image: circleci/node:12-browsers
66
steps:
77
- checkout
88
- restore_cache:
@@ -19,7 +19,7 @@ jobs:
1919
key: v1-dependencies-{{ checksum "package.json" }}
2020
deploy_stage:
2121
docker:
22-
- image: circleci/node:10.18.1-browsers
22+
- image: circleci/node:12-browsers
2323
user: root
2424
steps:
2525
- checkout
@@ -31,7 +31,7 @@ jobs:
3131
- run: npm publish --dry-run
3232
deploy_prod:
3333
docker:
34-
- image: circleci/node:10.18.1-browsers
34+
- image: circleci/node:12-browsers
3535
user: root
3636
steps:
3737
- checkout
@@ -43,7 +43,7 @@ jobs:
4343
- run: npm publish
4444
deploy_demo:
4545
docker:
46-
- image: circleci/node:10.18.1-browsers
46+
- image: circleci/node:12-browsers
4747
user: root
4848
steps:
4949
- checkout

.github/ISSUE_TEMPLATE/FEATURE.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Feature Request
2+
description: Request a feature
3+
title: "[Feature]: "
4+
labels: [feature]
5+
assignees:
6+
- taylorjdawson
7+
- aaronbarnardsound
8+
body:
9+
- type: markdown
10+
attributes:
11+
value: |
12+
Thanks for taking the time to fill out this feature request!
13+
- type: textarea
14+
attributes:
15+
label: Is your request related to a problem?
16+
description: A clear and concise description of what the problem is.
17+
validations:
18+
required: false
19+
- type: textarea
20+
attributes:
21+
label: Feature Description
22+
description: A clear and concise description of what you want to happen.
23+
validations:
24+
required: false
25+
- type: textarea
26+
attributes:
27+
label: Alternative Solutions
28+
description: Let us know about other solutions you've tried or researched.
29+
validations:
30+
required: false
31+
- type: textarea
32+
attributes:
33+
label: Anything else?
34+
description: |
35+
Links? References? Images? Anything that will give us more context about the feature you are requesting!
36+
37+
Tip: You can attach images or log files by clicking this area to highlight it and then dragging files in.
38+
validations:
39+
required: false

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bnc-onboard",
3-
"version": "1.34.2",
3+
"version": "1.35.0",
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",
@@ -83,7 +83,7 @@
8383
"hdkey": "^2.0.1",
8484
"regenerator-runtime": "^0.13.7",
8585
"trezor-connect": "^8.1.9",
86-
"walletlink": "^2.1.9",
86+
"walletlink": "^2.1.11",
8787
"web3-provider-engine": "^15.0.4"
8888
},
8989
"resolutions": {

src/interfaces.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,18 +507,15 @@ export interface WalletInterfaceStore {
507507

508508
export interface WalletStateSliceStore {
509509
subscribe: (subscriber: (store: any) => void) => () => void
510-
reset: () => void
511510
setStateSyncer: (
512511
stateSyncer: StateSyncer
513512
) => { clear: () => void } | undefined
513+
reset: () => void
514514
get: () => any
515515
}
516516

517-
export interface BalanceStore {
518-
subscribe: (subscriber: (store: any) => void) => () => void
517+
export interface BalanceStore extends WalletStateSliceStore {
519518
setStateSyncer: (stateSyncer: StateSyncer) => undefined
520-
reset: () => void
521-
get: () => any
522519
}
523520

524521
export type Browser = {

src/modules/select/index.ts

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { getProviderName } from '../../utilities'
99
// wallets that qualify for default wallets need to have no
1010
// init parameters that are required for full functionality
1111
const desktopDefaultWalletNames = [
12-
'detectedwallet',
1312
'metamask',
1413
'binance',
1514
'frame',
@@ -19,7 +18,6 @@ const desktopDefaultWalletNames = [
1918
]
2019

2120
const mobileDefaultWalletNames = [
22-
'detectedwallet',
2321
'metamask',
2422
'coinbase',
2523
'trust',
@@ -39,48 +37,65 @@ const mobileDefaultWalletNames = [
3937
'tp'
4038
]
4139

42-
const injectedWalletDetected = () =>
43-
window.ethereum && getProviderName(window.ethereum) === undefined
40+
const providerNameToWalletName = (providerName: string) =>
41+
providerName === 'imToken'
42+
? providerName
43+
: providerName === 'WalletConnect'
44+
? 'walletConnect'
45+
: providerName.toLocaleLowerCase()
4446

4547
function select(
4648
wallets: Array<WalletInitOptions | WalletModule> | undefined,
4749
networkId: number,
4850
isMobile: boolean
4951
) {
52+
// If we detect an injected wallet then place the detected wallet
53+
// at the beginning of the list e.g. the top of the wallet select modal
54+
let detectedProviderName: string | undefined
55+
let detectedWalletName: string | undefined
56+
if (window?.ethereum) {
57+
detectedProviderName = getProviderName(window.ethereum)
58+
if (detectedProviderName) {
59+
detectedWalletName = providerNameToWalletName(detectedProviderName)
60+
}
61+
}
62+
5063
if (wallets) {
5164
const hideWallet = (wallet: WalletInitOptions) =>
5265
wallet?.display &&
5366
wallet?.display[isMobile ? 'mobile' : 'desktop'] === false
5467

55-
// For backwards compatibility if a user is still using 'detectedwallet' in the onboard wallet select array
56-
// it will be filtered out so there are no duplicates
57-
wallets = wallets.filter(
58-
wallet =>
59-
'walletName' in wallet
60-
? wallet.walletName !== 'detectedwallet' && !hideWallet(wallet)
61-
: true // It is not a WalletInitOption but rather a WalletModule so let it through
62-
)
63-
64-
// If we detect an injected wallet then place the detected wallet
65-
// at the beginning of the list e.g. the top of the wallet select modal
66-
if (injectedWalletDetected()) {
68+
if (detectedWalletName) {
69+
// This wallet is built into onboard so add the walletName and
70+
// the code below will load it as a wallet module
71+
wallets.unshift({ walletName: detectedWalletName })
72+
} else if (detectedProviderName) {
73+
// A provider has been detected but there is not a walletName therefore
74+
// this wallet is not built into onboard so add it as a generic injected wallet
6775
wallets.unshift({ walletName: 'detectedwallet' })
6876
}
6977

78+
const setOfWallets = new Set<string>()
7079
return Promise.all(
7180
wallets.map(wallet => {
7281
// If this is a wallet init object then load the built-in wallet module
73-
if (isWalletInit(wallet)) {
82+
if (isWalletInit(wallet) && !hideWallet(wallet)) {
7483
const { walletName, ...initParams } = wallet
75-
try {
76-
return getModule(walletName).then((m: any) =>
77-
m.default({ ...initParams, networkId, isMobile })
78-
)
79-
} catch (error) {
80-
if (error.name === 'DeprecatedWalletError') {
81-
console.warn(error.message)
82-
} else {
83-
throw error
84+
// Check to see if we have seen this wallet before
85+
// prevents duplicated injected wallet from being added
86+
if (!setOfWallets.has(walletName)) {
87+
try {
88+
const module = getModule(walletName).then((m: any) =>
89+
m.default({ ...initParams, networkId, isMobile })
90+
)
91+
setOfWallets.add(walletName)
92+
return module
93+
} catch (error) {
94+
if (error.name === 'DeprecatedWalletError') {
95+
console.warn(error.message)
96+
} else {
97+
throw error
98+
}
8499
}
85100
}
86101
}
@@ -94,17 +109,17 @@ function select(
94109
const defaultWalletNames = isMobile
95110
? mobileDefaultWalletNames
96111
: desktopDefaultWalletNames
97-
112+
// If we have detected a builtin wallet that is not already in the list of default wallets so add it
113+
if (detectedWalletName && !defaultWalletNames.includes(detectedWalletName)) {
114+
defaultWalletNames.unshift(detectedWalletName)
115+
// If we detected a provider but it is not builtin add the generic injected provider
116+
} else if (!detectedWalletName && detectedProviderName) {
117+
defaultWalletNames.unshift('detectedwallet')
118+
}
98119
return Promise.all(
99-
defaultWalletNames
100-
// Include the detected wallet only if an injected wallet is detected
101-
.filter(
102-
walletName =>
103-
walletName !== 'detectedwallet' || injectedWalletDetected()
104-
)
105-
.map(walletName =>
106-
getModule(walletName).then((m: any) => m.default({ networkId }))
107-
)
120+
defaultWalletNames.map(walletName =>
121+
getModule(walletName).then((m: any) => m.default({ networkId }))
122+
)
108123
)
109124
}
110125

src/modules/select/wallets/binance-chain-wallet.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,43 @@ function binanceChainWallet(
1818
// Ref: https://binance-wallet.gitbook.io/binance-chain-extension-wallet
1919
const provider = (window as any).BinanceChain
2020

21+
// The following code is necessary as when polling BSC wallet for a balance causes it to
22+
// relaunch the login prompt indefinitely
23+
24+
let providerInterface = null
25+
let address: string | number | null | undefined
26+
27+
if (provider) {
28+
providerInterface = createModernProviderInterface(provider)
29+
30+
if (providerInterface.balance.get) {
31+
if (providerInterface.address.get) {
32+
// Save and override the address `get` method
33+
// Enables us to save the address used below to determine when to get the balance
34+
// We only want to get the balance after we get the address
35+
const addressGet = providerInterface.address.get
36+
providerInterface.address.get = async () => {
37+
address = await addressGet()
38+
return address
39+
}
40+
} else if (providerInterface.address.onChange) {
41+
// Intercept the onChange event to save the address internally
42+
providerInterface.address.onChange(updatedAddress => {
43+
address = updatedAddress
44+
})
45+
}
46+
// Save and override the balance `get` method -- only call the original method
47+
// if we have an address from BSC
48+
const balanceGet = providerInterface.balance.get
49+
providerInterface.balance.get = () => {
50+
return address ? balanceGet() : Promise.resolve(null)
51+
}
52+
}
53+
}
54+
2155
return {
2256
provider,
23-
interface: provider && createModernProviderInterface(provider)
57+
interface: providerInterface
2458
}
2559
},
2660
type: 'injected',

src/modules/select/wallets/detectedwallet.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ function injected(options: CommonWalletOptions): WalletModule {
1212
const name =
1313
label ||
1414
Object.keys(provider)
15-
.find(key => key.startsWith('is') && !key.includes('MetaMask'))
15+
.find(
16+
key =>
17+
key.startsWith('is') &&
18+
!key.includes('MetaMask') &&
19+
!key.includes('Connected')
20+
)
1621
?.split('is')[1] ||
1722
'Detected Wallet'
1823

0 commit comments

Comments
 (0)