Skip to content

Commit f38af7e

Browse files
authored
Merge pull request #20 from theAlexPatin/develop
Squarelink Wallet Integration
2 parents 7b2ebe3 + 1f1f8a1 commit f38af7e

File tree

8 files changed

+178
-12
lines changed

8 files changed

+178
-12
lines changed

README.md

Lines changed: 19 additions & 4 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
@@ -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,7 @@ import Onboard from "bnc-onboard"
231245

232246
// PICK AND CHOOSE MODULES
233247

234-
const { portis, dapper, metamask, fortmatic } = Onboard.modules.select
248+
const { portis, squarelink, dapper, metamask, fortmatic } = Onboard.modules.select
235249

236250
const onboard = Onboard.init({
237251
// ...
@@ -242,7 +256,8 @@ const onboard = Onboard.init({
242256
"Please select the wallet that you would like to use with this Dapp",
243257
wallets: {
244258
desktop: [
245-
portis({ apiKey: 'sdda-w2-ds3', networkId: 1 })
259+
portis({ apiKey: 'sdda-w2-ds3', networkId: 1 }),
260+
squarelink({ apiKey: 'sdda-w2-ds3', networkId: 1 }),
246261
dapper(),
247262
metmask(),
248263
],

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,18 @@
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
"ow": "^0.13.2",
3336
"promise-cancelable": "^2.1.1",
3437
"regenerator-runtime": "^0.13.3",
38+
"squarelink": "^1.1.3",
3539
"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"
40+
"svelte-i18n": "^1.1.2-beta"
4041
},
4142
"scripts": {
4243
"prepare": "rollup -c",

rollup.config.js

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

src/modules/select/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,25 @@ 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()]
1820
const mobileModules = [coinbase(), trust()]
1921

22+
if (squarelinkInit) {
23+
desktopModules.push(squarelink({ ...squarelinkInit, networkId }))
24+
mobileModules.push(squarelink({ ...squarelinkInit, networkId }))
25+
}
26+
2027
if (portisInit) {
2128
desktopModules.push(portis({ ...portisInit, networkId }))
2229
mobileModules.push(portis({ ...portisInit, networkId }))
@@ -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
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import Squarelink from "squarelink"
2+
3+
import { networkName } 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("An options object is required to initialize squarelink module")
9+
}
10+
11+
const { apiKey, networkId } = options
12+
13+
if (!apiKey || typeof apiKey !== "string") {
14+
throw new Error(
15+
"A apiKey of type string is required to initialize squarelink module"
16+
)
17+
}
18+
19+
if (!network || typeof networkId !== "number") {
20+
throw new Error(
21+
"A network of type number is required to initialize squarelink module"
22+
)
23+
}
24+
25+
return {
26+
name: "Squarelink",
27+
iconSrc: sqlkIcon,
28+
wallet: ({ BigNumber }) => {
29+
const sqlk = new Squarelink(apiKey, networkName(networkId), { useSync: true })
30+
const provider = sqlk.getProviderSync()
31+
32+
return {
33+
provider,
34+
interface: {
35+
name: "Squarelink",
36+
connect: provider.enable,
37+
address: {
38+
get: () => Promise.resolve(provider.accounts[0])
39+
},
40+
network: {
41+
get: () => Promise.resolve(networkId)
42+
},
43+
balance: {
44+
get: () =>
45+
new Promise(resolve => {
46+
if (!provider.accounts.length) {
47+
resolve(null)
48+
return
49+
}
50+
51+
provider.sendAsync(
52+
{
53+
method: "eth_getBalance",
54+
params: [
55+
provider.accounts[0],
56+
"latest"
57+
],
58+
id: 1
59+
},
60+
(e, res) => {
61+
resolve(BigNumber(res.result).toString(10))
62+
}
63+
)
64+
})
65+
}
66+
}
67+
}
68+
}
69+
}
70+
}
71+
72+
export default squarelink

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

yarn.lock

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,7 +2320,7 @@ esutils@^2.0.2:
23202320
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
23212321
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==
23222322

2323-
eth-block-tracker@^4.2.0:
2323+
eth-block-tracker@^4.2.0, eth-block-tracker@^4.4.1:
23242324
version "4.4.3"
23252325
resolved "https://registry.yarnpkg.com/eth-block-tracker/-/eth-block-tracker-4.4.3.tgz#766a0a0eb4a52c867a28328e9ae21353812cf626"
23262326
integrity sha512-A8tG4Z4iNg4mw5tP1Vung9N9IjgMNqpiMoJ/FouSFwNCGHv2X0mmOYwtQOJzki6XN7r7Tyo01S29p7b224I4jw==
@@ -2380,6 +2380,26 @@ eth-json-rpc-middleware@^1.5.0:
23802380
promise-to-callback "^1.0.0"
23812381
tape "^4.6.3"
23822382

2383+
eth-json-rpc-middleware@^4.1.1:
2384+
version "4.3.0"
2385+
resolved "https://registry.yarnpkg.com/eth-json-rpc-middleware/-/eth-json-rpc-middleware-4.3.0.tgz#d3e72efb60b6f601f022ce01384481eaed552b6b"
2386+
integrity sha512-Acr+FaIHB0oIV0nWrCvepQghgA3FzYFvnMDXdTUeHQvAX/G6ioMbw1exGJs+6HirRjJ+MmkZqaArphx+PTrRNQ==
2387+
dependencies:
2388+
btoa "^1.2.1"
2389+
clone "^2.1.1"
2390+
eth-json-rpc-errors "^1.0.1"
2391+
eth-query "^2.1.2"
2392+
eth-sig-util "^1.4.2"
2393+
ethereumjs-block "^1.6.0"
2394+
ethereumjs-tx "^1.3.7"
2395+
ethereumjs-util "^5.1.2"
2396+
ethereumjs-vm "^2.6.0"
2397+
fetch-ponyfill "^4.0.0"
2398+
json-rpc-engine "^5.1.3"
2399+
json-stable-stringify "^1.0.1"
2400+
pify "^3.0.0"
2401+
safe-event-emitter "^1.0.1"
2402+
23832403
eth-json-rpc-middleware@^4.1.4:
23842404
version "4.2.0"
23852405
resolved "https://registry.yarnpkg.com/eth-json-rpc-middleware/-/eth-json-rpc-middleware-4.2.0.tgz#cfb77c5056cb8001548c6c7d54f4af5fce04d489"
@@ -4846,6 +4866,42 @@ split-string@^3.0.1, split-string@^3.0.2:
48464866
dependencies:
48474867
extend-shallow "^3.0.0"
48484868

4869+
squarelink-provider-engine@^15.0.5:
4870+
version "15.0.5"
4871+
resolved "https://registry.yarnpkg.com/squarelink-provider-engine/-/squarelink-provider-engine-15.0.5.tgz#93a440c5daec517b1b494424d1c279f195cd781c"
4872+
integrity sha512-rl9586BLpN/ldujibbMsCfq+lEyY/YMkmWqYcbmKs6VUvB56fsIG23HvVFl1mPRUu7XIq4dOt+V+4G6+GcKTtQ==
4873+
dependencies:
4874+
async "^2.5.0"
4875+
backoff "^2.5.0"
4876+
clone "^2.0.0"
4877+
cross-fetch "^2.1.0"
4878+
eth-block-tracker "^4.4.1"
4879+
eth-json-rpc-filters "^4.0.2"
4880+
eth-json-rpc-infura "^3.1.0"
4881+
eth-json-rpc-middleware "^4.1.1"
4882+
eth-sig-util "^1.4.2"
4883+
ethereumjs-block "^1.2.2"
4884+
ethereumjs-tx "^1.2.0"
4885+
ethereumjs-util "^5.1.5"
4886+
ethereumjs-vm "^2.3.4"
4887+
json-rpc-error "^2.0.0"
4888+
json-stable-stringify "^1.0.1"
4889+
promise-to-callback "^1.0.0"
4890+
readable-stream "^2.2.9"
4891+
request "^2.85.0"
4892+
semaphore "^1.0.3"
4893+
ws "^5.1.1"
4894+
xhr "^2.2.0"
4895+
xtend "^4.0.1"
4896+
4897+
squarelink@^1.1.3:
4898+
version "1.1.3"
4899+
resolved "https://registry.yarnpkg.com/squarelink/-/squarelink-1.1.3.tgz#e799fabb3055916a1e06567c0efc804945671ff2"
4900+
integrity sha512-DHYE2epLW59ylejSVdaqwKyE0TO7nqPeHiVwemOYLjFRrkMYXRMK7xh8CjsBJIXqyf5JmpnNNLinLAikKv0X4g==
4901+
dependencies:
4902+
bignumber.js "^9.0.0"
4903+
squarelink-provider-engine "^15.0.5"
4904+
48494905
sshpk@^1.7.0:
48504906
version "1.16.1"
48514907
resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.16.1.tgz#fb661c0bef29b39db40769ee39fa70093d6f6877"
@@ -5244,7 +5300,7 @@ vlq@^0.2.2:
52445300
eth-block-tracker "^4.2.0"
52455301
eth-json-rpc-filters "^4.0.2"
52465302
eth-json-rpc-infura "^3.1.0"
5247-
eth-json-rpc-middleware "github:walletconnect/eth-json-rpc-middleware"
5303+
eth-json-rpc-middleware "^4.1.1"
52485304
eth-sig-util "^1.4.2"
52495305
ethereumjs-block "^1.2.2"
52505306
ethereumjs-tx "^1.2.0"

0 commit comments

Comments
 (0)