Skip to content

Commit 2c3f48b

Browse files
authored
Merge pull request #283 from blocknative/develop
Release 1.6.0
2 parents 873eb30 + 643e0d7 commit 2c3f48b

File tree

11 files changed

+547
-454
lines changed

11 files changed

+547
-454
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bnc-onboard",
3-
"version": "1.5.0",
3+
"version": "1.6.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",
@@ -43,9 +43,9 @@
4343
"@ledgerhq/hw-transport-u2f": "^5.7.0",
4444
"@portis/web3": "^2.0.0-beta.42",
4545
"@toruslabs/torus-embed": "^1.2.4",
46-
"@unilogin/provider": "^0.5.20",
46+
"@unilogin/provider": "^0.5.21",
4747
"@walletconnect/web3-provider": "^1.0.0-beta.45",
48-
"authereum": "^0.0.4-beta.88",
48+
"authereum": "^0.0.4-beta.131",
4949
"bignumber.js": "^9.0.0",
5050
"bnc-sdk": "2.0.0",
5151
"bowser": "^2.5.2",

src/interfaces.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ export interface WalletModule {
8484
}>
8585
type: 'hardware' | 'injected' | 'sdk'
8686
link?: string
87-
url?: string
8887
installMessage?: (wallets: {
8988
currentWallet: string | undefined
9089
selectedWallet: string
@@ -117,6 +116,7 @@ export interface WalletInterface {
117116
address: StateSyncer
118117
network: StateSyncer
119118
balance: StateSyncer
119+
dashboard?: () => void
120120
}
121121

122122
export interface StateSyncer {
@@ -130,6 +130,7 @@ export interface Wallet {
130130
type: 'hardware' | 'injected' | 'sdk'
131131
instance?: any
132132
connect?: () => Promise<{ message: string } | undefined>
133+
dashboard?: () => void
133134
}
134135

135136
export interface CommonWalletOptions {
@@ -243,18 +244,20 @@ export interface WalletInterfaceStore {
243244
update: (
244245
updater: (walletInterface: WalletInterface | null) => WalletInterface | null
245246
) => void
246-
set: (walletInterface: WalletInterface) => void | never
247+
set: (walletInterface: WalletInterface | null) => void | never
247248
}
248249

249250
export interface WalletStateSliceStore {
250251
subscribe: (subscriber: (store: any) => void) => () => void
251252
reset: () => void
252-
setStateSyncer: (stateSyncer: StateSyncer) => number | undefined
253+
setStateSyncer: (
254+
stateSyncer: StateSyncer
255+
) => { clear: () => void } | undefined
253256
}
254257

255258
export interface BalanceStore {
256259
subscribe: (subscriber: (store: any) => void) => () => void
257-
setStateSyncer: (stateSyncer: StateSyncer) => number | undefined
260+
setStateSyncer: (stateSyncer: StateSyncer) => undefined
258261
reset: () => void
259262
}
260263

src/modules/select/wallets/authereum.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import authereumIcon from '../wallet-icons/icon-authereum.png'
2-
import { networkName } from '../../../utilities'
2+
import { networkName, openLink } from '../../../utilities'
33
import {
44
WalletModule,
55
AuthereumOptions,
@@ -37,7 +37,9 @@ function authereum(
3737
interface: {
3838
name: 'Authereum',
3939
connect: () => provider.enable(),
40-
disconnect: () => instance.logout(),
40+
disconnect: () => {
41+
instance.destroy()
42+
},
4143
address: {
4244
get: () => instance.getAccountAddress()
4345
},
@@ -49,16 +51,19 @@ function authereum(
4951
const loggedIn = await instance.isAuthenticated()
5052
return loggedIn && instance.getBalance()
5153
}
52-
}
54+
},
55+
dashboard: () =>
56+
openLink(
57+
`https://${
58+
networkId !== 1 ? `${networkName(networkId)}.` : ''
59+
}authereum.com/`
60+
)
5361
}
5462
}
5563
},
5664
type: 'sdk',
5765
desktop: true,
5866
mobile: true,
59-
url: `https://${
60-
networkId !== 1 ? `${networkName(networkId)}.` : ''
61-
}authereum.com/`,
6267
preferred
6368
}
6469
}

src/modules/select/wallets/portis.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { networkName } from '../../../utilities'
1+
import { networkName, openLink } from '../../../utilities'
22
import {
33
SdkWalletOptions,
44
WalletModule,
@@ -65,14 +65,14 @@ function portis(options: SdkWalletOptions & CommonWalletOptions): WalletModule {
6565
)
6666
}, 1)
6767
})
68-
}
68+
},
69+
dashboard: () => openLink('https://wallet.portis.io/')
6970
}
7071
}
7172
},
7273
type: 'sdk',
7374
desktop: true,
7475
mobile: true,
75-
url: 'https://wallet.portis.io/',
7676
preferred
7777
}
7878
}

src/modules/select/wallets/squarelink.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { networkName, networkToId } from '../../../utilities'
1+
import { networkName, networkToId, openLink } from '../../../utilities'
22
import {
33
SdkWalletOptions,
44
CommonWalletOptions,
@@ -60,14 +60,14 @@ function squarelink(
6060
}
6161
)
6262
})
63-
}
63+
},
64+
dashboard: () => openLink('https://app.squarelink.com/')
6465
}
6566
}
6667
},
6768
type: 'sdk',
6869
desktop: true,
6970
mobile: true,
70-
url: 'https://app.squarelink.com/',
7171
preferred
7272
}
7373
}

src/modules/select/wallets/torus.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { networkName } from '../../../utilities'
1+
import { networkName, openLink } from '../../../utilities'
22
import {
33
TorusOptions,
44
CommonWalletOptions,
@@ -76,14 +76,14 @@ function torus(options: TorusOptions & CommonWalletOptions): WalletModule {
7676
}
7777
)
7878
})
79-
}
79+
},
80+
dashboard: () => openLink('https://app.tor.us/')
8081
}
8182
}
8283
},
8384
type: 'sdk',
8485
desktop: true,
8586
mobile: true,
86-
url: 'https://app.tor.us/',
8787
preferred
8888
}
8989
}

src/modules/select/wallets/unilogin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ function unilogin(options: CommonWalletOptions): WalletModule {
2323
disconnect: () =>
2424
new Promise(resolve =>
2525
provider.send({ method: 'ul_disconnect' }, resolve)
26-
)
26+
),
27+
dashboard: () => provider.openDashboard()
2728
}
2829
}
2930
},

src/stores.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getBlocknative } from './services'
22
import { writable, derived, get } from 'svelte/store'
3-
import { wait, makeCancelable } from './utilities'
3+
import { wait, makeCancelable, createInterval } from './utilities'
44
import { validateWalletInterface, validateType } from './validation'
55
import {
66
WritableStore,
@@ -51,7 +51,7 @@ export const wallet: WritableStore = writable({
5151
provider: null,
5252
connect: null,
5353
instance: null,
54-
url: null,
54+
dashboard: null,
5555
type: null
5656
})
5757

@@ -70,7 +70,7 @@ export const state = derived(
7070
)
7171

7272
// keep track of intervals that are syncing state so they can be cleared
73-
let currentSyncerIntervals: (number | undefined)[] = []
73+
let currentSyncerIntervals: ({ clear: () => void } | undefined)[] = []
7474

7575
export const walletInterface: WalletInterfaceStore = createWalletInterfaceStore(
7676
null
@@ -79,7 +79,8 @@ export const walletInterface: WalletInterfaceStore = createWalletInterfaceStore(
7979
walletInterface.subscribe((walletInterface: WalletInterface | null) => {
8080
// clear all current intervals if they exist
8181
currentSyncerIntervals.forEach(
82-
(interval: number | undefined) => interval && clearInterval(interval)
82+
(interval: { clear: () => void } | undefined) =>
83+
interval && interval.clear()
8384
)
8485

8586
const currentState = get(state)
@@ -118,7 +119,7 @@ export function resetWalletState(options?: {
118119
provider: undefined,
119120
connect: undefined,
120121
instance: undefined,
121-
url: undefined
122+
dashboard: undefined
122123
}))
123124

124125
currentInterface.disconnect && currentInterface.disconnect()
@@ -135,10 +136,10 @@ export function resetWalletState(options?: {
135136
provider: undefined,
136137
connect: undefined,
137138
instance: undefined,
138-
url: undefined
139+
dashboard: undefined
139140
}))
140141

141-
disconnected &&
142+
!disconnected &&
142143
currentInterface.disconnect &&
143144
currentInterface.disconnect()
144145

@@ -175,8 +176,10 @@ function createWalletInterfaceStore(
175176
return {
176177
subscribe,
177178
update,
178-
set: (walletInterface: WalletInterface) => {
179-
validateWalletInterface(walletInterface)
179+
set: (walletInterface: WalletInterface | null) => {
180+
if (walletInterface) {
181+
validateWalletInterface(walletInterface)
182+
}
180183
set(walletInterface)
181184
}
182185
}
@@ -228,11 +231,11 @@ function createWalletStateSliceStore(options: {
228231
}
229232

230233
if (get) {
231-
const interval: any = setInterval(() => {
234+
const interval: any = createInterval(() => {
232235
get()
233236
.then(newVal => {
234237
if (newVal || currentState !== initialState) {
235-
set(newVal)
238+
interval.status.active && set(newVal)
236239
}
237240
})
238241
.catch((err: any) => {

src/utilities.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,20 @@ export function isPromise(val: any): val is Promise<any> {
270270
}
271271
return false
272272
}
273+
274+
export function createInterval(func: any, interval: number) {
275+
const id = setInterval(func, interval)
276+
const status = { active: true }
277+
278+
return {
279+
status,
280+
clear: () => {
281+
clearInterval(id)
282+
status.active = false
283+
}
284+
}
285+
}
286+
287+
export function openLink(url: string) {
288+
window.open(url)
289+
}

src/views/WalletSelect.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
wallet.set({
176176
provider,
177177
instance,
178-
url: module.url,
178+
dashboard: selectedWalletInterface.dashboard,
179179
name: module.name,
180180
connect: selectedWalletInterface.connect,
181181
type: module.type

0 commit comments

Comments
 (0)