Skip to content

Commit 5df92fd

Browse files
committed
Implement new validation
1 parent 07d6769 commit 5df92fd

File tree

4 files changed

+230
-188
lines changed

4 files changed

+230
-188
lines changed

src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ import {
1717

1818
import { isMobileDevice } from "./utilities"
1919
import { initializeBlocknative } from "./services"
20+
import { validateInit, validateConfig } from "./validation"
2021

2122
import { version } from "../package.json"
2223

2324
function init(initialization) {
24-
// validateInit(initialization)
25+
validateInit(initialization)
2526

2627
const { subscriptions, dappId, networkId, modules } = initialization
2728

@@ -106,7 +107,7 @@ function init(initialization) {
106107
}
107108

108109
function config(options) {
109-
// validateConfig(options)
110+
validateConfig(options)
110111
app.update(store => ({ ...store, ...options }))
111112
}
112113

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/stores.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { writable, derived } from "svelte/store"
22
import Cancelable from "promise-cancelable"
33
import { getBlocknative } from "./services"
44
import { wait, makeQuerablePromise } from "./utilities"
5+
import { validateWalletInterface, validateType } from "./validation"
56

67
export const app = writable({
78
dappId: null,
@@ -74,7 +75,7 @@ function createWalletInterfaceStore(initialState) {
7475
subscribe,
7576
update,
7677
set: walletInterface => {
77-
// validateWalletInterface(walletInterface)
78+
validateWalletInterface(walletInterface)
7879
set(walletInterface)
7980
}
8081
}
@@ -87,9 +88,7 @@ function createUserStateStore(parameter) {
8788
subscribe,
8889
reset: () => set(null),
8990
setStateSyncer: stateSyncer => {
90-
if (!stateSyncer || typeof stateSyncer !== "object") {
91-
throw new Error("setStateSyncer must be called with a valid interface")
92-
}
91+
validateType({ name: "stateSyncer", value: stateSyncer, type: "object" })
9392

9493
if (stateSyncer.onChange) {
9594
stateSyncer.onChange(set)
@@ -139,9 +138,7 @@ function createBalanceStore() {
139138
return {
140139
subscribe,
141140
setStateSyncer: syncer => {
142-
if (!syncer || typeof syncer !== "object") {
143-
throw new Error("setStateSyncer must be called with a valid interface")
144-
}
141+
validateType({ name: "syncer", value: syncer, type: "object" })
145142

146143
stateSyncer = syncer
147144
}

0 commit comments

Comments
 (0)