Skip to content

Commit

Permalink
Prevent crash if asset mentioned in /info response is unknown (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
andywer authored Mar 31, 2020
1 parent 62e64f1 commit 4020ff3
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,21 @@ export async function fetchTransferInfos(
assetCode => assetCode !== "transactions"
)

const assetInfos = assetCodes.map<AssetTransferInfo>(assetCode => ({
asset:
transferServer.assets.find(asset => asset.code === assetCode) ||
fail(`${transferServer.domain} does not issue asset ${assetCode}.`),
deposit: response.data.deposit[assetCode],
endpoints: response.data,
transferServer,
withdraw: response.data.withdraw[assetCode]
}))
const assetInfos = assetCodes
// Filter out assets that the transfer server lists, but are not in
// the stellar.toml. Prevent crashes on partially inconsistent data.
.filter(assetCode =>
transferServer.assets.some(asset => asset.code === assetCode)
)
.map<AssetTransferInfo>(assetCode => ({
asset:
transferServer.assets.find(asset => asset.code === assetCode) ||
fail(`${transferServer.domain} does not issue asset ${assetCode}.`),
deposit: response.data.deposit[assetCode],
endpoints: response.data,
transferServer,
withdraw: response.data.withdraw[assetCode]
}))

return {
assets: assetInfos,
Expand Down

0 comments on commit 4020ff3

Please sign in to comment.