summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/withdraw.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/operations/withdraw.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/withdraw.ts80
1 files changed, 35 insertions, 45 deletions
diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts
index 8a718dd49..3dffab7d6 100644
--- a/packages/taler-wallet-core/src/operations/withdraw.ts
+++ b/packages/taler-wallet-core/src/operations/withdraw.ts
@@ -136,6 +136,7 @@ import {
getExchangeDetails,
getExchangePaytoUri,
fetchFreshExchange,
+ ReadyExchangeSummary,
} from "./exchanges.js";
import {
TransitionInfo,
@@ -616,9 +617,10 @@ export async function getCandidateWithdrawalDenoms(
return await ws.db
.mktx((x) => [x.denominations])
.runReadOnly(async (tx) => {
- const allDenoms = await tx.denominations.indexes.byExchangeBaseUrl.getAll(
- exchangeBaseUrl,
- );
+ const allDenoms =
+ await tx.denominations.indexes.byExchangeBaseUrl.getAll(
+ exchangeBaseUrl,
+ );
return allDenoms.filter((d) =>
isWithdrawableDenom(d, ws.config.testing.denomselAllowLate),
);
@@ -870,10 +872,10 @@ async function handleKycRequired(
amlStatus === AmlStatus.normal || amlStatus === undefined
? WithdrawalGroupStatus.PendingKyc
: amlStatus === AmlStatus.pending
- ? WithdrawalGroupStatus.PendingAml
- : amlStatus === AmlStatus.fronzen
- ? WithdrawalGroupStatus.SuspendedAml
- : assertUnreachable(amlStatus);
+ ? WithdrawalGroupStatus.PendingAml
+ : amlStatus === AmlStatus.fronzen
+ ? WithdrawalGroupStatus.SuspendedAml
+ : assertUnreachable(amlStatus);
notificationKycUrl = kycUrl;
@@ -1508,10 +1510,7 @@ async function processWithdrawalGroupPendingReady(
withdrawalGroupId,
});
- await ws.exchangeOps.updateExchangeFromUrl(
- ws,
- withdrawalGroup.exchangeBaseUrl,
- );
+ await ws.exchangeOps.fetchFreshExchange(ws, withdrawalGroup.exchangeBaseUrl);
if (withdrawalGroup.denomsSel.selectedDenoms.length === 0) {
logger.warn("Finishing empty withdrawal group (no denoms)");
@@ -1549,9 +1548,8 @@ async function processWithdrawalGroupPendingReady(
await ws.db
.mktx((x) => [x.planchets])
.runReadOnly(async (tx) => {
- const planchets = await tx.planchets.indexes.byGroup.getAll(
- withdrawalGroupId,
- );
+ const planchets =
+ await tx.planchets.indexes.byGroup.getAll(withdrawalGroupId);
for (const p of planchets) {
if (p.planchetStatus === PlanchetStatus.WithdrawalDone) {
wgContext.planchetsFinished.add(p.coinPub);
@@ -1759,19 +1757,18 @@ export async function getExchangeWithdrawalInfo(
ageRestricted: number | undefined,
): Promise<ExchangeWithdrawalDetails> {
logger.trace("updating exchange");
- const { exchange, exchangeDetails } =
- await ws.exchangeOps.updateExchangeFromUrl(ws, exchangeBaseUrl);
+ const exchange = await ws.exchangeOps.fetchFreshExchange(ws, exchangeBaseUrl);
- if (exchangeDetails.currency != instructedAmount.currency) {
+ if (exchange.currency != instructedAmount.currency) {
// Specifiying the amount in the conversion input currency is not yet supported.
// We might add support for it later.
throw new Error(
- `withdrawal only supported when specifying target currency ${exchangeDetails.currency}`,
+ `withdrawal only supported when specifying target currency ${exchange.currency}`,
);
}
const withdrawalAccountsList = await fetchWithdrawalAccountInfo(ws, {
- exchangeDetails,
+ exchange,
instructedAmount,
});
@@ -1799,7 +1796,7 @@ export async function getExchangeWithdrawalInfo(
const exchangeWireAccounts: string[] = [];
- for (const account of exchangeDetails.wireInfo.accounts) {
+ for (const account of exchange.wireInfo.accounts) {
exchangeWireAccounts.push(account.payto_uri);
}
@@ -1839,17 +1836,18 @@ export async function getExchangeWithdrawalInfo(
const possibleDenoms = await ws.db
.mktx((x) => [x.denominations])
.runReadOnly(async (tx) => {
- const ds = await tx.denominations.indexes.byExchangeBaseUrl.getAll(
- exchangeBaseUrl,
- );
+ const ds =
+ await tx.denominations.indexes.byExchangeBaseUrl.getAll(
+ exchangeBaseUrl,
+ );
return ds.filter((x) => x.isOffered);
});
let versionMatch;
- if (exchangeDetails.protocolVersionRange) {
+ if (exchange.protocolVersionRange) {
versionMatch = LibtoolVersion.compare(
WALLET_EXCHANGE_PROTOCOL_VERSION,
- exchangeDetails.protocolVersionRange,
+ exchange.protocolVersionRange,
);
if (
@@ -1859,7 +1857,7 @@ export async function getExchangeWithdrawalInfo(
) {
logger.warn(
`wallet's support for exchange protocol version ${WALLET_EXCHANGE_PROTOCOL_VERSION} might be outdated ` +
- `(exchange has ${exchangeDetails.protocolVersionRange}), checking for updates`,
+ `(exchange has ${exchange.protocolVersionRange}), checking for updates`,
);
}
}
@@ -1871,7 +1869,7 @@ export async function getExchangeWithdrawalInfo(
}
}
- const paytoUris = exchangeDetails.wireInfo.accounts.map((x) => x.payto_uri);
+ const paytoUris = exchange.wireInfo.accounts.map((x) => x.payto_uri);
if (!paytoUris) {
throw Error("exchange is in invalid state");
}
@@ -1881,7 +1879,7 @@ export async function getExchangeWithdrawalInfo(
exchangePaytoUris: paytoUris,
exchangeWireAccounts,
exchangeCreditAccountDetails: withdrawalAccountsList,
- exchangeVersion: exchangeDetails.protocolVersionRange || "unknown",
+ exchangeVersion: exchange.protocolVersionRange || "unknown",
numOfferedDenoms: possibleDenoms.length,
selectedDenoms,
// FIXME: delete this field / replace by something we can display to the user
@@ -1923,7 +1921,7 @@ export async function getWithdrawalDetailsForUri(
// FIXME: right now the exchange gets permanently added,
// we might want to only temporarily add it.
try {
- await ws.exchangeOps.updateExchangeFromUrl(ws, info.suggestedExchange);
+ await ws.exchangeOps.fetchFreshExchange(ws, info.suggestedExchange);
} catch (e) {
// We still continued if it failed, as other exchanges might be available.
// We don't want to fail if the bank-suggested exchange is broken/offline.
@@ -2289,7 +2287,6 @@ export interface PrepareCreateWithdrawalGroupResult {
creationInfo?: {
amount: AmountJson;
canonExchange: string;
- exchangeDetails: ExchangeDetailsRecord;
};
}
@@ -2376,7 +2373,6 @@ export async function internalPrepareCreateWithdrawalGroup(
};
const exchangeInfo = await fetchFreshExchange(ws, canonExchange);
- const exchangeDetails = exchangeInfo.exchangeDetails;
const transactionId = constructTransactionIdentifier({
tag: TransactionType.Withdrawal,
withdrawalGroupId: withdrawalGroup.withdrawalGroupId,
@@ -2388,7 +2384,6 @@ export async function internalPrepareCreateWithdrawalGroup(
creationInfo: {
canonExchange,
amount,
- exchangeDetails,
},
};
}
@@ -2411,8 +2406,6 @@ export async function internalPerformCreateWithdrawalGroup(
if (!prep.creationInfo) {
return { withdrawalGroup, transitionInfo: undefined };
}
- const { amount, canonExchange, exchangeDetails } = prep.creationInfo;
-
await tx.withdrawalGroups.add(withdrawalGroup);
await tx.reserves.put({
reservePub: withdrawalGroup.reservePub,
@@ -2529,13 +2522,13 @@ export async function acceptWithdrawalFromUri(
withdrawInfo.wireTypes,
);
- const { exchangeDetails } = await ws.exchangeOps.updateExchangeFromUrl(
+ const exchange = await ws.exchangeOps.fetchFreshExchange(
ws,
selectedExchange,
);
const withdrawalAccountList = await fetchWithdrawalAccountInfo(ws, {
- exchangeDetails,
+ exchange,
instructedAmount: withdrawInfo.amount,
});
@@ -2666,14 +2659,14 @@ async function fetchAccount(
async function fetchWithdrawalAccountInfo(
ws: InternalWalletState,
req: {
- exchangeDetails: ExchangeDetailsRecord;
+ exchange: ReadyExchangeSummary;
instructedAmount: AmountJson;
reservePub?: string;
},
): Promise<WithdrawalExchangeAccountDetails[]> {
- const { exchangeDetails, instructedAmount } = req;
+ const { exchange, instructedAmount } = req;
const withdrawalAccounts: WithdrawalExchangeAccountDetails[] = [];
- for (let acct of exchangeDetails.wireInfo.accounts) {
+ for (let acct of exchange.wireInfo.accounts) {
const acctInfo = await fetchAccount(
ws,
req.instructedAmount,
@@ -2704,12 +2697,9 @@ export async function createManualWithdrawal(
): Promise<AcceptManualWithdrawalResult> {
const { exchangeBaseUrl } = req;
const amount = Amounts.parseOrThrow(req.amount);
- const { exchangeDetails } = await ws.exchangeOps.updateExchangeFromUrl(
- ws,
- exchangeBaseUrl,
- );
+ const exchange = await ws.exchangeOps.fetchFreshExchange(ws, exchangeBaseUrl);
- if (exchangeDetails.currency != amount.currency) {
+ if (exchange.currency != amount.currency) {
throw Error(
"manual withdrawal with conversion from foreign currency is not yet supported",
);
@@ -2719,7 +2709,7 @@ export async function createManualWithdrawal(
);
const withdrawalAccountsList = await fetchWithdrawalAccountInfo(ws, {
- exchangeDetails,
+ exchange,
instructedAmount: amount,
reservePub: reserveKeyPair.pub,
});