diff options
Diffstat (limited to 'packages/taler-wallet-core/src/operations/common.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/common.ts | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/packages/taler-wallet-core/src/operations/common.ts b/packages/taler-wallet-core/src/operations/common.ts index ee7a1b46e..95441be2b 100644 --- a/packages/taler-wallet-core/src/operations/common.ts +++ b/packages/taler-wallet-core/src/operations/common.ts @@ -22,6 +22,8 @@ import { Amounts, CoinRefreshRequest, CoinStatus, + ExchangeEntryStatus, + ExchangeListItem, ExchangeTosStatus, j2s, Logger, @@ -32,7 +34,12 @@ import { TransactionIdStr, TransactionType, } from "@gnu-taler/taler-util"; -import { WalletStoresV1, CoinRecord, ExchangeDetailsRecord } from "../db.js"; +import { + WalletStoresV1, + CoinRecord, + ExchangeDetailsRecord, + ExchangeRecord, +} from "../db.js"; import { makeErrorDetail, TalerError } from "../errors.js"; import { InternalWalletState } from "../internal-wallet-state.js"; import { checkDbInvariant, checkLogicInvariant } from "../util/invariants.js"; @@ -320,3 +327,29 @@ export function getExchangeTosStatus( } return ExchangeTosStatus.Changed; } + +export function makeExchangeListItem( + r: ExchangeRecord, + exchangeDetails: ExchangeDetailsRecord | undefined, +): ExchangeListItem { + if (!exchangeDetails) { + return { + exchangeBaseUrl: r.baseUrl, + currency: undefined, + tosStatus: ExchangeTosStatus.Unknown, + paytoUris: [], + exchangeStatus: ExchangeEntryStatus.Unknown, + permanent: r.permanent, + }; + } + let exchangeStatus; + exchangeStatus = ExchangeEntryStatus.Ok; + return { + exchangeBaseUrl: r.baseUrl, + currency: exchangeDetails.currency, + tosStatus: getExchangeTosStatus(exchangeDetails), + paytoUris: exchangeDetails.wireInfo.accounts.map((x) => x.payto_uri), + exchangeStatus, + permanent: r.permanent, + }; +} |