Skip to content

Commit 9ac2878

Browse files
authored
Merge pull request #27 from blocknative/develop
Release 0.2.0
2 parents 1f50104 + 6872321 commit 9ac2878

File tree

16 files changed

+686
-379
lines changed

16 files changed

+686
-379
lines changed

README.md

Lines changed: 32 additions & 11 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
})
@@ -203,23 +208,32 @@ modules.select.defaults({
203208
```javascript
204209
portis({
205210
apiKey: String, // your Portis api key
206-
network: String // the name of network you want to connect to
211+
networkId: Number // the networkId of network you want to connect to
212+
})
213+
```
214+
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
207221
})
208222
```
209223

210224
`fortmatic` Initialization:
211225

212226
```javascript
213227
fortmatic({
214-
apiKey: String, // your Portis api key
215-
network: String // the name of the network you want to connect to
228+
apiKey: String, // your Fortmatic api key
229+
networkId: Number // the networkId of the network you want to connect to
216230
})
217231
```
218232

219233
`walletConnect` Initialization:
220234

221235
```javascript
222-
fortmatic({
236+
walletConnect({
223237
infuraKey: String
224238
})
225239
```
@@ -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', network: 'main' })
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', network: 'main'})]
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: 7 additions & 7 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": [
@@ -26,17 +26,17 @@
2626
"babel-plugin-external-helpers": "^6.18.0"
2727
},
2828
"dependencies": {
29+
"@portis/web3": "^2.0.0-beta.42",
30+
"@walletconnect/web3-provider": "^1.0.0-beta.36",
2931
"bignumber.js": "^9.0.0",
30-
"bnc-sdk": "0.1.1",
32+
"bnc-sdk": "0.2.1",
3133
"bowser": "^2.5.2",
32-
"ow": "^0.13.2",
34+
"fortmatic": "^0.8.2",
3335
"promise-cancelable": "^2.1.1",
3436
"regenerator-runtime": "^0.13.3",
37+
"squarelink": "^1.1.3",
3538
"svelte": "^3.0.0",
36-
"svelte-i18n": "^1.1.2-beta",
37-
"@portis/web3": "^2.0.0-beta.42",
38-
"@walletconnect/web3-provider": "^1.0.0-beta.36",
39-
"fortmatic": "^0.8.2"
39+
"svelte-i18n": "^1.1.2-beta"
4040
},
4141
"scripts": {
4242
"prepare": "rollup -c",

rollup.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ 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",
5252
"@walletconnect/web3-provider",
53-
"fortmatic"
53+
"fortmatic",
5454
],
5555
plugins: [
5656
svelte(),

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: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@ import coinbase from "./wallets/coinbase"
55
import trust from "./wallets/trust"
66
import portis from "./wallets/portis"
77
import fortmatic from "./wallets/fortmatic"
8-
import { networkName } from "../../utilities"
8+
import squarelink from "./wallets/squarelink"
99

1010
function defaults({
1111
heading,
1212
description,
1313
networkId,
1414
fortmaticInit,
1515
portisInit,
16+
squarelinkInit,
1617
walletConnectInit
1718
}) {
1819
const desktopModules = [metamask(), dapper()]
1920
const mobileModules = [coinbase(), trust()]
20-
const network = networkName(networkId)
2121

2222
if (portisInit) {
23-
desktopModules.push(portis({ ...portisInit, network }))
24-
mobileModules.push(portis({ ...portisInit, network }))
23+
desktopModules.push(portis({ ...portisInit, networkId }))
24+
mobileModules.push(portis({ ...portisInit, networkId }))
2525
}
2626

2727
if (fortmaticInit) {
28-
desktopModules.push(fortmatic({ ...fortmaticInit, network }))
29-
mobileModules.push(fortmatic({ ...fortmaticInit, network }))
28+
desktopModules.push(fortmatic({ ...fortmaticInit, networkId }))
29+
mobileModules.push(fortmatic({ ...fortmaticInit, networkId }))
3030
}
3131

3232
if (walletConnectInit) {
@@ -38,6 +38,11 @@ function defaults({
3838
)
3939
}
4040

41+
if (squarelinkInit) {
42+
desktopModules.push(squarelink({ ...squarelinkInit, networkId }))
43+
mobileModules.push(squarelink({ ...squarelinkInit, networkId }))
44+
}
45+
4146
return {
4247
heading: heading || "Select a Wallet",
4348
description:
@@ -58,5 +63,6 @@ export default {
5863
coinbase,
5964
trust,
6065
portis,
61-
fortmatic
66+
fortmatic,
67+
squarelink
6268
}
Lines changed: 11 additions & 0 deletions
Loading

src/modules/select/wallets/fortmatic.js

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,42 @@
11
import Fortmatic from "fortmatic"
2-
import { networkToId } from "../../../utilities"
32
import fortmaticIcon from "../wallet-icons/icon-fortmatic.svg"
3+
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-
}
11-
12-
const { apiKey, network } = options
7+
validateType({ name: "Fortmatic options", value: options, type: "object" })
138

14-
if (!apiKey || typeof apiKey !== "string") {
15-
throw new Error(
16-
"A apiKey of type string is required to initialize fortmatic module"
17-
)
18-
}
9+
const { apiKey, networkId } = options
1910

20-
if (!network || typeof network !== "string") {
21-
throw new Error(
22-
"A network of type string 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(apiKey, network)
31-
const provider = fortmatic.getProvider()
18+
const instance = new Fortmatic(
19+
apiKey,
20+
networkId === 1 ? undefined : networkName(networkId)
21+
)
22+
const provider = instance.getProvider()
3223

3324
return {
3425
provider,
26+
instance,
3527
interface: {
3628
name: "Fortmatic",
37-
connect: fortmatic.user.login,
29+
connect: instance.user.login,
3830
address: {
3931
get: () => Promise.resolve(provider.account)
4032
},
4133
network: {
42-
get: () => Promise.resolve(networkToId(network))
34+
get: () => Promise.resolve(networkId)
4335
},
4436
balance: {
4537
get: () =>
4638
provider.account &&
47-
fortmatic.user.getBalances().then(res =>
39+
instance.user.getBalances().then(res =>
4840
res[0]
4941
? BigNumber(res[0].crypto_amount)
5042
.times(BigNumber("1000000000000000000"))

0 commit comments

Comments
 (0)