Skip to content

Commit 35445b2

Browse files
authored
Merge pull request #463 from blocknative/develop
Release 1.17.0
2 parents fbb0ca4 + 140db9a commit 35445b2

File tree

13 files changed

+208
-90
lines changed

13 files changed

+208
-90
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.16.1",
3+
"version": "1.17.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",
@@ -48,10 +48,10 @@
4848
"@ledgerhq/hw-app-eth": "^5.21.0",
4949
"@ledgerhq/hw-transport-u2f": "^5.21.0",
5050
"@portis/web3": "^2.0.0-beta.57",
51-
"@toruslabs/torus-embed": "^1.8.2",
51+
"@toruslabs/torus-embed": "1.8.2",
5252
"@unilogin/provider": "^0.6.1",
5353
"@walletconnect/web3-provider": "^1.3.1",
54-
"authereum": "^0.0.4-beta.157",
54+
"authereum": "^0.1.12",
5555
"bignumber.js": "^9.0.0",
5656
"bnc-sdk": "^2.1.4",
5757
"bowser": "^2.10.0",

src/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface Initialization {
77
darkMode?: boolean
88
apiUrl?: string
99
hideBranding?: boolean
10+
blockPollingInterval?: number
1011
}
1112

1213
export interface Subscriptions {

src/modules/select/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const defaultWalletNames = [
1616
'hyperpay',
1717
'unilogin',
1818
'tokenpocket',
19-
'dcent'
19+
'dcent',
20+
'atoken'
2021
]
2122

2223
function select(
@@ -109,6 +110,8 @@ function getModule(name: string): Promise<any> | undefined {
109110
return import('./wallets/tokenpocket')
110111
case 'dcent':
111112
return import('./wallets/dcent')
113+
case 'atoken':
114+
return import('./wallets/atoken')
112115
default:
113116
return
114117
}
Loading
Loading

src/modules/select/wallets/atoken.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { mobileWalletInstallMessage } from '../content'
2+
import { WalletModule, Helpers, CommonWalletOptions } from '../../../interfaces'
3+
4+
import atokenIcon from '../wallet-icons/icon-atoken.png'
5+
import atokenIcon2x from '../wallet-icons/icon-atoken@2x.png'
6+
7+
function atoken(options: CommonWalletOptions): WalletModule {
8+
const { preferred, label, iconSrc, svg } = options
9+
10+
return {
11+
name: label || 'AToken',
12+
iconSrc: iconSrc || atokenIcon,
13+
iconSrcSet: iconSrc || atokenIcon2x,
14+
svg,
15+
wallet: async (helpers: Helpers) => {
16+
const { getProviderName, createModernProviderInterface } = helpers
17+
18+
const provider =
19+
(window as any).ethereum ||
20+
((window as any).web3 && (window as any).web3.currentProvider)
21+
22+
return {
23+
provider,
24+
interface:
25+
(getProviderName(provider) === 'AToken' &&
26+
createModernProviderInterface(provider)) ||
27+
null
28+
}
29+
},
30+
type: 'injected',
31+
link: 'https://www.atoken.com',
32+
installMessage: mobileWalletInstallMessage,
33+
mobile: true,
34+
preferred
35+
}
36+
}
37+
38+
export default atoken

src/modules/select/wallets/providerEngine.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import HookedWalletSubprovider from 'web3-provider-engine/subproviders/hooked-wa
44
import SubscriptionSubprovider from 'web3-provider-engine/subproviders/subscriptions'
55
import FilterSubprovider from 'web3-provider-engine/subproviders/filters'
66

7+
import { get } from 'svelte/store'
8+
9+
import { app } from '../../../stores'
10+
711
function createProvider(config: any) {
812
const {
913
getAccounts,
@@ -12,9 +16,11 @@ function createProvider(config: any) {
1216
processMessage,
1317
processPersonalMessage,
1418
signMessage,
15-
signPersonalMessage
19+
signPersonalMessage,
1620
} = config
1721

22+
const pollingInterval = get(app).blockPollingInterval
23+
1824
const idMgmt =
1925
getAccounts &&
2026
new HookedWalletSubprovider({
@@ -30,7 +36,7 @@ function createProvider(config: any) {
3036
rpcUrl: rpcUrl.includes('http') ? rpcUrl : `https://${rpcUrl}`
3137
})
3238

33-
const provider = new Web3ProviderEngine()
39+
const provider = new Web3ProviderEngine({pollingInterval})
3440

3541
provider.addProvider(new SubscriptionSubprovider())
3642
provider.addProvider(new FilterSubprovider())

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import {
66

77
import walletConnectIcon from '../wallet-icons/icon-wallet-connect'
88

9+
import { get } from 'svelte/store'
10+
11+
import {
12+
app,
13+
} from '../../../stores'
14+
915
function walletConnect(
1016
options: WalletConnectOptions & { networkId: number }
1117
): WalletModule {
@@ -20,6 +26,8 @@ function walletConnect(
2026
networkId
2127
} = options
2228

29+
const pollingInterval = get(app).blockPollingInterval
30+
2331
if (!infuraKey) {
2432
if (!rpc || !rpc[networkId]) {
2533
throw new Error(
@@ -50,7 +58,8 @@ function walletConnect(
5058
const provider = new WalletConnectProvider({
5159
infuraId: infuraKey,
5260
rpc,
53-
bridge
61+
bridge,
62+
pollingInterval
5463
})
5564

5665
provider.autoRefreshOnNetworkChange = false

src/onboard.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ function init(initialization: Initialization): API {
4949
networkId,
5050
darkMode,
5151
apiUrl,
52-
hideBranding
52+
hideBranding,
53+
blockPollingInterval = 4000
5354
} = initialization
5455

5556
const { os, browser, isMobile } = getDeviceInfo()
@@ -86,7 +87,8 @@ function init(initialization: Initialization): API {
8687
browser,
8788
darkMode,
8889
displayBranding,
89-
checkModules: initializedModules.walletCheck
90+
checkModules: initializedModules.walletCheck,
91+
blockPollingInterval
9092
}))
9193

9294
initializeStores()

src/stores.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ export const app: WritableStore = writable({
3030
checkModules: [],
3131
walletSelectDisplayedUI: false,
3232
walletCheckDisplayedUI: false,
33-
displayBranding: false
33+
displayBranding: false,
34+
blockPollingInterval: 4000,
3435
})
3536

3637
export const stateSyncStatus: {

src/utilities.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ export function getProviderName(provider: any): string | undefined {
258258
return 'HyperPay'
259259
}
260260

261+
if (provider.isAToken) {
262+
return 'AToken'
263+
}
264+
261265
if (provider.host && provider.host.indexOf('localhost') !== -1) {
262266
return 'localhost'
263267
}

src/validation.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export function validateInit(init: Initialization): never | void {
6464
darkMode,
6565
apiUrl,
6666
hideBranding,
67+
blockPollingInterval,
6768
...otherParams
6869
} = init
6970

@@ -77,7 +78,8 @@ export function validateInit(init: Initialization): never | void {
7778
'walletCheck',
7879
'darkMode',
7980
'apiUrl',
80-
'hideBranding'
81+
'hideBranding',
82+
'blockPollingInterval'
8183
],
8284
'init'
8385
)
@@ -107,6 +109,12 @@ export function validateInit(init: Initialization): never | void {
107109
type: 'boolean',
108110
optional: true
109111
})
112+
validateType({
113+
name: 'blockPollingInterval',
114+
value: blockPollingInterval,
115+
type: 'number',
116+
optional: true
117+
})
110118

111119
validateType({
112120
name: 'subscriptions',
@@ -640,7 +648,7 @@ export function validateWalletInit(
640648
'rpcUri',
641649
'webUri',
642650
'xsUri',
643-
'blockedPopupRedirect'
651+
'blockedPopupRedirect',
644652
],
645653
'walletInitObject'
646654
)

0 commit comments

Comments
 (0)