Skip to content

Commit f96305f

Browse files
committed
Add extra wallet check customization options
1 parent c3a9c48 commit f96305f

File tree

5 files changed

+72
-66
lines changed

5 files changed

+72
-66
lines changed

src/interfaces.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,20 @@ export type AllWalletInitOptions = CommonWalletOptions &
249249
ImTokenOptions &
250250
TrustWalletOptions & { networkId: number }
251251

252-
export interface WalletCheckInit {
253-
checkName: string
252+
export interface WalletCheckCustomOptions {
254253
heading?: string
255254
description?: string
256255
minimumBalance?: string
256+
icon?: string
257+
button?: {
258+
text: string
259+
onclick: () => void
260+
}
261+
html?: string
262+
}
263+
264+
export interface WalletCheckInit extends WalletCheckCustomOptions {
265+
checkName: string
257266
}
258267

259268
export interface WalletSelectFunction {

src/modules/check/balance.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
1-
import { WalletCheckModal, StateAndHelpers } from '../../interfaces'
2-
import { validateType } from '../../validation'
1+
import {
2+
WalletCheckModal,
3+
StateAndHelpers,
4+
WalletCheckCustomOptions
5+
} from '../../interfaces'
36
import { balanceIcon } from './icons'
47

58
function balance(
6-
options: {
7-
minimumBalance: string
8-
heading?: string
9-
description?: string
10-
icon?: string
11-
} = { minimumBalance: '0' }
9+
options: WalletCheckCustomOptions & { minimumBalance: string } = {
10+
minimumBalance: '0'
11+
}
1212
): (currentState: StateAndHelpers) => Promise<WalletCheckModal | undefined> {
13-
validateType({ name: 'balance options', value: options, type: 'object' })
14-
15-
const { minimumBalance, heading, description, icon } = options
16-
17-
validateType({
18-
name: 'minimumBalance',
19-
value: minimumBalance,
20-
type: 'string'
21-
})
13+
const { minimumBalance, heading, description, icon, html, button } = options
2214

2315
return async (StateAndHelpers: StateAndHelpers) => {
2416
const { balance, BigNumber, stateSyncStatus, stateStore } = StateAndHelpers
@@ -44,7 +36,9 @@ function balance(
4436
.div(BigNumber('1000000000000000000'))
4537
.toString(10)} ETH.`,
4638
eventCode: 'nsfFail',
47-
icon: icon || balanceIcon
39+
icon: icon || balanceIcon,
40+
html,
41+
button
4842
}
4943
}
5044
}

src/modules/check/connect.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
import {
22
WalletCheckModal,
33
StateAndHelpers,
4-
WalletCheckModule
4+
WalletCheckModule,
5+
WalletCheckCustomOptions
56
} from '../../interfaces'
67
import { connectIcon } from './icons'
78

8-
function connect(
9-
options: {
10-
heading?: string
11-
description?: string
12-
icon?: string
13-
} = {}
14-
): WalletCheckModule {
15-
const { heading, description, icon } = options
9+
function connect(options: WalletCheckCustomOptions = {}): WalletCheckModule {
10+
const { heading, description, icon, html, button } = options
1611

1712
return async (
1813
stateAndHelpers: StateAndHelpers
@@ -42,7 +37,9 @@ function connect(
4237
`This dapp requires access to your wallet, please login and authorize access to your ${wallet.name} accounts to continue.`,
4338
eventCode: 'loginFail',
4439
action: wallet.connect,
45-
icon: icon || connectIcon
40+
icon: icon || connectIcon,
41+
html,
42+
button
4643
}
4744
}
4845
}

src/modules/check/network.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { networkName } from '../../utilities'
2-
import { WalletCheckModal, StateAndHelpers } from '../../interfaces'
2+
import {
3+
WalletCheckModal,
4+
StateAndHelpers,
5+
WalletCheckCustomOptions
6+
} from '../../interfaces'
37
import { networkIcon } from './icons'
48

59
function network(
6-
options: {
7-
heading?: string
8-
description?: string
9-
icon?: string
10-
} = {}
10+
options: WalletCheckCustomOptions = {}
1111
): (currentState: StateAndHelpers) => Promise<WalletCheckModal | undefined> {
12-
const { heading, description, icon } = options
12+
const { heading, description, icon, html, button } = options
1313

1414
return async (stateAndHelpers: StateAndHelpers) => {
1515
const {
@@ -48,13 +48,14 @@ function network(
4848
appNetworkId
4949
)} network</b> for this Dapp. <br><br> <i style="font-size: inherit; font-family: inherit;">*Some wallets may not support changing networks. If you can not change networks in your wallet you may consider switching to a different wallet.</i>`,
5050
eventCode: 'networkFail',
51-
button: {
51+
button: button || {
5252
onclick: () => {
5353
exit()
5454
walletSelect()
5555
},
5656
text: 'Switch Wallet'
5757
},
58+
html,
5859
icon: icon || networkIcon
5960
}
6061
}

src/validation.ts

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,23 @@ function validateWalletCheck(
342342
heading,
343343
description,
344344
minimumBalance,
345+
html,
346+
icon,
347+
button,
345348
...otherParams
346349
} = check
347350

348351
invalidParams(
349352
otherParams,
350-
['checkName', 'heading', 'description', 'minimumBalance'],
353+
[
354+
'checkName',
355+
'heading',
356+
'description',
357+
'html',
358+
'icon',
359+
'button',
360+
'minimumBalance'
361+
],
351362
'walletCheck item'
352363
)
353364

@@ -367,6 +378,27 @@ function validateWalletCheck(
367378
optional: true
368379
})
369380

381+
validateType({
382+
name: 'html',
383+
value: html,
384+
type: 'string',
385+
optional: true
386+
})
387+
388+
validateType({
389+
name: 'icon',
390+
value: icon,
391+
type: 'string',
392+
optional: true
393+
})
394+
395+
validateType({
396+
name: 'button',
397+
value: button,
398+
type: 'object',
399+
optional: true
400+
})
401+
370402
validateType({
371403
name: 'minimumBalance',
372404
value: minimumBalance,
@@ -543,33 +575,6 @@ export function validateWalletInterface(
543575
})
544576
}
545577

546-
export function validateWalletCheckInit(
547-
walletCheckInit: WalletCheckInit[]
548-
): void | never {
549-
validateType({
550-
name: 'walletCheckInit',
551-
value: walletCheckInit,
552-
type: 'array'
553-
})
554-
555-
walletCheckInit.forEach(init => {
556-
validateType({ name: 'walletCheckInit', value: init, type: 'object' })
557-
558-
validateType({
559-
name: 'walletCheckInit.checkName',
560-
value: init.checkName,
561-
type: 'string'
562-
})
563-
564-
validateType({
565-
name: 'walletCheckInit.minimumBalance',
566-
value: init.minimumBalance,
567-
type: 'string',
568-
optional: true
569-
})
570-
})
571-
}
572-
573578
export function validateWalletInit(
574579
walletInit: WalletInitOptions
575580
): void | never {

0 commit comments

Comments
 (0)