Skip to content

Commit

Permalink
Deal with Coingecko price validator's loose JDT typing
Browse files Browse the repository at this point in the history
We ended up with some implicit anys and unexpected unknowns due to the
JDT schema's inability to type a few properties. With noImplicitAny,
this triggers actual errors, and we adjust for those here.
  • Loading branch information
Shadowfiend committed Oct 13, 2021
1 parent 293ce0a commit 81df7e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions background/lib/prices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export async function getPrice(
return null
}

return json ? parseFloat(json[coingeckoCoinId][currencySymbol]) : null
return json
? parseFloat(
json[coingeckoCoinId][currencySymbol] as string // FIXME Drop as when strict mode arrives and price schema type can include this.
)
: null
}

function multiplyByFloat(n: bigint, f: number, precision: number) {
Expand Down Expand Up @@ -78,7 +82,7 @@ export async function getPrices(
amounts: [
multiplyByFloat(
BigInt(10) ** BigInt(c.decimals),
parseFloat(simpleCoinPrices[symbol]),
parseFloat(simpleCoinPrices[symbol] as string), // FIXME Drop as when strict mode arrives and price schema type can include this.
8
),
BigInt(1),
Expand Down
2 changes: 1 addition & 1 deletion background/lib/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const coingeckoPriceSchema = {
},
additionalProperties: true,
},
}
} as const

type CoinGeckoPriceDataJtd = JTDDataType<typeof coingeckoPriceSchema>

Expand Down

0 comments on commit 81df7e0

Please sign in to comment.