-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #470 from EdgeApp/william/no-json-schema
Replace all JSON Schema uses with Cleaners
- Loading branch information
Showing
9 changed files
with
100 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,50 @@ | ||
export const EtherscanGetBlockHeight = { | ||
type: 'object', | ||
properties: { | ||
result: { type: 'string' } | ||
}, | ||
required: ['result'] | ||
} | ||
import { add } from 'biggystring' | ||
import { | ||
asArray, | ||
asNumber, | ||
asObject, | ||
asString, | ||
asUnknown, | ||
Cleaner | ||
} from 'cleaners' | ||
|
||
export const EtherscanGetAccountNonce = { | ||
type: 'object', | ||
properties: { | ||
result: { type: 'string' } | ||
}, | ||
required: ['result'] | ||
const asHexNumber: Cleaner<number> = raw => { | ||
const clean = asString(raw) | ||
if (/0[xX][0-9a-fA-F]+/.test(clean)) return parseInt(clean, 16) | ||
throw new TypeError('Expected a hex number') | ||
} | ||
|
||
export const EthGasStationSchema = { | ||
type: 'object', | ||
properties: { | ||
safeLow: { type: 'number' }, | ||
average: { type: 'number' }, | ||
standard: { type: 'number' }, | ||
fastest: { type: 'number' } | ||
}, | ||
required: ['safeLow', 'fastest'] | ||
const asHexString: Cleaner<string> = raw => { | ||
const clean = asString(raw) | ||
if (/0[xX][0-9a-fA-F]+/.test(clean)) return add(raw, '0') | ||
throw new TypeError('Expected a hex number') | ||
} | ||
|
||
export const EIP712TypedDataSchema = { | ||
type: 'object', | ||
properties: { | ||
types: { | ||
type: 'object', | ||
properties: { | ||
EIP712Domain: { type: 'array' } | ||
}, | ||
additionalProperties: { | ||
type: 'array', | ||
items: { | ||
type: 'object', | ||
properties: { | ||
name: { type: 'string' }, | ||
type: { type: 'string' } | ||
}, | ||
required: ['name', 'type'] | ||
} | ||
}, | ||
required: ['EIP712Domain'] | ||
}, | ||
primaryType: { type: 'string' }, | ||
domain: { type: 'object' }, | ||
message: { type: 'object' } | ||
}, | ||
required: ['types', 'primaryType', 'domain', 'message'] | ||
} | ||
export const asEtherscanGetBlockHeight = asObject({ | ||
result: asHexNumber | ||
}) | ||
|
||
export const asEtherscanGetAccountNonce = asObject({ | ||
result: asHexString | ||
}) | ||
|
||
export const asEthGasStation = asObject({ | ||
safeLow: asNumber, | ||
average: asNumber, | ||
fast: asNumber, | ||
fastest: asNumber | ||
}) | ||
|
||
export const asEIP712TypedData = asObject({ | ||
types: asObject( | ||
asArray( | ||
asObject({ | ||
name: asString, | ||
type: asString | ||
}) | ||
) | ||
), | ||
primaryType: asString, | ||
domain: asUnknown, | ||
message: asUnknown | ||
}) |
Oops, something went wrong.