Skip to content

Commit 37af3d7

Browse files
committed
Update interfaces, edit torus implementation
1 parent 0683420 commit 37af3d7

File tree

10 files changed

+109
-55
lines changed

10 files changed

+109
-55
lines changed

src/interfaces.ts

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface Subscriptions {
1717
export interface WalletSelectModule {
1818
heading: string
1919
description: string
20-
wallets: Array<WalletModule | WalletInit>
20+
wallets: Array<WalletModule | WalletInitOptions>
2121
}
2222

2323
export interface WalletCheckModule {
@@ -118,46 +118,36 @@ export interface Wallet {
118118
loading?: Promise<undefined>
119119
}
120120

121-
export interface SdkWalletOptions {
122-
apiKey: string
121+
export interface CommonWalletOptions {
123122
networkId: number
124123
preferred?: boolean
125124
label?: string
126125
iconSrc?: string
127126
svg?: string
128127
}
129128

129+
export interface SdkWalletOptions {
130+
apiKey: string
131+
}
132+
130133
export interface WalletConnectOptions {
131134
infuraKey: string
132-
preferred?: boolean
133-
label?: string
134-
iconSrc?: string
135-
svg?: string
136135
}
137136

138137
export interface TorusOptions {
139-
networkId: number
140-
chainId?: number
141138
loginMethod?: 'google' | 'facebook' | 'twitch' | 'reddit' | 'discord'
142139
buildEnv?: 'production' | 'development' | 'staging' | 'testing'
143140
showTorusButton?: boolean
144141
buttonPosition?: 'top-left' | 'top-right' | 'bottom-right' | 'bottom-left'
145142
enableLogging?: boolean
146-
preferred?: boolean
147-
label?: string
148-
iconSrc?: string
149-
svg?: string
150143
}
151144

152-
export interface WalletInit {
145+
export interface WalletInitOptions
146+
extends CommonWalletOptions,
147+
SdkWalletOptions,
148+
WalletConnectOptions,
149+
TorusOptions {
153150
walletName: string
154-
preferred?: boolean
155-
apiKey?: string
156-
infuraKey?: string
157-
networkId?: number
158-
label?: string
159-
iconSrc?: string
160-
svg?: string
161151
}
162152

163153
export interface WalletCheckInit {

src/modules/select/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { WalletInit, WalletModule } from '../../interfaces'
1+
import { WalletModule, WalletInitOptions } from '../../interfaces'
22
import { isWalletInit } from '../../validation'
33

44
const defaultWalletNames = [
@@ -13,7 +13,7 @@ const defaultWalletNames = [
1313
]
1414

1515
function select(
16-
wallets: Array<WalletInit | WalletModule> | undefined,
16+
wallets: Array<WalletInitOptions | WalletModule> | undefined,
1717
networkId: number
1818
) {
1919
if (wallets) {

src/modules/select/wallets/authereum.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
import authereumIcon from '../wallet-icons/authereum.png'
22
import { networkName } from '../../../utilities'
3-
import { WalletModule } from '../../../interfaces'
3+
import { WalletModule, CommonWalletOptions } from '../../../interfaces'
44

5-
function authereum(options: {
6-
networkId: number
7-
preferred?: boolean
8-
label?: string
9-
iconSrc?: string
10-
svg?: string
11-
}): WalletModule {
5+
function authereum(options: CommonWalletOptions): WalletModule {
126
const { networkId, preferred, label, iconSrc, svg } = options
137

148
return {

src/modules/select/wallets/coinbase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { mobileWalletInstallMessage } from '../content'
2-
import { WalletModule, Helpers } from '../../../interfaces'
2+
import { WalletModule, Helpers, CommonWalletOptions } from '../../../interfaces'
33

44
function coinbase(
55
options: {

src/modules/select/wallets/fortmatic.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { networkName } from '../../../utilities'
2-
import { SdkWalletOptions, WalletModule, Helpers } from '../../../interfaces'
2+
import {
3+
SdkWalletOptions,
4+
WalletModule,
5+
Helpers,
6+
CommonWalletOptions
7+
} from '../../../interfaces'
38

49
const fortmaticIcon = `
510
<svg
@@ -15,7 +20,9 @@ const fortmaticIcon = `
1520
</svg>
1621
`
1722

18-
function fortmatic(options: SdkWalletOptions): WalletModule {
23+
function fortmatic(
24+
options: SdkWalletOptions & CommonWalletOptions
25+
): WalletModule {
1926
const { apiKey, networkId, preferred, label, iconSrc, svg } = options
2027

2128
return {

src/modules/select/wallets/portis.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import { networkName } from '../../../utilities'
2-
import { SdkWalletOptions, WalletModule, Helpers } from '../../../interfaces'
2+
import {
3+
SdkWalletOptions,
4+
WalletModule,
5+
Helpers,
6+
CommonWalletOptions
7+
} from '../../../interfaces'
38

49
const portisIcon = `
510
<svg height="40" viewBox="0 0 26 40" width="26" xmlns="http://www.w3.org/2000/svg"><g fill="none"><path d="m.38447675 22.9277905.93812327-.4094678 11.54391448-5.0174216 12.4724258 5.4268894-4.6829268 9.6753574-11.46701915 1.6205695-8.60843446-9.3004926z" fill="#133444"/><path d="m22.7456446 16.9549441c-2.0594671-2.4810138-4.9778453-4.095319-8.1739757-4.5214466l-.2037727-.0269133c-.9972573-.1211147-2.0055061-.1211147-3.0027634 0l-.2056951.024991c-3.19683486.4253443-6.11569177 2.0406007-8.17397573 4.5233689l-.51904361.861228-.86315031 1.4340982-.63054187 1.0496216c0 .024991-.02499099.0595939-.03460291.0845849v.0173014l1.38988346.8285474 8.84296527 5.2288838 1.7070768 1.0073291v-12.4954944l-1.7070768.7689535v-1.8647122l1.7070768-.7689535 1.7051544.7689535 8.6776402 3.9504986z" fill="#c42370"/><path d="m25.7234381 26.0324402c-.0248538 4.0988643-1.872927 7.97397-5.0424337 10.5731107-1.2054271.9911619-2.5812108 1.7546176-4.0600744 2.2530337-1.2073828.3962299-2.4702232.5974018-3.7409588.5959469-7.11281993 0-12.8799712-6.3227281-12.8799712-13.4220913.00397806-1.0496754.13304725-2.0951358.38447675-3.1142617l12.47242585 7.3800313 12.4743482-7.3800313c.2623236 1.017244.3941046 2.0637403.3921873 3.1142617z" fill="#1c4d6b"/><path d="m11.3651328 12.4161961 1.5013817.6747567-1.7070768.7747206v-1.5436741z" fill="#000"/><path d="m11.1594377 15.7438424 1.7070768-.7766431v12.4993392l-1.7070768-1.0073291z" fill="#000"/><path d="m12.8665145 14.9671993v12.4993392l11.9533822-7.0647603z" fill="#1d4259"/><path d="m12.8665145.56470023v14.40249907l11.9533822 5.4345789z" fill="#4b6b9a"/><path d="m12.8665145 14.9671993v12.4954944l-1.7070768-1.007329-10.22900396-6.0535865h-.01730146.02499099c0-.024991.02691338-.0595939.03460291-.0845849l1.49369218-2.4837198 8.69301934-3.9408867v1.8589451z" fill="#343535"/><path d="m12.8665145 14.9671993v12.4993392l-1.7070768-1.0073291-10.23861588-6.0478193-.00768954-.0096119.01730146-.0173014 10.22900396-4.6406344z" fill="#3e5578"/><path d="m12.8665145.56470023v14.40249907l-11.95338222 5.4345789z" fill="#6db2d8"/><g fill="#335f8a"><path d="m8.02787456 38.4298931c.18070408.0768953.35948577.1537907.53826746.2210741-.17878169-.0672834-.35756338-.1441788-.53826746-.2210741z"/><path d="m8.56614202 38.6509672c.17878169.0692058.36717529.1384116.55364652.1922384-.18647123-.0538268-.37486483-.1153431-.55364652-.1922384z"/><path d="m9.59077256 39.000841c.14417878.0442149.28066803.0768954.42484684.1114983-.13648928-.0346029-.28066806-.0768953-.42484684-.1114983z"/></g><path d="m.38447675 22.9277905 12.47242585 7.3800312c-.1695149 1.1206915-.4701886 2.2175699-.8958309 3.2680524-1.0034843 2.4222035-3.01045293 4.9751291-6.91865911 3.0277544-3.17007392-2.5978633-5.0183503-6.4726906-5.04241259-10.5711883.00728258-1.0462943.13630945-2.0881863.38447675-3.1046497z" fill="#6db2d8"/><path d="m20.6733149 36.6036285-.0346029.0269134c-.0672834.0499819-.1287997.1018863-.1922384.1537907l-.0173014.015379c-.0672835.0595939-.1441788.1114983-.2133846.1634027-.0758242.0613437-.1554406.1178457-.2383756.1691697-.0828404.0521651-.1624447.1093005-.2383756.1710922-.0768953.0595939-.1461012.0941968-.2133846.1461012l-.0442148.0249909c-.074973.0519044-.1518683.0941968-.2210742.1441788 0 0-.0173014 0-.0249909.0173015-.0768954.0519043-.1537907.0941968-.2306861.1461011-.0768953.0519044-.1710921.0941968-.255677.1441788s-.1710922.0941968-.2556771.1364893h-.0096119l-.255677.1268773c-.0845849.0422924-.1710922.0865073-.265289.1287997-.0941968.0422925-.1787817.0845849-.2633666.1191878-.1787816.0768954-.3594857.1537907-.5382674.2210741-.1787817.0672835-.3671753.1364893-.5536465.1922384-.0729076.0274308-.147369.0505395-.2229965.0692058l-.2460652.0768954c-.1461011.0422924-.2825904.0768953-.4267692.1114982-.0519043.0153791-.1114982.024991-.1634026.0422925l-.0922744.0173014-.2306861.049982c-.0768953.0173015-.1364892.0269134-.2133846.0422924-.0632285.0158437-.1274537.0274043-.1922383.034603-.0692058.0096119-.1461012.0269133-.2133846.0346029-.0346029 0-.0692058 0-.1018864.0173014l-.1634026.0173015h-.0845849c-.0590384.0105165-.1188222.016302-.1787817.0173014-.0738847.010539-.1483704.0163181-.2229965.0173015-.0595939 0-.1095758 0-.1710921 0s-.1018864.0096119-.1518683.0096119c-.0595939 0-.1191878 0-.1710922 0s-.1614802 0-.2383756 0h-.5113541c-.0800209.0050111-.160277.0050111-.2402979 0-.0595939 0-.1191878 0-.1787817 0-.0519044 0-.1018864-.0096119-.1537907-.0096119-.0519044 0-.1114983 0-.1710922 0-.0733428-.0095846-.1471332-.0153595-.2210741-.0173015-.0595939 0-.1191878 0-.1787817-.0173014h-.0865073c-.0532121-.0105119-.1072489-.0163015-.1614802-.0173015-.0345121-.0018508-.0686979-.0076559-.1018863-.0173014-.0718302-.0066855-.1431228-.0182465-.2133846-.0346029-.0692059 0-.1287997-.024991-.1922384-.034603-.0718469-.0101919-.1430817-.0243105-.2133846-.0422924-.0692058-.0173014-.1537907-.0326805-.2306861-.049982l-.0941968-.0173014c-.0593497-.0042617-.1184021-.0119642-.17685927-.0230686-.14610116-.0346029-.29027995-.0768954-.42676919-.1114983l-.25567704-.0768953c-.07689535-.024991-.1537907-.0422925-.22299652-.0692059-.19223837-.0595938-.3671753-.1268773-.55364652-.1922383-.18647122-.0653611-.3671753-.1441788-.53826745-.2210742-.08458489-.0422924-.17878169-.0768953-.26528896-.1191878l-.26336657-.1287997-.25567704-.1268773c-.08458489-.0422924-.16916977-.0941968-.25567704-.1364892-.08650727-.0422925-.17109216-.0941968-.25567704-.1441788-.08458489-.049982-.1537907-.0941968-.23068605-.1461012l-.02499099-.0173014c-.07756662-.0428621-.1520765-.0910366-.22299652-.1441788l-.04229244-.024991c-.06728343-.0422925-.14417878-.0941968-.2133846-.1461012-.06920581-.0519043-.16148023-.1095759-.23837558-.1710921-.07689535-.0615163-.16148024-.1095759-.23837559-.1691698l-.2133846-.1634026-.01730145-.0153791c-.06920582-.0519044-.12879971-.1038087-.19223838-.1537907l-.0346029-.0269134c3.89859425 1.9454524 5.92094194-.6132404 6.92058154-3.0200648.4259299-1.0505261.7272373-2.1473626.8977532-3.2680524.1691803 1.1238755.4698526 2.2239751.8958308 3.2776643 1.0111739 2.3779887 3.0258321 4.9386038 6.9244263 2.9912291z" fill="#529bba"/><path d="m15.7077977 39.1123393c.1441788-.0346029.2902799-.0768953.4267692-.1114983-.1364893.034603-.2825904.0768954-.4267692.1114983z" fill="#335f8a"/><path d="m16.611318 38.8489727c.1922384-.0595939.3671753-.1287997.5555689-.1922383-.180704.0711281-.3671753.1326444-.5555689.1922383z" fill="#335f8a"/><path d="m17.1668869 38.6509672c.1787817-.0672834.3575634-.1441788.5363451-.2210741-.1787817.0768953-.3575634.1537907-.5363451.2210741z" fill="#335f8a"/><path d="m25.723417 26.0324402c-.0248327 4.0988643-1.8729059 7.97397-5.0424126 10.5731107-3.8985942 1.9454523-5.9209419-.6151628-6.9205815-3.0200649-.4250714-1.0506755-.7257265-2.1474858-.8958308-3.2680524l12.4724258-7.3800312c.2564764 1.0116964.3862701 2.0513377.3863991 3.0950378z" fill="#4b6b9a"/></g></svg>
611
`
712

8-
function portis(options: SdkWalletOptions): WalletModule {
13+
function portis(options: SdkWalletOptions & CommonWalletOptions): WalletModule {
914
const { apiKey, networkId, preferred, label, iconSrc, svg } = options
1015

1116
return {

src/modules/select/wallets/squarelink.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { networkName, networkToId } from '../../../utilities'
2-
import { SdkWalletOptions, WalletModule, Helpers } from '../../../interfaces'
2+
import {
3+
SdkWalletOptions,
4+
CommonWalletOptions,
5+
WalletModule,
6+
Helpers
7+
} from '../../../interfaces'
38

49
const sqlkIcon = `
510
<svg width="88px" height="88px" viewBox="0 0 88 88" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
@@ -14,7 +19,9 @@ const sqlkIcon = `
1419
</svg>
1520
`
1621

17-
function squarelink(options: SdkWalletOptions): WalletModule {
22+
function squarelink(
23+
options: SdkWalletOptions & CommonWalletOptions
24+
): WalletModule {
1825
const { apiKey, networkId, preferred, label, iconSrc, svg } = options
1926

2027
return {

src/modules/select/wallets/torus.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import Torus from '@toruslabs/torus-embed'
22
import { networkName } from '../../../utilities'
3-
import { TorusOptions, WalletModule, Helpers } from '../../../interfaces'
3+
import {
4+
TorusOptions,
5+
CommonWalletOptions,
6+
WalletModule
7+
} from '../../../interfaces'
48

59
//import torusIcon from '../wallet-icons/icon-torus.png'
610

@@ -175,10 +179,9 @@ dGljYzpjb3B5cmlnaHQAQ29weXJpZ2h0IEFwcGxlIEluYy4sIDIwMTlYSzXXAAAAF3RFWHRpY2M6
175179
ZGVzY3JpcHRpb24ARGlzcGxheRcblbgAAAAASUVORK5CYII=" />
176180
</svg>`
177181

178-
function torus(options: TorusOptions): WalletModule {
182+
function torus(options: TorusOptions & CommonWalletOptions): WalletModule {
179183
const {
180184
networkId,
181-
chainId,
182185
preferred,
183186
label,
184187
iconSrc,
@@ -194,7 +197,7 @@ function torus(options: TorusOptions): WalletModule {
194197
name: label || 'Torus',
195198
svg: svg || torusIcon,
196199
iconSrc,
197-
wallet: async (helpers: Helpers) => {
200+
wallet: async () => {
198201
const instance = new Torus({
199202
buttonPosition: buttonPosition // default: bottom-left
200203
})
@@ -204,24 +207,22 @@ function torus(options: TorusOptions): WalletModule {
204207
enableLogging: enableLogging, // default: false
205208
network: {
206209
host: networkName(networkId), // default: mainnet
207-
chainId: chainId, // default: 1
210+
chainId: networkId, // default: 1
208211
networkName: `${networkName(networkId)} Network` // default: Main Ethereum Network
209212
},
210213
showTorusButton: showTorusButton // default: true
211214
})
212215

213216
const provider = instance.provider
214217

215-
const { BigNumber } = helpers
216-
217218
return {
218219
provider,
219220
instance,
220221
interface: {
221222
name: 'Torus',
222223
connect: async () => {
223224
let result = await instance.login({ verifier: loginMethod })
224-
return Promise.resolve({ message: result[0] })
225+
return { message: result[0] }
225226
},
226227
disconnect: () => instance.logout(),
227228
address: {
@@ -239,7 +240,7 @@ function torus(options: TorusOptions): WalletModule {
239240
if (err) {
240241
reject(`Error while checking Balance: ${err}`)
241242
} else {
242-
resolve(BigNumber(data.c[0]).toString())
243+
resolve(data.toString(10))
243244
}
244245
}
245246
)

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { WalletConnectOptions, WalletModule } from '../../../interfaces'
1+
import {
2+
WalletConnectOptions,
3+
WalletModule,
4+
CommonWalletOptions
5+
} from '../../../interfaces'
26

37
const walletConnectIcon = `
48
<svg
@@ -12,7 +16,9 @@ const walletConnectIcon = `
1216
</svg>
1317
`
1418

15-
function walletConnect(options: WalletConnectOptions): WalletModule {
19+
function walletConnect(
20+
options: WalletConnectOptions & CommonWalletOptions
21+
): WalletModule {
1622
const { infuraKey, preferred, label, iconSrc, svg } = options
1723

1824
return {

src/validation.ts

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
ConfigOptions,
88
WalletCheckModal,
99
WalletInterface,
10-
WalletInit,
10+
WalletInitOptions,
1111
WalletCheckInit
1212
} from './interfaces'
1313

@@ -188,11 +188,13 @@ export function isWalletModule(obj: any): obj is WalletModule {
188188
return (obj as WalletModule).wallet !== undefined
189189
}
190190

191-
export function isWalletInit(obj: any): obj is WalletInit {
192-
return (obj as WalletInit).walletName !== undefined
191+
export function isWalletInit(obj: any): obj is WalletInitOptions {
192+
return (obj as WalletInitOptions).walletName !== undefined
193193
}
194194

195-
export function validateWallet(obj: WalletModule | WalletInit): never | void {
195+
export function validateWallet(
196+
obj: WalletModule | WalletInitOptions
197+
): never | void {
196198
validateType({
197199
name: 'selectWallet.wallets item',
198200
value: obj,
@@ -508,7 +510,9 @@ export function validateWalletCheckInit(
508510
})
509511
}
510512

511-
export function validateWalletInit(walletInit: WalletInit): void | never {
513+
export function validateWalletInit(
514+
walletInit: WalletInitOptions
515+
): void | never {
512516
validateType({ name: 'walletInit', value: walletInit, type: 'object' })
513517

514518
const {
@@ -520,6 +524,11 @@ export function validateWalletInit(walletInit: WalletInit): void | never {
520524
label,
521525
iconSrc,
522526
svg,
527+
buildEnv,
528+
buttonPosition,
529+
enableLogging,
530+
loginMethod,
531+
showTorusButton,
523532
...otherParams
524533
} = walletInit
525534

@@ -533,7 +542,12 @@ export function validateWalletInit(walletInit: WalletInit): void | never {
533542
'preferred',
534543
'label',
535544
'iconSrc',
536-
'svg'
545+
'svg',
546+
'buildEnv',
547+
'buttonPosition',
548+
'enableLogging',
549+
'loginMethod',
550+
'showTorusButton'
537551
],
538552
'walletInitObject'
539553
)
@@ -590,4 +604,34 @@ export function validateWalletInit(walletInit: WalletInit): void | never {
590604
type: 'string',
591605
optional: true
592606
})
607+
validateType({
608+
name: 'walletInit.buildEnv',
609+
value: buildEnv,
610+
type: 'string',
611+
optional: true
612+
})
613+
validateType({
614+
name: 'walletInit.buttonPosition',
615+
value: buttonPosition,
616+
type: 'string',
617+
optional: true
618+
})
619+
validateType({
620+
name: 'walletInit.enableLogging',
621+
value: enableLogging,
622+
type: 'boolean',
623+
optional: true
624+
})
625+
validateType({
626+
name: 'walletInit.loginMethod',
627+
value: loginMethod,
628+
type: 'string',
629+
optional: true
630+
})
631+
validateType({
632+
name: 'walletInit.showTorusButton',
633+
value: showTorusButton,
634+
type: 'boolean',
635+
optional: true
636+
})
593637
}

0 commit comments

Comments
 (0)