Skip to content

Commit ad18889

Browse files
committed
Merge develop
2 parents 5df92fd + e230f47 commit ad18889

File tree

11 files changed

+207
-45
lines changed

11 files changed

+207
-45
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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +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",
3032
"bnc-sdk": "0.1.1",
3133
"bowser": "^2.5.2",
34+
"fortmatic": "^0.8.2",
3235
"promise-cancelable": "^2.1.1",
3336
"regenerator-runtime": "^0.13.3",
37+
"squarelink": "^1.1.3",
3438
"svelte": "^3.0.0",
35-
"svelte-i18n": "^1.1.2-beta",
36-
"@portis/web3": "^2.0.0-beta.42",
37-
"@walletconnect/web3-provider": "^1.0.0-beta.36",
38-
"fortmatic": "^0.8.2"
39+
"svelte-i18n": "^1.1.2-beta"
3940
},
4041
"scripts": {
4142
"prepare": "rollup -c",

rollup.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ export default [
4545
"svelte/store",
4646
"svelte/internal",
4747
"svelte/transition",
48+
"squarelink",
4849
"promise-cancelable",
4950
"regenerator-runtime/runtime",
5051
"@portis/web3",
5152
"@walletconnect/web3-provider",
52-
"fortmatic"
53+
"fortmatic",
5354
],
5455
plugins: [
5556
svelte(),

src/modules/select/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ 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 squarelink from "./wallets/squarelink"
89

910
function defaults({
1011
heading,
1112
description,
1213
networkId,
1314
fortmaticInit,
1415
portisInit,
16+
squarelinkInit,
1517
walletConnectInit
1618
}) {
1719
const desktopModules = [metamask(), dapper()]
@@ -36,6 +38,11 @@ function defaults({
3638
)
3739
}
3840

41+
if (squarelinkInit) {
42+
desktopModules.push(squarelink({ ...squarelinkInit, networkId }))
43+
mobileModules.push(squarelink({ ...squarelinkInit, networkId }))
44+
}
45+
3946
return {
4047
heading: heading || "Select a Wallet",
4148
description:
@@ -56,5 +63,6 @@ export default {
5663
coinbase,
5764
trust,
5865
portis,
59-
fortmatic
66+
fortmatic,
67+
squarelink
6068
}
Lines changed: 11 additions & 0 deletions
Loading

src/modules/select/wallets/fortmatic.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@ function fortmatic(options) {
1515
name: "Fortmatic",
1616
iconSrc: fortmaticIcon,
1717
wallet: ({ BigNumber }) => {
18-
const fortmatic = new Fortmatic(
18+
const instance = new Fortmatic(
1919
apiKey,
2020
networkId === 1 ? undefined : networkName(networkId)
2121
)
22-
const provider = fortmatic.getProvider()
22+
const provider = instance.getProvider()
2323

2424
return {
2525
provider,
26+
instance,
2627
interface: {
2728
name: "Fortmatic",
28-
connect: fortmatic.user.login,
29+
connect: instance.user.login,
2930
address: {
3031
get: () => Promise.resolve(provider.account)
3132
},
@@ -35,7 +36,7 @@ function fortmatic(options) {
3536
balance: {
3637
get: () =>
3738
provider.account &&
38-
fortmatic.user.getBalances().then(res =>
39+
instance.user.getBalances().then(res =>
3940
res[0]
4041
? BigNumber(res[0].crypto_amount)
4142
.times(BigNumber("1000000000000000000"))

src/modules/select/wallets/portis.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,25 @@ function portis(options) {
1616
name: "Portis",
1717
iconSrc: portisIcon,
1818
wallet: ({ BigNumber }) => {
19-
const portis = new Portis(apiKey, networkName(networkId))
20-
const { provider } = portis
19+
const instance = new Portis(apiKey, networkName(networkId))
20+
const { provider } = instance
2121

2222
return {
2323
provider,
24+
instance,
2425
interface: {
2526
name: "Portis",
2627
connect: provider.enable,
2728
address: {
2829
onChange: func => {
29-
portis.onLogin(address => {
30+
instance.onLogin(address => {
3031
func(address)
3132
provider.address = address
3233
})
3334
}
3435
},
3536
network: {
36-
get: () => Promise.resolve(portis.config.network.chainId)
37+
get: () => Promise.resolve(instance.config.network.chainId)
3738
},
3839
balance: {
3940
get: () =>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import Squarelink from "squarelink"
2+
3+
import { networkName, networkToId } from "../../../utilities"
4+
import sqlkIcon from "../wallet-icons/icon-squarelink.svg"
5+
6+
function squarelink(options) {
7+
if (!options || typeof options !== "object") {
8+
throw new Error(
9+
"An options object is required to initialize squarelink module"
10+
)
11+
}
12+
13+
const { apiKey, networkId } = options
14+
15+
if (!apiKey || typeof apiKey !== "string") {
16+
throw new Error(
17+
"A apiKey of type string is required to initialize squarelink module"
18+
)
19+
}
20+
21+
if (!networkId || typeof networkId !== "number") {
22+
throw new Error(
23+
"A network of type number is required to initialize squarelink module"
24+
)
25+
}
26+
27+
return {
28+
name: "Squarelink",
29+
iconSrc: sqlkIcon,
30+
wallet: ({ BigNumber }) => {
31+
const instance = new Squarelink(apiKey, networkName(networkId), {
32+
useSync: true
33+
})
34+
35+
const provider = instance.getProviderSync()
36+
37+
return {
38+
provider,
39+
instance,
40+
interface: {
41+
name: "Squarelink",
42+
connect: provider.enable,
43+
address: {
44+
get: () => Promise.resolve(instance.accounts[0])
45+
},
46+
network: {
47+
get: () => Promise.resolve(networkToId(instance.network))
48+
},
49+
balance: {
50+
get: () =>
51+
new Promise(resolve => {
52+
if (!instance.accounts.length) {
53+
resolve(null)
54+
return
55+
}
56+
57+
provider.sendAsync(
58+
{
59+
method: "eth_getBalance",
60+
params: [instance.accounts[0], "latest"],
61+
id: 1
62+
},
63+
(e, res) => {
64+
resolve(BigNumber(res.result).toString(10))
65+
}
66+
)
67+
})
68+
}
69+
}
70+
}
71+
}
72+
}
73+
}
74+
75+
export default squarelink

src/views/WalletSelect.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@
5858
}
5959
6060
function handleWalletSelect(module) {
61-
const { provider, interface: selectedWalletInterface } = module.wallet({
61+
const {
62+
provider,
63+
interface: selectedWalletInterface,
64+
instance
65+
} = module.wallet({
6266
getProviderName,
6367
createLegacyProviderInterface,
6468
createModernProviderInterface,
@@ -89,6 +93,7 @@
8993
9094
wallet.set({
9195
provider,
96+
instance,
9297
name: module.name,
9398
connect: selectedWalletInterface.connect
9499
});

types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface selectDefaultsOptions {
1717
networkId: number
1818
fortmaticInit?: any
1919
portisInit?: any
20+
squarelinkInit?: any
2021
walletConnectInit?: any
2122
}
2223

@@ -28,6 +29,7 @@ interface select {
2829
coinbase: () => any
2930
trust: () => any
3031
portis: (options: { apiKey: string; network: string }) => any
32+
squarleink: (options: { apiKey: string; network: string }) => any
3133
fortmatic: (options: { apiKey: string; network: string }) => any
3234
}
3335

0 commit comments

Comments
 (0)