Skip to content

Commit 75265e1

Browse files
authored
Merge pull request #323 from blocknative/develop
Release 1.7.7
2 parents a6e5273 + 8593980 commit 75265e1

File tree

8 files changed

+200
-136
lines changed

8 files changed

+200
-136
lines changed

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.7.6",
3+
"version": "1.7.7",
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",
@@ -44,7 +44,7 @@
4444
"@portis/web3": "^2.0.0-beta.42",
4545
"@toruslabs/torus-embed": "^1.3.0",
4646
"@unilogin/provider": "^0.5.21",
47-
"@walletconnect/web3-provider": "^1.0.0-beta.75",
47+
"@walletconnect/web3-provider": "^1.0.0-beta.47",
4848
"authereum": "^0.0.4-beta.131",
4949
"bignumber.js": "^9.0.0",
5050
"bnc-sdk": "2.0.0",

src/modules/select/wallets/hd-wallet.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import HDKey from 'hdkey'
2-
import { publicToAddress, toChecksumAddress } from 'ethereumjs-util'
3-
import buffer from 'buffer'
2+
import * as ethUtil from 'ethereumjs-util'
3+
import * as buffer from 'buffer'
4+
5+
const { publicToAddress, toChecksumAddress } = ethUtil
46

57
const numberToGet = 5
68

src/modules/select/wallets/ledger.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,8 @@ import {
44
Helpers,
55
CommonWalletOptions
66
} from '../../../interfaces'
7-
import ledgerIcon from '../wallet-icons/icon-ledger'
8-
9-
import createProvider from './providerEngine'
10-
import { generateAddresses, isValidPath } from './hd-wallet'
11-
12-
import TransportU2F from '@ledgerhq/hw-transport-u2f'
13-
import Eth from '@ledgerhq/hw-app-eth'
14-
import * as EthereumTx from 'ethereumjs-tx'
15-
import * as ethUtil from 'ethereumjs-util'
167

17-
import buffer from 'buffer'
8+
import ledgerIcon from '../wallet-icons/icon-ledger'
189

1910
const LEDGER_LIVE_PATH = `m/44'/60'`
2011
const ACCOUNTS_TO_GET = 5
@@ -81,6 +72,15 @@ async function ledgerProvider(options: {
8172
BigNumber: any
8273
networkName: (id: number) => string
8374
}) {
75+
const { default: createProvider } = await import('./providerEngine')
76+
const { generateAddresses, isValidPath } = await import('./hd-wallet')
77+
const { default: TransportU2F } = await import('@ledgerhq/hw-transport-u2f')
78+
const { default: Eth } = await import('@ledgerhq/hw-app-eth')
79+
80+
const EthereumTx = await import('ethereumjs-tx')
81+
const ethUtil = await import('ethereumjs-util')
82+
const buffer = await import('buffer')
83+
8484
const { networkId, rpcUrl, LedgerTransport, BigNumber, networkName } = options
8585

8686
let dPath = ''

src/modules/select/wallets/trezor.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ import trezorIcon from '../wallet-icons/icon-trezor'
99
import createProvider from './providerEngine'
1010
import { generateAddresses, isValidPath } from './hd-wallet'
1111

12-
import * as TrezorConnectLibrary from 'trezor-connect'
13-
import * as EthereumTx from 'ethereumjs-tx'
14-
import * as ethUtil from 'ethereumjs-util'
15-
16-
const { default: TrezorConnect, DEVICE_EVENT, DEVICE } = TrezorConnectLibrary
17-
1812
const TREZOR_DEFAULT_PATH = "m/44'/60'/0'/0"
1913

2014
function trezor(options: TrezorOptions & CommonWalletOptions): WalletModule {
@@ -82,6 +76,12 @@ async function trezorProvider(options: {
8276
BigNumber: any
8377
networkName: (id: number) => string
8478
}) {
79+
const TrezorConnectLibrary = await import('trezor-connect')
80+
const EthereumTx = await import('ethereumjs-tx')
81+
const ethUtil = await import('ethereumjs-util')
82+
83+
const { default: TrezorConnect, DEVICE_EVENT, DEVICE } = TrezorConnectLibrary
84+
8585
const { networkId, email, appUrl, rpcUrl, BigNumber, networkName } = options
8686
let dPath: string = ''
8787

src/modules/select/wallets/wallet-connect.ts

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,44 @@ import walletConnectIcon from '../wallet-icons/icon-wallet-connect'
1010
function walletConnect(
1111
options: WalletConnectOptions & CommonWalletOptions
1212
): WalletModule {
13-
const { infuraKey, rpc, bridge, preferred, label, iconSrc, svg } = options
13+
const {
14+
infuraKey,
15+
rpc,
16+
bridge,
17+
preferred,
18+
label,
19+
iconSrc,
20+
svg,
21+
networkId
22+
} = options
23+
24+
if (!infuraKey) {
25+
if (!rpc || !rpc[networkId]) {
26+
throw new Error(
27+
`A "infuraKey" or a "rpc" object with a parameter of ${networkId} must be included in the WalletConnect initialization object`
28+
)
29+
}
30+
}
1431

1532
return {
1633
name: label || 'WalletConnect',
1734
svg: svg || walletConnectIcon,
1835
iconSrc,
1936
wallet: async (helpers: Helpers) => {
20-
const { resetWalletState } = helpers
21-
37+
const createProvider = (await import('./providerEngine')).default
2238
const { default: WalletConnectProvider } = await import(
2339
'@walletconnect/web3-provider'
2440
)
2541

42+
const { resetWalletState, networkName, getBalance } = helpers
43+
44+
const rpcUrl =
45+
rpc && rpc[networkId]
46+
? rpc[networkId]
47+
: `https://${networkName(networkId)}.infura.io/v3/${infuraKey}`
48+
49+
const balanceProvider = createProvider({ rpcUrl })
50+
2651
const provider = new WalletConnectProvider({
2752
infuraId: infuraKey,
2853
rpc,
@@ -68,18 +93,13 @@ function walletConnect(
6893
}
6994
},
7095
balance: {
71-
get: () =>
72-
new Promise(resolve => {
73-
if (!provider.wc._accounts[0]) {
74-
resolve(null)
75-
return
76-
}
96+
get: async () => {
97+
if (!provider.wc._accounts[0]) {
98+
return null
99+
}
77100

78-
provider.send('eth_getBalance', [
79-
provider.wc._accounts[0],
80-
'latest'
81-
])
82-
})
101+
return getBalance(balanceProvider, provider.wc._accounts[0])
102+
}
83103
},
84104
disconnect: () => {
85105
provider.wc.killSession()

src/stores.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,12 @@ export function resetWalletState(options?: {
125125
// no options object, so do a full reset by disconnecting and setting interface to null
126126
if (!options) {
127127
wallet.update(() => ({
128-
name: null,
129-
provider: null,
130-
connect: null,
131-
instance: null,
132-
dashboard: null
128+
name: undefined,
129+
provider: undefined,
130+
connect: undefined,
131+
instance: undefined,
132+
dashboard: undefined,
133+
type: undefined
133134
}))
134135

135136
currentInterface.disconnect && currentInterface.disconnect()

src/views/WalletSelect.svelte

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,6 @@
9898
deviceWallets.length > 4 ? deviceWallets.slice(4) : undefined
9999
}
100100
101-
modalData = {
102-
heading,
103-
description,
104-
explanation,
105-
primaryWallets,
106-
secondaryWallets
107-
}
108-
109101
if (appState.autoSelectWallet) {
110102
const module = deviceWallets.find(
111103
(m: WalletModule) => m.name === appState.autoSelectWallet
@@ -114,15 +106,23 @@
114106
app.update(store => ({ ...store, autoSelectWallet: '' }))
115107
116108
if (module) {
117-
handleWalletSelect(module)
109+
handleWalletSelect(module, true)
118110
return
119111
}
120112
}
121113
114+
modalData = {
115+
heading,
116+
description,
117+
explanation,
118+
primaryWallets,
119+
secondaryWallets
120+
}
121+
122122
app.update(store => ({ ...store, walletSelectDisplayedUI: true }))
123123
}
124124
125-
async function handleWalletSelect(module: WalletModule) {
125+
async function handleWalletSelect(module: WalletModule, autoSelected?: boolean) {
126126
const currentWalletInterface = get(walletInterface)
127127
128128
if (currentWalletInterface && currentWalletInterface.name === module.name) {
@@ -163,7 +163,18 @@
163163
selectedWallet: selectedWalletModule.name
164164
})
165165
166-
app.update(store => ({ ...store, walletSelectDisplayedUI: true }))
166+
// if it was autoSelected then we need to add modalData to show the modal
167+
if (autoSelected) {
168+
modalData = {
169+
heading,
170+
description,
171+
explanation,
172+
primaryWallets,
173+
secondaryWallets
174+
}
175+
176+
app.update(store => ({ ...store, walletSelectDisplayedUI: true }))
177+
}
167178
168179
return
169180
}

0 commit comments

Comments
 (0)