Skip to content

Commit ccd91d8

Browse files
authored
Merge pull request #24 from blocknative/feature/remove-ow-dependency
Remove `ow` dependency
2 parents e230f47 + ad18889 commit ccd91d8

File tree

9 files changed

+482
-326
lines changed

9 files changed

+482
-326
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"bnc-sdk": "0.1.1",
3333
"bowser": "^2.5.2",
3434
"fortmatic": "^0.8.2",
35-
"ow": "^0.13.2",
3635
"promise-cancelable": "^2.1.1",
3736
"regenerator-runtime": "^0.13.3",
3837
"squarelink": "^1.1.3",

rollup.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export default [
3939
external: [
4040
"bowser",
4141
"bnc-sdk",
42-
"ow",
4342
"bignumber.js",
4443
"svelte-i18n",
4544
"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/wallets/fortmatic.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
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",

src/modules/select/wallets/portis.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
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",

src/stores.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { writable, derived } from "svelte/store"
22
import Cancelable from "promise-cancelable"
3-
import { validateWalletInterface } from "./validation"
43
import { getBlocknative } from "./services"
54
import { wait, makeQuerablePromise } from "./utilities"
5+
import { validateWalletInterface, validateType } from "./validation"
66

77
export const app = writable({
88
dappId: null,
@@ -88,9 +88,7 @@ function createUserStateStore(parameter) {
8888
subscribe,
8989
reset: () => set(null),
9090
setStateSyncer: stateSyncer => {
91-
if (!stateSyncer || typeof stateSyncer !== "object") {
92-
throw new Error("setStateSyncer must be called with a valid interface")
93-
}
91+
validateType({ name: "stateSyncer", value: stateSyncer, type: "object" })
9492

9593
if (stateSyncer.onChange) {
9694
stateSyncer.onChange(set)
@@ -140,9 +138,7 @@ function createBalanceStore() {
140138
return {
141139
subscribe,
142140
setStateSyncer: syncer => {
143-
if (!syncer || typeof syncer !== "object") {
144-
throw new Error("setStateSyncer must be called with a valid interface")
145-
}
141+
validateType({ name: "syncer", value: syncer, type: "object" })
146142

147143
stateSyncer = syncer
148144
}

0 commit comments

Comments
 (0)