Skip to content

Commit 7b2ebe3

Browse files
authored
Merge pull request #18 from blocknative/fix/wallet-network
Fix wallet module initialization network. closes #17
2 parents 1f50104 + 0d693cd commit 7b2ebe3

File tree

5 files changed

+25
-23
lines changed

5 files changed

+25
-23
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ modules.select.defaults({
203203
```javascript
204204
portis({
205205
apiKey: String, // your Portis api key
206-
network: String // the name of network you want to connect to
206+
networkId: Number // the networkId of network you want to connect to
207207
})
208208
```
209209

@@ -212,14 +212,14 @@ portis({
212212
```javascript
213213
fortmatic({
214214
apiKey: String, // your Portis api key
215-
network: String // the name of the network you want to connect to
215+
networkId: Number // the networkId of the network you want to connect to
216216
})
217217
```
218218

219219
`walletConnect` Initialization:
220220

221221
```javascript
222-
fortmatic({
222+
walletConnect({
223223
infuraKey: String
224224
})
225225
```
@@ -242,11 +242,11 @@ const onboard = Onboard.init({
242242
"Please select the wallet that you would like to use with this Dapp",
243243
wallets: {
244244
desktop: [
245-
portis({ apiKey: 'sdda-w2-ds3', network: 'main' })
245+
portis({ apiKey: 'sdda-w2-ds3', networkId: 1 })
246246
dapper(),
247247
metmask(),
248248
],
249-
mobile: [fortmatic({apiKey: 'sd-3d3-d', network: 'main'})]
249+
mobile: [fortmatic({apiKey: 'sd-3d3-d', networkId: 1})]
250250
}
251251
}
252252
//....

src/modules/select/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ 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"
98

109
function defaults({
1110
heading,
@@ -17,16 +16,15 @@ function defaults({
1716
}) {
1817
const desktopModules = [metamask(), dapper()]
1918
const mobileModules = [coinbase(), trust()]
20-
const network = networkName(networkId)
2119

2220
if (portisInit) {
23-
desktopModules.push(portis({ ...portisInit, network }))
24-
mobileModules.push(portis({ ...portisInit, network }))
21+
desktopModules.push(portis({ ...portisInit, networkId }))
22+
mobileModules.push(portis({ ...portisInit, networkId }))
2523
}
2624

2725
if (fortmaticInit) {
28-
desktopModules.push(fortmatic({ ...fortmaticInit, network }))
29-
mobileModules.push(fortmatic({ ...fortmaticInit, network }))
26+
desktopModules.push(fortmatic({ ...fortmaticInit, networkId }))
27+
mobileModules.push(fortmatic({ ...fortmaticInit, networkId }))
3028
}
3129

3230
if (walletConnectInit) {

src/modules/select/wallets/fortmatic.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Fortmatic from "fortmatic"
2-
import { networkToId } from "../../../utilities"
32
import fortmaticIcon from "../wallet-icons/icon-fortmatic.svg"
3+
import { networkName } from "../../../utilities"
44

55
function fortmatic(options) {
66
if (!options || typeof options !== "object") {
@@ -9,25 +9,28 @@ function fortmatic(options) {
99
)
1010
}
1111

12-
const { apiKey, network } = options
12+
const { apiKey, networkId } = options
1313

1414
if (!apiKey || typeof apiKey !== "string") {
1515
throw new Error(
1616
"A apiKey of type string is required to initialize fortmatic module"
1717
)
1818
}
1919

20-
if (!network || typeof network !== "string") {
20+
if (!networkId || typeof networkId !== "number") {
2121
throw new Error(
22-
"A network of type string is required to initialize fortmatic module"
22+
"A networkId of type number is required to initialize fortmatic module"
2323
)
2424
}
2525

2626
return {
2727
name: "Fortmatic",
2828
iconSrc: fortmaticIcon,
2929
wallet: ({ BigNumber }) => {
30-
const fortmatic = new Fortmatic(apiKey, network)
30+
const fortmatic = new Fortmatic(
31+
apiKey,
32+
networkId === 1 ? undefined : networkName(networkId)
33+
)
3134
const provider = fortmatic.getProvider()
3235

3336
return {
@@ -39,7 +42,7 @@ function fortmatic(options) {
3942
get: () => Promise.resolve(provider.account)
4043
},
4144
network: {
42-
get: () => Promise.resolve(networkToId(network))
45+
get: () => Promise.resolve(networkId)
4346
},
4447
balance: {
4548
get: () =>

src/modules/select/wallets/portis.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
import Portis from "@portis/web3"
22

3+
import { networkName } from "../../../utilities"
34
import portisIcon from "../wallet-icons/icon-portis.svg"
45

56
function portis(options) {
67
if (!options || typeof options !== "object") {
78
throw new Error("An options object is required to initialize portis module")
89
}
910

10-
const { apiKey, network } = options
11+
const { apiKey, networkId } = options
1112

1213
if (!apiKey || typeof apiKey !== "string") {
1314
throw new Error(
1415
"A apiKey of type string is required to initialize portis module"
1516
)
1617
}
1718

18-
if (!network || typeof network !== "string") {
19+
if (!networkId || typeof networkId !== "number") {
1920
throw new Error(
20-
"A network of type string is required to initialize portis module"
21+
"A network of type number is required to initialize portis module"
2122
)
2223
}
2324

2425
return {
2526
name: "Portis",
2627
iconSrc: portisIcon,
2728
wallet: ({ BigNumber }) => {
28-
const portis = new Portis(apiKey, network)
29+
const portis = new Portis(apiKey, networkName(networkId))
2930
const { provider } = portis
3031

3132
return {

src/utilities.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export function isMobileDevice() {
140140
export function networkName(id) {
141141
switch (id) {
142142
case 1:
143-
return "main"
143+
return "mainnet"
144144
case 3:
145145
return "ropsten"
146146
case 4:
@@ -158,7 +158,7 @@ export function networkName(id) {
158158

159159
export function networkToId(network) {
160160
switch (network) {
161-
case "main":
161+
case "mainnet":
162162
return 1
163163
case "ropsten":
164164
return 3

0 commit comments

Comments
 (0)