Skip to content

Commit e7ff702

Browse files
committed
Update authereum integration and merge in upstream changes
2 parents 48c67e6 + 6872321 commit e7ff702

File tree

15 files changed

+538
-257
lines changed

15 files changed

+538
-257
lines changed

README.md

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ const onboard = Onboard.init({
2929
modules: {
3030
// default wallets that are included: MetaMask, Dapper, Coinbase, Trust, WalletConnect
3131
walletSelect: Onboard.modules.select.defaults({
32+
// if you want squarelink as a wallet option
33+
squarelinkInit: { apiKey: "Your squarelink key here" },
3234
// if you want fortmatic as a wallet option
3335
fortmaticInit: { apiKey: "Your fortmatic key here" },
3436
// if you want portis as a wallet option
@@ -88,7 +90,7 @@ const options = {
8890
address: Function, // Called with the current account address of the user [String]
8991
network: Function, // Called with the current network id the users' wallet is connected to [Number]
9092
balance: Function, // Called with the current balance in `wei` of the users' current account address [String]
91-
wallet: Function // Called with the users' current selected wallet [Object]: {provider: Object, name: String}
93+
wallet: Function // Called with the users' current selected wallet [Object]: {provider: Object, name: String, instance: Object (if a sdk wallet)}
9294
},
9395
modules: {
9496
walletSelect: {
@@ -176,6 +178,7 @@ The wallet select modules are functions that return a wallet object. The followi
176178
- `dapper`
177179
- `walletConnect` (requires initialization)
178180
- `portis` (requires initialization)
181+
- `squarelink` (requires initialization)
179182
- `fortmatic` (requires initialization)
180183

181184
#### Mobile Wallets
@@ -184,6 +187,7 @@ The wallet select modules are functions that return a wallet object. The followi
184187
- `coinbase`
185188
- `walletConnect` (requires initialization)
186189
- `portis` (requires initialization)
190+
- `squarelink` (requires initialization)
187191
- `fortmatic` (requires initialization)
188192

189193
`defaults` Initialization:
@@ -192,7 +196,8 @@ The wallet select modules are functions that return a wallet object. The followi
192196
modules.select.defaults({
193197
heading: String, // Override the default heading [optional]
194198
description: String, // Override the default description [optional]
195-
networkId: Number, // Required if you want the Portis or Fortmatic modules to be included
199+
networkId: Number, // Required if you want the Portis, Squarelink, or Fortmatic modules to be included
200+
squarelinkInit: Object, // initialization object for Squarelink module (see below)
196201
portisInit: Object, // initialization object for Portis module (see below)
197202
fortmaticInit: Object // initialization object for Fortmatic module (see below)
198203
})
@@ -207,11 +212,20 @@ portis({
207212
})
208213
```
209214

215+
`squarelink` Initialization:
216+
217+
```javascript
218+
squarelink({
219+
apiKey: String, // your Squarelink api key
220+
networkId: Number // the networkId of the network you want to connect to
221+
})
222+
```
223+
210224
`fortmatic` Initialization:
211225

212226
```javascript
213227
fortmatic({
214-
apiKey: String, // your Portis api key
228+
apiKey: String, // your Fortmatic api key
215229
networkId: Number // the networkId of the network you want to connect to
216230
})
217231
```
@@ -231,7 +245,13 @@ import Onboard from "bnc-onboard"
231245

232246
// PICK AND CHOOSE MODULES
233247

234-
const { portis, dapper, metamask, fortmatic } = Onboard.modules.select
248+
const {
249+
portis,
250+
squarelink,
251+
dapper,
252+
metamask,
253+
fortmatic
254+
} = Onboard.modules.select
235255

236256
const onboard = Onboard.init({
237257
// ...
@@ -242,11 +262,12 @@ const onboard = Onboard.init({
242262
"Please select the wallet that you would like to use with this Dapp",
243263
wallets: {
244264
desktop: [
245-
portis({ apiKey: 'sdda-w2-ds3', networkId: 1 })
265+
portis({ apiKey: "sdda-w2-ds3", networkId: 1 }),
266+
squarelink({ apiKey: "sdda-w2-ds3", networkId: 1 }),
246267
dapper(),
247-
metmask(),
268+
metmask()
248269
],
249-
mobile: [fortmatic({apiKey: 'sd-3d3-d', networkId: 1})]
270+
mobile: [fortmatic({ apiKey: "sd-3d3-d", networkId: 1 })]
250271
}
251272
}
252273
//....
@@ -263,7 +284,7 @@ const onboard = Onboard.init({
263284
walletSelect: Onboard.modules.select.defaults({
264285
portisInit: { apiKey: "Your portis key here" },
265286
networkId: 4
266-
}),
287+
})
267288
// ...
268289
}
269290
})

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bnc-onboard",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"main": "dist/cjs/index.js",
55
"module": "dist/esm/index.js",
66
"files": [
@@ -28,14 +28,14 @@
2828
"dependencies": {
2929
"@portis/web3": "^2.0.0-beta.42",
3030
"@walletconnect/web3-provider": "^1.0.0-beta.36",
31-
"authereum": "^0.0.4-beta.24",
31+
"authereum": "^0.0.4-beta.26",
3232
"bignumber.js": "^9.0.0",
33-
"bnc-sdk": "0.1.1",
33+
"bnc-sdk": "0.2.1",
3434
"bowser": "^2.5.2",
3535
"fortmatic": "^0.8.2",
36-
"ow": "^0.13.2",
3736
"promise-cancelable": "^2.1.1",
3837
"regenerator-runtime": "^0.13.3",
38+
"squarelink": "^1.1.3",
3939
"svelte": "^3.0.0",
4040
"svelte-i18n": "^1.1.2-beta"
4141
},

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ export default [
3939
external: [
4040
"bowser",
4141
"bnc-sdk",
42-
"ow",
4342
"bignumber.js",
4443
"svelte-i18n",
4544
"svelte",
4645
"svelte/store",
4746
"svelte/internal",
4847
"svelte/transition",
48+
"squarelink",
4949
"promise-cancelable",
5050
"regenerator-runtime/runtime",
5151
"@portis/web3",

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import {
1515
walletInterface
1616
} from "./stores"
1717

18-
import { validateInit, validateConfig } from "./validation"
1918
import { isMobileDevice } from "./utilities"
2019
import { initializeBlocknative } from "./services"
20+
import { validateInit, validateConfig } from "./validation"
2121

2222
import { version } from "../package.json"
2323

src/modules/ready/index.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,13 @@ import connect from "./connect"
22
import network from "./network"
33
import balance from "./balance"
44

5+
import { validateDefaultsOptions } from "../../validation"
6+
57
function defaults(options) {
6-
if (!options || typeof options !== "object") {
7-
throw new Error("initModules must be called with a valid option object")
8-
}
8+
validateDefaultsOptions(options)
99

1010
const { networkId, minimumBalance } = options
1111

12-
if (!networkId || typeof networkId !== "number") {
13-
throw new Error(
14-
"initModules must be called with a property of networkId that is of type Number"
15-
)
16-
}
17-
1812
return [connect(), network(networkId), balance(minimumBalance || "0")]
1913
}
2014

src/modules/select/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import trust from "./wallets/trust"
66
import portis from "./wallets/portis"
77
import fortmatic from "./wallets/fortmatic"
88
import authereum from "./wallets/authereum"
9+
import squarelink from "./wallets/squarelink"
910

1011
function defaults({
1112
heading,
1213
description,
1314
networkId,
1415
fortmaticInit,
1516
portisInit,
17+
squarelinkInit,
1618
walletConnectInit
1719
}) {
1820
const desktopModules = [metamask(), dapper()]
@@ -37,6 +39,11 @@ function defaults({
3739
)
3840
}
3941

42+
if (squarelinkInit) {
43+
desktopModules.push(squarelink({ ...squarelinkInit, networkId }))
44+
mobileModules.push(squarelink({ ...squarelinkInit, networkId }))
45+
}
46+
4047
desktopModules.push(authereum({ networkId }))
4148
mobileModules.push(authereum({ networkId }))
4249

@@ -61,5 +68,6 @@ export default {
6168
trust,
6269
portis,
6370
fortmatic,
64-
authereum
71+
authereum,
72+
squarelink
6573
}
Lines changed: 11 additions & 0 deletions
Loading

src/modules/select/wallets/fortmatic.js

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,32 @@
11
import Fortmatic from "fortmatic"
22
import fortmaticIcon from "../wallet-icons/icon-fortmatic.svg"
33
import { networkName } from "../../../utilities"
4+
import { validateType } from "../../../validation"
45

56
function fortmatic(options) {
6-
if (!options || typeof options !== "object") {
7-
throw new Error(
8-
"An options object is required to initialize fortmatic module"
9-
)
10-
}
7+
validateType({ name: "Fortmatic options", value: options, type: "object" })
118

129
const { apiKey, networkId } = options
1310

14-
if (!apiKey || typeof apiKey !== "string") {
15-
throw new Error(
16-
"A apiKey of type string is required to initialize fortmatic module"
17-
)
18-
}
19-
20-
if (!networkId || typeof networkId !== "number") {
21-
throw new Error(
22-
"A networkId of type number is required to initialize fortmatic module"
23-
)
24-
}
11+
validateType({ name: "apiKey", value: apiKey, type: "string" })
12+
validateType({ name: "networkId", value: networkId, type: "number" })
2513

2614
return {
2715
name: "Fortmatic",
2816
iconSrc: fortmaticIcon,
2917
wallet: ({ BigNumber }) => {
30-
const fortmatic = new Fortmatic(
18+
const instance = new Fortmatic(
3119
apiKey,
3220
networkId === 1 ? undefined : networkName(networkId)
3321
)
34-
const provider = fortmatic.getProvider()
22+
const provider = instance.getProvider()
3523

3624
return {
3725
provider,
26+
instance,
3827
interface: {
3928
name: "Fortmatic",
40-
connect: fortmatic.user.login,
29+
connect: instance.user.login,
4130
address: {
4231
get: () => Promise.resolve(provider.account)
4332
},
@@ -47,7 +36,7 @@ function fortmatic(options) {
4736
balance: {
4837
get: () =>
4938
provider.account &&
50-
fortmatic.user.getBalances().then(res =>
39+
instance.user.getBalances().then(res =>
5140
res[0]
5241
? BigNumber(res[0].crypto_amount)
5342
.times(BigNumber("1000000000000000000"))

src/modules/select/wallets/portis.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,41 @@
11
import Portis from "@portis/web3"
22

33
import { networkName } from "../../../utilities"
4+
import { validateType } from "../../../validation"
45
import portisIcon from "../wallet-icons/icon-portis.svg"
56

67
function portis(options) {
7-
if (!options || typeof options !== "object") {
8-
throw new Error("An options object is required to initialize portis module")
9-
}
8+
validateType({ name: "Portis options", value: options, type: "object" })
109

1110
const { apiKey, networkId } = options
1211

13-
if (!apiKey || typeof apiKey !== "string") {
14-
throw new Error(
15-
"A apiKey of type string is required to initialize portis module"
16-
)
17-
}
18-
19-
if (!networkId || typeof networkId !== "number") {
20-
throw new Error(
21-
"A network of type number is required to initialize portis module"
22-
)
23-
}
12+
validateType({ name: "apiKey", value: apiKey, type: "string" })
13+
validateType({ name: "networkId", value: networkId, type: "number" })
2414

2515
return {
2616
name: "Portis",
2717
iconSrc: portisIcon,
2818
wallet: ({ BigNumber }) => {
29-
const portis = new Portis(apiKey, networkName(networkId))
30-
const { provider } = portis
19+
const instance = new Portis(apiKey, networkName(networkId))
20+
const { provider } = instance
3121

3222
return {
3323
provider,
24+
instance,
3425
interface: {
3526
name: "Portis",
3627
connect: provider.enable,
3728
disconnect: () => portis.logout(),
3829
address: {
3930
onChange: func => {
40-
portis.onLogin(address => {
31+
instance.onLogin(address => {
4132
func(address)
4233
provider.address = address
4334
})
4435
}
4536
},
4637
network: {
47-
get: () => Promise.resolve(portis.config.network.chainId)
38+
get: () => Promise.resolve(instance.config.network.chainId)
4839
},
4940
balance: {
5041
get: () =>

0 commit comments

Comments
 (0)