Skip to content

Commit

Permalink
Merge pull request #48 from EdgeApp/matthew/cleaner-custom-tokens
Browse files Browse the repository at this point in the history
Add customTokens to cleaners
  • Loading branch information
peachbits authored Oct 3, 2024
2 parents 92f758e + 42c7537 commit 72cfc7f
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/indexApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
asObject,
asOptional,
asString,
asUnknown
asUnknown,
Cleaner
} from 'cleaners'
import cluster from 'cluster'
import cookieParser from 'cookie-parser'
Expand All @@ -23,6 +24,27 @@ import { checkForKeys } from './util'

const FIVE_MINUTES = 1000 * 60 * 5

/**
* Cleaners ported from edge-core-js
*/
const asJsonObject: Cleaner<object> = raw => {
if (raw == null || typeof raw !== 'object') {
throw new TypeError('Expected a JSON object')
}
return raw
}
const asEdgeDenomination = asObject({
multiplier: asString,
name: asString,
symbol: asOptional(asString)
})
const asEdgeToken = asObject({
currencyCode: asString,
denominations: asArray(asEdgeDenomination),
displayName: asString,
networkLocation: asOptional(asJsonObject)
})

const asLog = asObject({
isoDate: asOptional(asString),
uniqueId: asOptional(asString),
Expand All @@ -46,6 +68,7 @@ const asLog = asObject({
wallets: asArray(
asObject({
currencyCode: asString,
customTokens: asOptional(asObject(asEdgeToken)),
imported: asOptional(asBoolean),
repoId: asOptional(asString),
pluginDump: asOptional(asUnknown)
Expand Down Expand Up @@ -89,6 +112,7 @@ const retrievedLogObj = {
wallets: asArray(
asObject({
currencyCode: asString,
customTokens: asOptional(asObject(asEdgeToken)),
imported: asOptional(asBoolean),
repoId: asOptional(asString),
pluginDump: asOptional(asUnknown)
Expand Down

0 comments on commit 72cfc7f

Please sign in to comment.