Skip to content

Commit 2072308

Browse files
committed
Merge branch 'develop' into feature/custom-derivation-path
2 parents 87bd999 + bc25401 commit 2072308

File tree

9 files changed

+42
-27
lines changed

9 files changed

+42
-27
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.3.5",
3+
"version": "1.3.6",
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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ export interface TrezorOptions {
154154

155155
export interface LedgerOptions {
156156
rpcUrl: string
157+
LedgerTransport?: any
157158
}
158159

159160
export interface TorusOptions {
@@ -165,13 +166,12 @@ export interface TorusOptions {
165166
enabledVerifiers: TorusVerifierStatus
166167
}
167168

168-
169169
interface TorusVerifierStatus {
170-
google?: boolean;
171-
facebook?: boolean;
172-
reddit?: boolean;
173-
twitch?: boolean;
174-
discord?: boolean;
170+
google?: boolean
171+
facebook?: boolean
172+
reddit?: boolean
173+
twitch?: boolean
174+
discord?: boolean
175175
}
176176

177177
export interface AuthereumOptions {

src/modules/select/wallets/fortmatic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ function fortmatic(
2525
networkId === 1 ? undefined : networkName(networkId)
2626
)
2727
const provider = instance.getProvider()
28-
2928
const { BigNumber } = helpers
3029

3130
return {
@@ -34,6 +33,7 @@ function fortmatic(
3433
interface: {
3534
name: 'Fortmatic',
3635
connect: instance.user.login,
36+
disconnect: instance.user.logout,
3737
address: {
3838
get: () => Promise.resolve(provider.account)
3939
},

src/modules/select/wallets/ledger.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@ const LEDGER_LIVE_PATH = `m/44'/60'`
1919
const ACCOUNTS_TO_GET = 5
2020

2121
function ledger(options: LedgerOptions & CommonWalletOptions): WalletModule {
22-
const { rpcUrl, networkId, preferred, label, iconSrc, svg } = options
22+
const {
23+
rpcUrl,
24+
LedgerTransport,
25+
networkId,
26+
preferred,
27+
label,
28+
iconSrc,
29+
svg
30+
} = options
2331

2432
return {
2533
name: label || 'Ledger',
@@ -31,6 +39,7 @@ function ledger(options: LedgerOptions & CommonWalletOptions): WalletModule {
3139
const provider = await ledgerProvider({
3240
rpcUrl,
3341
networkId,
42+
LedgerTransport,
3443
BigNumber,
3544
networkName
3645
})
@@ -65,10 +74,11 @@ function ledger(options: LedgerOptions & CommonWalletOptions): WalletModule {
6574
async function ledgerProvider(options: {
6675
networkId: number
6776
rpcUrl: string
77+
LedgerTransport: any
6878
BigNumber: any
6979
networkName: (id: number) => string
7080
}) {
71-
const { networkId, rpcUrl, BigNumber, networkName } = options
81+
const { networkId, rpcUrl, LedgerTransport, BigNumber, networkName } = options
7282

7383
let dPath = ''
7484
let addressToPath = new Map()
@@ -106,17 +116,21 @@ async function ledgerProvider(options: {
106116
provider.disconnect = disconnect
107117
provider.isCustomPath = isCustomPath
108118

109-
let transport
119+
let transport: any
110120
let eth: any
111121

112122
try {
113-
transport = await TransportU2F.create()
123+
transport = LedgerTransport
124+
? await LedgerTransport.create()
125+
: await TransportU2F.create()
126+
114127
eth = new Eth(transport)
115128
} catch (error) {
116129
throw new Error('Error connecting to Ledger wallet')
117130
}
118131

119132
function disconnect() {
133+
transport.close()
120134
dPath = ''
121135
addressToPath = new Map()
122136
enabled = false
@@ -290,15 +304,6 @@ async function ledgerProvider(options: {
290304

291305
async function signTransaction(transactionData: any) {
292306
const path = [...addressToPath.values()][0]
293-
let transport
294-
let eth
295-
296-
try {
297-
transport = await TransportU2F.create()
298-
eth = new Eth(transport)
299-
} catch (error) {
300-
throw new Error('Error connecting to Ledger wallet')
301-
}
302307

303308
try {
304309
const transaction = new EthereumTx.Transaction(transactionData, {

src/modules/select/wallets/portis.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ function portis(options: SdkWalletOptions & CommonWalletOptions): WalletModule {
1919
const { default: Portis } = await import('@portis/web3')
2020
const instance = new Portis(apiKey, networkName(networkId))
2121
const provider = instance.provider
22-
2322
const { BigNumber } = helpers
2423

2524
return {
@@ -28,6 +27,10 @@ function portis(options: SdkWalletOptions & CommonWalletOptions): WalletModule {
2827
interface: {
2928
name: 'Portis',
3029
connect: provider.enable,
30+
disconnect: () => {
31+
instance.logout()
32+
provider.stop()
33+
},
3134
address: {
3235
onChange: func => {
3336
instance.onLogin((address: string) => {

src/modules/select/wallets/squarelink.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ function squarelink(
2525
})
2626

2727
const provider = instance.getProviderSync()
28-
2928
const { BigNumber } = helpers
3029

3130
return {
@@ -34,6 +33,7 @@ function squarelink(
3433
interface: {
3534
name: 'Squarelink',
3635
connect: provider.enable,
36+
disconnect: () => provider.stop(),
3737
address: {
3838
get: () => Promise.resolve(instance.accounts[0])
3939
},

src/validation.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ export function validateWalletInit(
527527
appUrl,
528528
email,
529529
rpcUrl,
530+
LedgerTransport,
530531
buildEnv,
531532
buttonPosition,
532533
enableLogging,
@@ -551,6 +552,7 @@ export function validateWalletInit(
551552
'appUrl',
552553
'email',
553554
'rpcUrl',
555+
'LedgerTransport',
554556
'buildEnv',
555557
'buttonPosition',
556558
'enableLogging',
@@ -619,11 +621,17 @@ export function validateWalletInit(
619621
validateType({
620622
name: 'walletInit.appUrl',
621623
value: appUrl,
622-
623624
type: 'string',
624625
optional: true
625626
})
626627

628+
validateType({
629+
name: 'walletInit.LedgerTransport',
630+
value: LedgerTransport,
631+
type: 'function',
632+
optional: true
633+
})
634+
627635
validateType({
628636
name: 'walletInit.email',
629637
value: email,
@@ -660,7 +668,6 @@ export function validateWalletInit(
660668
optional: true
661669
})
662670

663-
664671
validateType({
665672
name: 'walletInit.enabledVerifiers',
666673
value: enabledVerifiers,

src/views/WalletCheck.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
window.scrollTo(0, 0)
5959
}
6060
61-
let originalOverflowValue
61+
let originalOverflowValue: string
6262
6363
onMount(() => {
6464
originalOverflowValue = window.document.body.style.overflow

src/views/WalletSelect.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
window.scrollTo(0, 0)
6262
}
6363
64-
let originalOverflowValue
64+
let originalOverflowValue: string
6565
6666
onMount(() => {
6767
originalOverflowValue = window.document.body.style.overflow

0 commit comments

Comments
 (0)