wallet-core: emit balance-change notifications, do less implicit background work
This commit is contained in:
parent
97a9e92d8b
commit
35ae9f2c22
@ -2499,6 +2499,8 @@ export interface InitiatePeerPullCreditResponse {
|
||||
/**
|
||||
* Taler URI for the other party to make the payment
|
||||
* that was requested.
|
||||
*
|
||||
* @deprecated since it's not necessarily valid yet until the tx is in the right state
|
||||
*/
|
||||
talerUri: string;
|
||||
|
||||
|
@ -26,7 +26,6 @@ import {
|
||||
codecForDepositSuccess,
|
||||
codecForTackTransactionAccepted,
|
||||
codecForTackTransactionWired,
|
||||
CoinDepositPermission,
|
||||
CoinRefreshRequest,
|
||||
CreateDepositGroupRequest,
|
||||
CreateDepositGroupResponse,
|
||||
|
@ -907,6 +907,8 @@ async function handleInsufficientFunds(
|
||||
refreshReason: RefreshReason.PayMerchant,
|
||||
});
|
||||
});
|
||||
|
||||
ws.notify({ type: NotificationType.BalanceChange });
|
||||
}
|
||||
|
||||
async function unblockBackup(
|
||||
@ -1446,6 +1448,7 @@ export async function confirmPay(
|
||||
});
|
||||
|
||||
notifyTransition(ws, transactionId, transitionInfo);
|
||||
ws.notify({ type: NotificationType.BalanceChange });
|
||||
|
||||
return runPayForConfirmPay(ws, proposalId);
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import {
|
||||
InitiatePeerPullCreditRequest,
|
||||
InitiatePeerPullCreditResponse,
|
||||
Logger,
|
||||
NotificationType,
|
||||
TalerErrorCode,
|
||||
TalerPreciseTimestamp,
|
||||
TalerUriAction,
|
||||
@ -785,24 +786,14 @@ export async function initiatePeerPullPayment(
|
||||
});
|
||||
});
|
||||
|
||||
// FIXME: Should we somehow signal to the client
|
||||
// whether purse creation has failed, or does the client/
|
||||
// check this asynchronously from the transaction status?
|
||||
|
||||
const taskId = constructTaskIdentifier({
|
||||
tag: PendingTaskType.PeerPullCredit,
|
||||
pursePub: pursePair.pub,
|
||||
});
|
||||
|
||||
await runTaskWithErrorReporting(ws, taskId, async () => {
|
||||
return processPeerPullCredit(ws, pursePair.pub);
|
||||
});
|
||||
|
||||
const transactionId = constructTransactionIdentifier({
|
||||
tag: TransactionType.PeerPullCredit,
|
||||
pursePub: pursePair.pub,
|
||||
});
|
||||
|
||||
// The pending-incoming balance has changed.
|
||||
ws.notify({ type: NotificationType.BalanceChange });
|
||||
|
||||
return {
|
||||
talerUri: stringifyTalerUri({
|
||||
type: TalerUriAction.PayPull,
|
||||
|
@ -22,6 +22,7 @@ import {
|
||||
ExchangePurseDeposits,
|
||||
HttpStatusCode,
|
||||
Logger,
|
||||
NotificationType,
|
||||
PeerContractTerms,
|
||||
PreparePeerPullDebitRequest,
|
||||
PreparePeerPullDebitResponse,
|
||||
@ -388,7 +389,6 @@ export async function confirmPeerPullDebit(
|
||||
ws: InternalWalletState,
|
||||
req: ConfirmPeerPullDebitRequest,
|
||||
): Promise<AcceptPeerPullPaymentResponse> {
|
||||
|
||||
let peerPullPaymentIncomingId: string;
|
||||
|
||||
if (req.transactionId) {
|
||||
@ -400,7 +400,9 @@ export async function confirmPeerPullDebit(
|
||||
} else if (req.peerPullPaymentIncomingId) {
|
||||
peerPullPaymentIncomingId = req.peerPullPaymentIncomingId;
|
||||
} else {
|
||||
throw Error("invalid request, transactionId or peerPullPaymentIncomingId required");
|
||||
throw Error(
|
||||
"invalid request, transactionId or peerPullPaymentIncomingId required",
|
||||
);
|
||||
}
|
||||
|
||||
const peerPullInc = await ws.db
|
||||
@ -479,13 +481,7 @@ export async function confirmPeerPullDebit(
|
||||
return pi;
|
||||
});
|
||||
|
||||
await runTaskWithErrorReporting(
|
||||
ws,
|
||||
TaskIdentifiers.forPeerPullPaymentDebit(ppi),
|
||||
async () => {
|
||||
return processPeerPullDebit(ws, ppi.peerPullPaymentIncomingId);
|
||||
},
|
||||
);
|
||||
ws.notify({ type: NotificationType.BalanceChange });
|
||||
|
||||
const transactionId = constructTransactionIdentifier({
|
||||
tag: TransactionType.PeerPullDebit,
|
||||
|
@ -22,6 +22,7 @@ import {
|
||||
ExchangePurseMergeRequest,
|
||||
HttpStatusCode,
|
||||
Logger,
|
||||
NotificationType,
|
||||
PeerContractTerms,
|
||||
PreparePeerPushCreditRequest,
|
||||
PreparePeerPushCreditResponse,
|
||||
@ -60,7 +61,12 @@ import {
|
||||
} from "../index.js";
|
||||
import { assertUnreachable } from "../util/assertUnreachable.js";
|
||||
import { checkDbInvariant } from "../util/invariants.js";
|
||||
import { OperationAttemptResult, OperationAttemptResultType, constructTaskIdentifier, runLongpollAsync } from "./common.js";
|
||||
import {
|
||||
OperationAttemptResult,
|
||||
OperationAttemptResultType,
|
||||
constructTaskIdentifier,
|
||||
runLongpollAsync,
|
||||
} from "./common.js";
|
||||
import { updateExchangeFromUrl } from "./exchanges.js";
|
||||
import {
|
||||
codecForExchangePurseStatus,
|
||||
@ -206,6 +212,8 @@ export async function preparePeerPushCredit(
|
||||
});
|
||||
});
|
||||
|
||||
ws.notify({ type: NotificationType.BalanceChange });
|
||||
|
||||
return {
|
||||
amount: purseStatus.balance,
|
||||
amountEffective: wi.withdrawalAmountEffective,
|
||||
@ -631,15 +639,15 @@ export async function confirmPeerPushCredit(
|
||||
}
|
||||
peerPushPaymentIncomingId = parsedTx.peerPushPaymentIncomingId;
|
||||
} else {
|
||||
throw Error("no transaction ID (or deprecated peerPushPaymentIncomingId) provided");
|
||||
throw Error(
|
||||
"no transaction ID (or deprecated peerPushPaymentIncomingId) provided",
|
||||
);
|
||||
}
|
||||
|
||||
await ws.db
|
||||
.mktx((x) => [x.contractTerms, x.peerPushPaymentIncoming])
|
||||
.runReadWrite(async (tx) => {
|
||||
peerInc = await tx.peerPushPaymentIncoming.get(
|
||||
peerPushPaymentIncomingId,
|
||||
);
|
||||
peerInc = await tx.peerPushPaymentIncoming.get(peerPushPaymentIncomingId);
|
||||
if (!peerInc) {
|
||||
return;
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import {
|
||||
InitiatePeerPushDebitRequest,
|
||||
InitiatePeerPushDebitResponse,
|
||||
Logger,
|
||||
NotificationType,
|
||||
RefreshReason,
|
||||
TalerError,
|
||||
TalerErrorCode,
|
||||
@ -678,6 +679,7 @@ export async function initiatePeerPushDebit(
|
||||
};
|
||||
});
|
||||
notifyTransition(ws, transactionId, transitionInfo);
|
||||
ws.notify({ type: NotificationType.BalanceChange });
|
||||
|
||||
return {
|
||||
contractPriv: contractKeyPair.priv,
|
||||
|
@ -278,6 +278,7 @@ async function refreshCreateSession(
|
||||
}
|
||||
await tx.refreshGroups.put(rg);
|
||||
});
|
||||
ws.notify({ type: NotificationType.BalanceChange });
|
||||
return;
|
||||
}
|
||||
|
||||
@ -458,6 +459,7 @@ async function refreshMelt(
|
||||
}
|
||||
await tx.refreshGroups.put(rg);
|
||||
});
|
||||
ws.notify({ type: NotificationType.BalanceChange });
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ import {
|
||||
getRandomBytes,
|
||||
j2s,
|
||||
Logger,
|
||||
NotificationType,
|
||||
parseTipUri,
|
||||
PrepareTipResult,
|
||||
TalerErrorCode,
|
||||
@ -57,7 +58,13 @@ import {
|
||||
readSuccessResponseJsonOrThrow,
|
||||
} from "@gnu-taler/taler-util/http";
|
||||
import { checkDbInvariant, checkLogicInvariant } from "../util/invariants.js";
|
||||
import { constructTaskIdentifier, makeCoinAvailable, makeCoinsVisible, OperationAttemptResult, OperationAttemptResultType } from "./common.js";
|
||||
import {
|
||||
constructTaskIdentifier,
|
||||
makeCoinAvailable,
|
||||
makeCoinsVisible,
|
||||
OperationAttemptResult,
|
||||
OperationAttemptResultType,
|
||||
} from "./common.js";
|
||||
import { updateExchangeFromUrl } from "./exchanges.js";
|
||||
import {
|
||||
getCandidateWithdrawalDenoms,
|
||||
@ -421,6 +428,7 @@ export async function processTip(
|
||||
return { oldTxState, newTxState };
|
||||
});
|
||||
notifyTransition(ws, transactionId, transitionInfo);
|
||||
ws.notify({ type: NotificationType.BalanceChange });
|
||||
|
||||
return {
|
||||
type: OperationAttemptResultType.Finished,
|
||||
|
@ -62,7 +62,6 @@ import {
|
||||
ExchangeWithdrawResponse,
|
||||
WithdrawUriInfoResponse,
|
||||
ExchangeBatchWithdrawRequest,
|
||||
WalletNotification,
|
||||
TransactionState,
|
||||
TransactionMajorState,
|
||||
TransactionMinorState,
|
||||
@ -76,7 +75,6 @@ import {
|
||||
DenominationRecord,
|
||||
DenominationVerificationStatus,
|
||||
KycPendingInfo,
|
||||
KycUserType,
|
||||
PlanchetRecord,
|
||||
PlanchetStatus,
|
||||
WalletStoresV1,
|
||||
@ -108,11 +106,7 @@ import {
|
||||
readSuccessResponseJsonOrThrow,
|
||||
throwUnexpectedRequestError,
|
||||
} from "@gnu-taler/taler-util/http";
|
||||
import {
|
||||
checkDbInvariant,
|
||||
checkLogicInvariant,
|
||||
InvariantViolatedError,
|
||||
} from "../util/invariants.js";
|
||||
import { checkDbInvariant, checkLogicInvariant } from "../util/invariants.js";
|
||||
import {
|
||||
DbAccess,
|
||||
GetReadOnlyAccess,
|
||||
@ -1614,6 +1608,7 @@ async function processWithdrawalGroupPendingReady(
|
||||
}
|
||||
|
||||
notifyTransition(ws, transactionId, res.transitionInfo);
|
||||
ws.notify({ type: NotificationType.BalanceChange });
|
||||
|
||||
if (numPlanchetErrors > 0) {
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user