diff options
author | Florian Dold <florian@dold.me> | 2022-10-14 18:40:04 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-10-14 18:48:03 +0200 |
commit | 6acddd6d70abc568e4b3740f56662691278aa645 (patch) | |
tree | 2733a5669090e54a864ad7c1052ef21fffc5aa06 /packages/taler-wallet-core | |
parent | da9ec5eb16298d8ca5690800eca1c15f5a6cfaa5 (diff) |
wallet-core: get rid of duplicated withdrawal info API
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r-- | packages/taler-wallet-core/src/db.ts | 16 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/backup/import.ts | 2 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/withdraw.ts | 107 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/wallet.ts | 55 |
4 files changed, 29 insertions, 151 deletions
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index f4cdb68c1..8f7f22292 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -47,6 +47,7 @@ import { DenominationInfo, GlobalFees, ExchangeGlobalFees, + DenomSelectionState, } from "@gnu-taler/taler-util"; import { RetryInfo, RetryTags } from "./util/retries.js"; import { Event, IDBDatabase } from "@gnu-taler/idb-bridge"; @@ -430,8 +431,11 @@ export interface ExchangeDetailsRecord { /** * Fees for exchange services + * + * FIXME: Put in separate object store! */ globalFees: ExchangeGlobalFees[]; + /** * Signing keys we got from the exchange, can also contain * older signing keys that are not returned by /keys anymore. @@ -1280,18 +1284,6 @@ export interface WalletBackupConfState { lastBackupNonce?: string; } -/** - * Selected denominations withn some extra info. - */ -export interface DenomSelectionState { - totalCoinValue: AmountJson; - totalWithdrawCost: AmountJson; - selectedDenoms: { - denomPubHash: string; - count: number; - }[]; -} - export const enum WithdrawalRecordType { BankManual = "bank-manual", BankIntegrated = "bank-integrated", diff --git a/packages/taler-wallet-core/src/operations/backup/import.ts b/packages/taler-wallet-core/src/operations/backup/import.ts index e631845f6..f4e6ab5eb 100644 --- a/packages/taler-wallet-core/src/operations/backup/import.ts +++ b/packages/taler-wallet-core/src/operations/backup/import.ts @@ -28,6 +28,7 @@ import { BackupWgType, codecForContractTerms, DenomKeyType, + DenomSelectionState, j2s, Logger, PayCoinSelection, @@ -43,7 +44,6 @@ import { CoinStatus, DenominationRecord, DenominationVerificationStatus, - DenomSelectionState, OperationStatus, ProposalDownload, PurchaseStatus, diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts index 3c2541e9a..e4bf6cd11 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.ts @@ -37,10 +37,12 @@ import { codecForWithdrawOperationStatusResponse, codecForWithdrawResponse, DenomKeyType, + DenomSelectionState, Duration, durationFromSpec, encodeCrock, ExchangeListItem, + ExchangeWithdrawalDetails, ExchangeWithdrawRequest, ForcedDenomSel, getRandomBytes, @@ -67,9 +69,6 @@ import { CoinStatus, DenominationRecord, DenominationVerificationStatus, - DenomSelectionState, - ExchangeDetailsRecord, - ExchangeRecord, PlanchetRecord, WalletStoresV1, WgInfo, @@ -127,96 +126,6 @@ import { const logger = new Logger("operations/withdraw.ts"); /** - * Information about what will happen when creating a reserve. - * - * Sent to the wallet frontend to be rendered and shown to the user. - */ -export interface ExchangeWithdrawDetails { - /** - * Exchange that the reserve will be created at. - * - * FIXME: Should be its own record. - */ - exchangeInfo: ExchangeRecord; - - exchangeDetails: ExchangeDetailsRecord; - - /** - * Filtered wire info to send to the bank. - */ - exchangeWireAccounts: string[]; - - /** - * Selected denominations for withdraw. - */ - selectedDenoms: DenomSelectionState; - - /** - * Does the wallet know about an auditor for - * the exchange that the reserve. - */ - isAudited: boolean; - - /** - * Did the user already accept the current terms of service for the exchange? - */ - termsOfServiceAccepted: boolean; - - /** - * The exchange is trusted directly. - */ - isTrusted: boolean; - - /** - * The earliest deposit expiration of the selected coins. - */ - earliestDepositExpiration: TalerProtocolTimestamp; - - /** - * Number of currently offered denominations. - */ - numOfferedDenoms: number; - - /** - * Public keys of trusted auditors for the currency we're withdrawing. - */ - trustedAuditorPubs: string[]; - - /** - * Result of checking the wallet's version - * against the exchange's version. - * - * Older exchanges don't return version information. - */ - versionMatch: VersionMatchResult | undefined; - - /** - * Libtool-style version string for the exchange or "unknown" - * for older exchanges. - */ - exchangeVersion: string; - - /** - * Libtool-style version string for the wallet. - */ - walletVersion: string; - - withdrawalAmountRaw: AmountString; - - /** - * Amount that will actually be added to the wallet's balance. - */ - withdrawalAmountEffective: AmountString; - - /** - * If the exchange supports age-restricted coins it will return - * the array of ages. - * - */ - ageRestrictionOptions?: number[]; -} - -/** * Check if a denom is withdrawable based on the expiration time, * revocation and offered state. */ @@ -1280,7 +1189,7 @@ export async function getExchangeWithdrawalInfo( exchangeBaseUrl: string, instructedAmount: AmountJson, ageRestricted: number | undefined, -): Promise<ExchangeWithdrawDetails> { +): Promise<ExchangeWithdrawalDetails> { const { exchange, exchangeDetails } = await ws.exchangeOps.updateExchangeFromUrl(ws, exchangeBaseUrl); await updateWithdrawalDenoms(ws, exchangeBaseUrl); @@ -1378,10 +1287,14 @@ export async function getExchangeWithdrawalInfo( } } - const ret: ExchangeWithdrawDetails = { + const paytoUris = exchangeDetails.wireInfo.accounts.map((x) => x.payto_uri); + if (!paytoUris) { + throw Error("exchange is in invalid state"); + } + + const ret: ExchangeWithdrawalDetails = { earliestDepositExpiration, - exchangeInfo: exchange, - exchangeDetails, + exchangePaytoUris: paytoUris, exchangeWireAccounts, exchangeVersion: exchangeDetails.protocolVersion || "unknown", isAudited, diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 254648064..22cbeb4b8 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -47,7 +47,6 @@ import { codecForForgetKnownBankAccounts, codecForGetContractTermsDetails, codecForGetExchangeTosRequest, - codecForGetExchangeWithdrawalInfo, codecForGetFeeForDeposit, codecForGetWithdrawalDetailsForAmountRequest, codecForGetWithdrawalDetailsForUri, @@ -112,7 +111,11 @@ import { importDb, WalletStoresV1, } from "./db.js"; -import { applyDevExperiment, maybeInitDevMode, setDevMode } from "./dev-experiments.js"; +import { + applyDevExperiment, + maybeInitDevMode, + setDevMode, +} from "./dev-experiments.js"; import { getErrorDetailFromException, TalerError } from "./errors.js"; import { ActiveLongpollInfo, @@ -248,32 +251,6 @@ const builtinExchanges: string[] = ["https://exchange.demo.taler.net/"]; const logger = new Logger("wallet.ts"); -async function getWithdrawalDetailsForAmount( - ws: InternalWalletState, - exchangeBaseUrl: string, - amount: AmountJson, - restrictAge: number | undefined, -): Promise<ManualWithdrawalDetails> { - const wi = await getExchangeWithdrawalInfo( - ws, - exchangeBaseUrl, - amount, - restrictAge, - ); - const paytoUris = wi.exchangeDetails.wireInfo.accounts.map( - (x) => x.payto_uri, - ); - if (!paytoUris) { - throw Error("exchange is in invalid state"); - } - return { - amountRaw: Amounts.stringify(amount), - amountEffective: Amounts.stringify(wi.selectedDenoms.totalCoinValue), - paytoUris, - tosAccepted: wi.termsOfServiceAccepted, - }; -} - /** * Call the right handler for a pending operation without doing * any special error handling. @@ -1038,16 +1015,6 @@ async function dispatchRequestInternal( const req = codecForGetWithdrawalDetailsForUri().decode(payload); return await getWithdrawalDetailsForUri(ws, req.talerWithdrawUri); } - - case "getExchangeWithdrawalInfo": { - const req = codecForGetExchangeWithdrawalInfo().decode(payload); - return await getExchangeWithdrawalInfo( - ws, - req.exchangeBaseUrl, - req.amount, - req.ageRestricted, - ); - } case "acceptManualWithdrawal": { const req = codecForAcceptManualWithdrawalRequet().decode(payload); const res = await createManualWithdrawal(ws, { @@ -1060,12 +1027,18 @@ async function dispatchRequestInternal( case "getWithdrawalDetailsForAmount": { const req = codecForGetWithdrawalDetailsForAmountRequest().decode(payload); - return await getWithdrawalDetailsForAmount( + const wi = await getExchangeWithdrawalInfo( ws, req.exchangeBaseUrl, Amounts.parseOrThrow(req.amount), req.restrictAge, ); + return { + amountRaw: req.amount, + amountEffective: Amounts.stringify(wi.selectedDenoms.totalCoinValue), + paytoUris: wi.exchangePaytoUris, + tosAccepted: wi.termsOfServiceAccepted, + }; } case "getBalances": { return await getBalances(ws); @@ -1255,7 +1228,7 @@ async function dispatchRequestInternal( case "withdrawFakebank": { const req = codecForWithdrawFakebankRequest().decode(payload); const amount = Amounts.parseOrThrow(req.amount); - const details = await getWithdrawalDetailsForAmount( + const details = await getExchangeWithdrawalInfo( ws, req.exchange, amount, @@ -1265,7 +1238,7 @@ async function dispatchRequestInternal( amount: amount, exchangeBaseUrl: req.exchange, }); - const paytoUri = details.paytoUris[0]; + const paytoUri = details.exchangePaytoUris[0]; const pt = parsePaytoUri(paytoUri); if (!pt) { throw Error("failed to parse payto URI"); |