Skip to content

Commit ecf2a32

Browse files
authored
Merge pull request #467 from blocknative/enhancement/polling-interval-param
blockPollingInterval add
2 parents 3bd5ef3 + 345654a commit ecf2a32

File tree

6 files changed

+35
-8
lines changed

6 files changed

+35
-8
lines changed

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/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/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)