-towards tip->reward rename
This commit is contained in:
parent
0fe4840ca2
commit
fdbd55d2bd
@ -51,8 +51,8 @@ import {
|
|||||||
stringToBytes,
|
stringToBytes,
|
||||||
TalerError,
|
TalerError,
|
||||||
TalerProtocolDuration,
|
TalerProtocolDuration,
|
||||||
TipCreateConfirmation,
|
RewardCreateConfirmation,
|
||||||
TipCreateRequest,
|
RewardCreateRequest,
|
||||||
TippingReserveStatus,
|
TippingReserveStatus,
|
||||||
WalletNotification,
|
WalletNotification,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
@ -1751,8 +1751,8 @@ export namespace MerchantPrivateApi {
|
|||||||
export async function giveTip(
|
export async function giveTip(
|
||||||
merchantService: MerchantServiceInterface,
|
merchantService: MerchantServiceInterface,
|
||||||
instance: string,
|
instance: string,
|
||||||
req: TipCreateRequest,
|
req: RewardCreateRequest,
|
||||||
): Promise<TipCreateConfirmation> {
|
): Promise<RewardCreateConfirmation> {
|
||||||
const reqUrl = new URL(
|
const reqUrl = new URL(
|
||||||
`private/tips`,
|
`private/tips`,
|
||||||
merchantService.makeInstanceBaseUrl(instance),
|
merchantService.makeInstanceBaseUrl(instance),
|
||||||
|
@ -191,12 +191,12 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) {
|
|||||||
|
|
||||||
const walletTipping = new WalletCli(t, "age-tipping");
|
const walletTipping = new WalletCli(t, "age-tipping");
|
||||||
|
|
||||||
const ptr = await walletTipping.client.call(WalletApiOperation.PrepareTip, {
|
const ptr = await walletTipping.client.call(WalletApiOperation.PrepareReward, {
|
||||||
talerTipUri: tip.taler_tip_uri,
|
talerRewardUri: tip.taler_reward_uri,
|
||||||
});
|
});
|
||||||
|
|
||||||
await walletTipping.client.call(WalletApiOperation.AcceptTip, {
|
await walletTipping.client.call(WalletApiOperation.AcceptReward, {
|
||||||
walletTipId: ptr.walletTipId,
|
walletRewardId: ptr.walletRewardId,
|
||||||
});
|
});
|
||||||
|
|
||||||
await walletTipping.runUntilDone();
|
await walletTipping.runUntilDone();
|
||||||
|
@ -99,17 +99,17 @@ export async function runTippingTest(t: GlobalTestState) {
|
|||||||
console.log("created tip", tip);
|
console.log("created tip", tip);
|
||||||
|
|
||||||
const doTip = async (): Promise<void> => {
|
const doTip = async (): Promise<void> => {
|
||||||
const ptr = await wallet.client.call(WalletApiOperation.PrepareTip, {
|
const ptr = await wallet.client.call(WalletApiOperation.PrepareReward, {
|
||||||
talerTipUri: tip.taler_tip_uri,
|
talerRewardUri: tip.taler_reward_uri,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(ptr);
|
console.log(ptr);
|
||||||
|
|
||||||
t.assertAmountEquals(ptr.tipAmountRaw, "TESTKUDOS:5");
|
t.assertAmountEquals(ptr.rewardAmountRaw, "TESTKUDOS:5");
|
||||||
t.assertAmountEquals(ptr.tipAmountEffective, "TESTKUDOS:4.85");
|
t.assertAmountEquals(ptr.rewardAmountEffective, "TESTKUDOS:4.85");
|
||||||
|
|
||||||
await wallet.client.call(WalletApiOperation.AcceptTip, {
|
await wallet.client.call(WalletApiOperation.AcceptReward, {
|
||||||
walletTipId: ptr.walletTipId,
|
walletRewardId: ptr.walletRewardId,
|
||||||
});
|
});
|
||||||
|
|
||||||
await wallet.runUntilDone();
|
await wallet.runUntilDone();
|
||||||
@ -127,7 +127,7 @@ export async function runTippingTest(t: GlobalTestState) {
|
|||||||
|
|
||||||
console.log("Transactions:", JSON.stringify(txns, undefined, 2));
|
console.log("Transactions:", JSON.stringify(txns, undefined, 2));
|
||||||
|
|
||||||
t.assertDeepEqual(txns.transactions[0].type, "tip");
|
t.assertDeepEqual(txns.transactions[0].type, "reward");
|
||||||
t.assertDeepEqual(txns.transactions[0].txState.major, TransactionMajorState.Done);
|
t.assertDeepEqual(txns.transactions[0].txState.major, TransactionMajorState.Done);
|
||||||
t.assertAmountEquals(
|
t.assertAmountEquals(
|
||||||
txns.transactions[0].amountEffective,
|
txns.transactions[0].amountEffective,
|
||||||
|
@ -499,7 +499,7 @@ export interface BackupRecoupGroup {
|
|||||||
export enum BackupCoinSourceType {
|
export enum BackupCoinSourceType {
|
||||||
Withdraw = "withdraw",
|
Withdraw = "withdraw",
|
||||||
Refresh = "refresh",
|
Refresh = "refresh",
|
||||||
Tip = "tip",
|
Reward = "reward",
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -546,7 +546,7 @@ export interface BackupRefreshCoinSource {
|
|||||||
* Metadata about a coin obtained from a tip.
|
* Metadata about a coin obtained from a tip.
|
||||||
*/
|
*/
|
||||||
export interface BackupTipCoinSource {
|
export interface BackupTipCoinSource {
|
||||||
type: BackupCoinSourceType.Tip;
|
type: BackupCoinSourceType.Reward;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wallet's identifier for the tip that this coin
|
* Wallet's identifier for the tip that this coin
|
||||||
|
@ -183,7 +183,16 @@ export class HttpLibImpl implements HttpRequestLibrary {
|
|||||||
resolve(resp);
|
resolve(resp);
|
||||||
});
|
});
|
||||||
res.on("error", (e) => {
|
res.on("error", (e) => {
|
||||||
reject(e);
|
const err = TalerError.fromDetail(
|
||||||
|
TalerErrorCode.WALLET_UNEXPECTED_REQUEST_ERROR,
|
||||||
|
{
|
||||||
|
requestUrl: url,
|
||||||
|
requestMethod: method,
|
||||||
|
httpStatusCode: 0,
|
||||||
|
},
|
||||||
|
`Error in HTTP response handler: ${e.message}`,
|
||||||
|
);
|
||||||
|
reject(err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -197,7 +206,16 @@ export class HttpLibImpl implements HttpRequestLibrary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
req.on("error", (e: Error) => {
|
req.on("error", (e: Error) => {
|
||||||
reject(e);
|
const err = TalerError.fromDetail(
|
||||||
|
TalerErrorCode.WALLET_UNEXPECTED_REQUEST_ERROR,
|
||||||
|
{
|
||||||
|
requestUrl: url,
|
||||||
|
requestMethod: method,
|
||||||
|
httpStatusCode: 0,
|
||||||
|
},
|
||||||
|
`Error in HTTP request: ${e.message}`,
|
||||||
|
);
|
||||||
|
reject(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (reqBody) {
|
if (reqBody) {
|
||||||
|
@ -290,22 +290,22 @@ export interface ReserveStatusEntry {
|
|||||||
active: boolean;
|
active: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TipCreateConfirmation {
|
export interface RewardCreateConfirmation {
|
||||||
// Unique tip identifier for the tip that was created.
|
// Unique tip identifier for the tip that was created.
|
||||||
tip_id: string;
|
reward_id: string;
|
||||||
|
|
||||||
// taler://tip URI for the tip
|
// taler://tip URI for the tip
|
||||||
taler_tip_uri: string;
|
taler_reward_uri: string;
|
||||||
|
|
||||||
// URL that will directly trigger processing
|
// URL that will directly trigger processing
|
||||||
// the tip when the browser is redirected to it
|
// the tip when the browser is redirected to it
|
||||||
tip_status_url: string;
|
reward_status_url: string;
|
||||||
|
|
||||||
// when does the tip expire
|
// when does the reward expire
|
||||||
tip_expiration: AbsoluteTime;
|
reward_expiration: AbsoluteTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TipCreateRequest {
|
export interface RewardCreateRequest {
|
||||||
// Amount that the customer should be tipped
|
// Amount that the customer should be tipped
|
||||||
amount: AmountString;
|
amount: AmountString;
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ export type Transaction =
|
|||||||
| TransactionWithdrawal
|
| TransactionWithdrawal
|
||||||
| TransactionPayment
|
| TransactionPayment
|
||||||
| TransactionRefund
|
| TransactionRefund
|
||||||
| TransactionTip
|
| TransactionReward
|
||||||
| TransactionRefresh
|
| TransactionRefresh
|
||||||
| TransactionDeposit
|
| TransactionDeposit
|
||||||
| TransactionPeerPullCredit
|
| TransactionPeerPullCredit
|
||||||
@ -201,7 +201,7 @@ export enum TransactionType {
|
|||||||
Payment = "payment",
|
Payment = "payment",
|
||||||
Refund = "refund",
|
Refund = "refund",
|
||||||
Refresh = "refresh",
|
Refresh = "refresh",
|
||||||
Tip = "tip",
|
Reward = "reward",
|
||||||
Deposit = "deposit",
|
Deposit = "deposit",
|
||||||
PeerPushDebit = "peer-push-debit",
|
PeerPushDebit = "peer-push-debit",
|
||||||
PeerPushCredit = "peer-push-credit",
|
PeerPushCredit = "peer-push-credit",
|
||||||
@ -591,8 +591,8 @@ export interface TransactionRefund extends TransactionCommon {
|
|||||||
paymentInfo: RefundPaymentInfo | undefined;
|
paymentInfo: RefundPaymentInfo | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TransactionTip extends TransactionCommon {
|
export interface TransactionReward extends TransactionCommon {
|
||||||
type: TransactionType.Tip;
|
type: TransactionType.Reward;
|
||||||
|
|
||||||
// Raw amount of the tip, without extra fees that apply
|
// Raw amount of the tip, without extra fees that apply
|
||||||
amountRaw: AmountString;
|
amountRaw: AmountString;
|
||||||
|
@ -605,7 +605,7 @@ export interface PrepareTipResult {
|
|||||||
*
|
*
|
||||||
* @deprecated use transactionId instead
|
* @deprecated use transactionId instead
|
||||||
*/
|
*/
|
||||||
walletTipId: string;
|
walletRewardId: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tip transaction ID.
|
* Tip transaction ID.
|
||||||
@ -620,13 +620,13 @@ export interface PrepareTipResult {
|
|||||||
/**
|
/**
|
||||||
* Amount that the merchant gave.
|
* Amount that the merchant gave.
|
||||||
*/
|
*/
|
||||||
tipAmountRaw: AmountString;
|
rewardAmountRaw: AmountString;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Amount that arrived at the wallet.
|
* Amount that arrived at the wallet.
|
||||||
* Might be lower than the raw amount due to fees.
|
* Might be lower than the raw amount due to fees.
|
||||||
*/
|
*/
|
||||||
tipAmountEffective: AmountString;
|
rewardAmountEffective: AmountString;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base URL of the merchant backend giving then tip.
|
* Base URL of the merchant backend giving then tip.
|
||||||
@ -654,14 +654,14 @@ export interface AcceptTipResponse {
|
|||||||
export const codecForPrepareTipResult = (): Codec<PrepareTipResult> =>
|
export const codecForPrepareTipResult = (): Codec<PrepareTipResult> =>
|
||||||
buildCodecForObject<PrepareTipResult>()
|
buildCodecForObject<PrepareTipResult>()
|
||||||
.property("accepted", codecForBoolean())
|
.property("accepted", codecForBoolean())
|
||||||
.property("tipAmountRaw", codecForAmountString())
|
.property("rewardAmountRaw", codecForAmountString())
|
||||||
.property("tipAmountEffective", codecForAmountString())
|
.property("rewardAmountEffective", codecForAmountString())
|
||||||
.property("exchangeBaseUrl", codecForString())
|
.property("exchangeBaseUrl", codecForString())
|
||||||
.property("merchantBaseUrl", codecForString())
|
.property("merchantBaseUrl", codecForString())
|
||||||
.property("expirationTimestamp", codecForTimestamp)
|
.property("expirationTimestamp", codecForTimestamp)
|
||||||
.property("walletTipId", codecForString())
|
.property("walletRewardId", codecForString())
|
||||||
.property("transactionId", codecForString())
|
.property("transactionId", codecForString())
|
||||||
.build("PrepareTipResult");
|
.build("PrepareRewardResult");
|
||||||
|
|
||||||
export interface BenchmarkResult {
|
export interface BenchmarkResult {
|
||||||
time: { [s: string]: number };
|
time: { [s: string]: number };
|
||||||
@ -1933,23 +1933,23 @@ export const codecForStartRefundQueryRequest =
|
|||||||
.property("transactionId", codecForTransactionIdStr())
|
.property("transactionId", codecForTransactionIdStr())
|
||||||
.build("StartRefundQueryRequest");
|
.build("StartRefundQueryRequest");
|
||||||
|
|
||||||
export interface PrepareTipRequest {
|
export interface PrepareRewardRequest {
|
||||||
talerTipUri: string;
|
talerRewardUri: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const codecForPrepareTipRequest = (): Codec<PrepareTipRequest> =>
|
export const codecForPrepareRewardRequest = (): Codec<PrepareRewardRequest> =>
|
||||||
buildCodecForObject<PrepareTipRequest>()
|
buildCodecForObject<PrepareRewardRequest>()
|
||||||
.property("talerTipUri", codecForString())
|
.property("talerRewardUri", codecForString())
|
||||||
.build("PrepareTipRequest");
|
.build("PrepareRewardRequest");
|
||||||
|
|
||||||
export interface AcceptTipRequest {
|
export interface AcceptRewardRequest {
|
||||||
walletTipId: string;
|
walletRewardId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const codecForAcceptTipRequest = (): Codec<AcceptTipRequest> =>
|
export const codecForAcceptTipRequest = (): Codec<AcceptRewardRequest> =>
|
||||||
buildCodecForObject<AcceptTipRequest>()
|
buildCodecForObject<AcceptRewardRequest>()
|
||||||
.property("walletTipId", codecForString())
|
.property("walletRewardId", codecForString())
|
||||||
.build("AcceptTipRequest");
|
.build("AcceptRewardRequest");
|
||||||
|
|
||||||
export interface FailTransactionRequest {
|
export interface FailTransactionRequest {
|
||||||
transactionId: TransactionIdStr;
|
transactionId: TransactionIdStr;
|
||||||
|
@ -652,12 +652,12 @@ walletCli
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case TalerUriAction.Tip: {
|
case TalerUriAction.Tip: {
|
||||||
const res = await wallet.client.call(WalletApiOperation.PrepareTip, {
|
const res = await wallet.client.call(WalletApiOperation.PrepareReward, {
|
||||||
talerTipUri: uri,
|
talerRewardUri: uri,
|
||||||
});
|
});
|
||||||
console.log("tip status", res);
|
console.log("tip status", res);
|
||||||
await wallet.client.call(WalletApiOperation.AcceptTip, {
|
await wallet.client.call(WalletApiOperation.AcceptReward, {
|
||||||
walletTipId: res.walletTipId,
|
walletRewardId: res.walletRewardId,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -677,7 +677,7 @@ export interface PlanchetRecord {
|
|||||||
export enum CoinSourceType {
|
export enum CoinSourceType {
|
||||||
Withdraw = "withdraw",
|
Withdraw = "withdraw",
|
||||||
Refresh = "refresh",
|
Refresh = "refresh",
|
||||||
Tip = "tip",
|
Reward = "reward",
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WithdrawCoinSource {
|
export interface WithdrawCoinSource {
|
||||||
@ -705,13 +705,13 @@ export interface RefreshCoinSource {
|
|||||||
oldCoinPub: string;
|
oldCoinPub: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TipCoinSource {
|
export interface RewardCoinSource {
|
||||||
type: CoinSourceType.Tip;
|
type: CoinSourceType.Reward;
|
||||||
walletTipId: string;
|
walletRewardId: string;
|
||||||
coinIndex: number;
|
coinIndex: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CoinSource = WithdrawCoinSource | RefreshCoinSource | TipCoinSource;
|
export type CoinSource = WithdrawCoinSource | RefreshCoinSource | RewardCoinSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CoinRecord as stored in the "coins" data store
|
* CoinRecord as stored in the "coins" data store
|
||||||
@ -815,9 +815,9 @@ export interface CoinAllocation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Status of a tip we got from a merchant.
|
* Status of a reward we got from a merchant.
|
||||||
*/
|
*/
|
||||||
export interface TipRecord {
|
export interface RewardRecord {
|
||||||
/**
|
/**
|
||||||
* Has the user accepted the tip? Only after the tip has been accepted coins
|
* Has the user accepted the tip? Only after the tip has been accepted coins
|
||||||
* withdrawn from the tip may be used.
|
* withdrawn from the tip may be used.
|
||||||
@ -827,17 +827,17 @@ export interface TipRecord {
|
|||||||
/**
|
/**
|
||||||
* The tipped amount.
|
* The tipped amount.
|
||||||
*/
|
*/
|
||||||
tipAmountRaw: AmountString;
|
rewardAmountRaw: AmountString;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Effect on the balance (including fees etc).
|
* Effect on the balance (including fees etc).
|
||||||
*/
|
*/
|
||||||
tipAmountEffective: AmountString;
|
rewardAmountEffective: AmountString;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Timestamp, the tip can't be picked up anymore after this deadline.
|
* Timestamp, the tip can't be picked up anymore after this deadline.
|
||||||
*/
|
*/
|
||||||
tipExpiration: TalerProtocolTimestamp;
|
rewardExpiration: TalerProtocolTimestamp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The exchange that will sign our coins, chosen by the merchant.
|
* The exchange that will sign our coins, chosen by the merchant.
|
||||||
@ -863,7 +863,7 @@ export interface TipRecord {
|
|||||||
/**
|
/**
|
||||||
* Tip ID chosen by the wallet.
|
* Tip ID chosen by the wallet.
|
||||||
*/
|
*/
|
||||||
walletTipId: string;
|
walletRewardId: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Secret seed used to derive planchets for this tip.
|
* Secret seed used to derive planchets for this tip.
|
||||||
@ -871,9 +871,9 @@ export interface TipRecord {
|
|||||||
secretSeed: string;
|
secretSeed: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The merchant's identifier for this tip.
|
* The merchant's identifier for this reward.
|
||||||
*/
|
*/
|
||||||
merchantTipId: string;
|
merchantRewardId: string;
|
||||||
|
|
||||||
createdTimestamp: TalerPreciseTimestamp;
|
createdTimestamp: TalerPreciseTimestamp;
|
||||||
|
|
||||||
@ -888,10 +888,10 @@ export interface TipRecord {
|
|||||||
*/
|
*/
|
||||||
pickedUpTimestamp: TalerPreciseTimestamp | undefined;
|
pickedUpTimestamp: TalerPreciseTimestamp | undefined;
|
||||||
|
|
||||||
status: TipRecordStatus;
|
status: RewardRecordStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum TipRecordStatus {
|
export enum RewardRecordStatus {
|
||||||
PendingPickup = 10,
|
PendingPickup = 10,
|
||||||
|
|
||||||
SuspendidPickup = 20,
|
SuspendidPickup = 20,
|
||||||
@ -1420,7 +1420,7 @@ export interface KycPendingInfo {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Group of withdrawal operations that need to be executed.
|
* Group of withdrawal operations that need to be executed.
|
||||||
* (Either for a normal withdrawal or from a tip.)
|
* (Either for a normal withdrawal or from a reward.)
|
||||||
*
|
*
|
||||||
* The withdrawal group record is only created after we know
|
* The withdrawal group record is only created after we know
|
||||||
* the coin selection we want to withdraw.
|
* the coin selection we want to withdraw.
|
||||||
@ -2480,12 +2480,12 @@ export const WalletStoresV1 = {
|
|||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
tips: describeStore(
|
rewards: describeStore(
|
||||||
"tips",
|
"rewards",
|
||||||
describeContents<TipRecord>({ keyPath: "walletTipId" }),
|
describeContents<RewardRecord>({ keyPath: "walletRewardId" }),
|
||||||
{
|
{
|
||||||
byMerchantTipIdAndBaseUrl: describeIndex("byMerchantTipIdAndBaseUrl", [
|
byMerchantTipIdAndBaseUrl: describeIndex("byMerchantRewardIdAndBaseUrl", [
|
||||||
"merchantTipId",
|
"merchantRewardId",
|
||||||
"merchantBaseUrl",
|
"merchantBaseUrl",
|
||||||
]),
|
]),
|
||||||
byStatus: describeIndex("byStatus", "status", {
|
byStatus: describeIndex("byStatus", "status", {
|
||||||
@ -2935,22 +2935,6 @@ export const walletDbFixups: FixupDescription[] = [
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "TipRecordRecord_status_add",
|
|
||||||
async fn(tx): Promise<void> {
|
|
||||||
await tx.tips.iter().forEachAsync(async (r) => {
|
|
||||||
// Remove legacy transactions that don't have the totalCost field yet.
|
|
||||||
if (r.status == null) {
|
|
||||||
if (r.pickedUpTimestamp) {
|
|
||||||
r.status = TipRecordStatus.Done;
|
|
||||||
} else {
|
|
||||||
r.status = TipRecordStatus.PendingPickup;
|
|
||||||
}
|
|
||||||
await tx.tips.put(r);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "CoinAvailabilityRecord_visibleCoinCount_add",
|
name: "CoinAvailabilityRecord_visibleCoinCount_add",
|
||||||
async fn(tx): Promise<void> {
|
async fn(tx): Promise<void> {
|
||||||
|
@ -96,7 +96,7 @@ export async function exportBackup(
|
|||||||
x.purchases,
|
x.purchases,
|
||||||
x.refreshGroups,
|
x.refreshGroups,
|
||||||
x.backupProviders,
|
x.backupProviders,
|
||||||
x.tips,
|
x.rewards,
|
||||||
x.recoupGroups,
|
x.recoupGroups,
|
||||||
x.withdrawalGroups,
|
x.withdrawalGroups,
|
||||||
])
|
])
|
||||||
@ -184,12 +184,12 @@ export async function exportBackup(
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
await tx.tips.iter().forEach((tip) => {
|
await tx.rewards.iter().forEach((tip) => {
|
||||||
backupTips.push({
|
backupTips.push({
|
||||||
exchange_base_url: tip.exchangeBaseUrl,
|
exchange_base_url: tip.exchangeBaseUrl,
|
||||||
merchant_base_url: tip.merchantBaseUrl,
|
merchant_base_url: tip.merchantBaseUrl,
|
||||||
merchant_tip_id: tip.merchantTipId,
|
merchant_tip_id: tip.merchantRewardId,
|
||||||
wallet_tip_id: tip.walletTipId,
|
wallet_tip_id: tip.walletRewardId,
|
||||||
next_url: tip.next_url,
|
next_url: tip.next_url,
|
||||||
secret_seed: tip.secretSeed,
|
secret_seed: tip.secretSeed,
|
||||||
selected_denoms: tip.denomsSel.selectedDenoms.map((x) => ({
|
selected_denoms: tip.denomsSel.selectedDenoms.map((x) => ({
|
||||||
@ -199,8 +199,8 @@ export async function exportBackup(
|
|||||||
timestamp_finished: tip.pickedUpTimestamp,
|
timestamp_finished: tip.pickedUpTimestamp,
|
||||||
timestamp_accepted: tip.acceptedTimestamp,
|
timestamp_accepted: tip.acceptedTimestamp,
|
||||||
timestamp_created: tip.createdTimestamp,
|
timestamp_created: tip.createdTimestamp,
|
||||||
timestamp_expiration: tip.tipExpiration,
|
timestamp_expiration: tip.rewardExpiration,
|
||||||
tip_amount_raw: Amounts.stringify(tip.tipAmountRaw),
|
tip_amount_raw: Amounts.stringify(tip.rewardAmountRaw),
|
||||||
selected_denoms_uid: tip.denomSelUid,
|
selected_denoms_uid: tip.denomSelUid,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -244,11 +244,11 @@ export async function exportBackup(
|
|||||||
refresh_group_id: coin.coinSource.refreshGroupId,
|
refresh_group_id: coin.coinSource.refreshGroupId,
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case CoinSourceType.Tip:
|
case CoinSourceType.Reward:
|
||||||
bcs = {
|
bcs = {
|
||||||
type: BackupCoinSourceType.Tip,
|
type: BackupCoinSourceType.Reward,
|
||||||
coin_index: coin.coinSource.coinIndex,
|
coin_index: coin.coinSource.coinIndex,
|
||||||
wallet_tip_id: coin.coinSource.walletTipId,
|
wallet_tip_id: coin.coinSource.walletRewardId,
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case CoinSourceType.Withdraw:
|
case CoinSourceType.Withdraw:
|
||||||
|
@ -56,7 +56,7 @@ import {
|
|||||||
WithdrawalGroupStatus,
|
WithdrawalGroupStatus,
|
||||||
WithdrawalRecordType,
|
WithdrawalRecordType,
|
||||||
RefreshOperationStatus,
|
RefreshOperationStatus,
|
||||||
TipRecordStatus,
|
RewardRecordStatus,
|
||||||
} from "../../db.js";
|
} from "../../db.js";
|
||||||
import { InternalWalletState } from "../../internal-wallet-state.js";
|
import { InternalWalletState } from "../../internal-wallet-state.js";
|
||||||
import { assertUnreachable } from "../../util/assertUnreachable.js";
|
import { assertUnreachable } from "../../util/assertUnreachable.js";
|
||||||
@ -250,11 +250,11 @@ export async function importCoin(
|
|||||||
refreshGroupId: backupCoin.coin_source.refresh_group_id,
|
refreshGroupId: backupCoin.coin_source.refresh_group_id,
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case BackupCoinSourceType.Tip:
|
case BackupCoinSourceType.Reward:
|
||||||
coinSource = {
|
coinSource = {
|
||||||
type: CoinSourceType.Tip,
|
type: CoinSourceType.Reward,
|
||||||
coinIndex: backupCoin.coin_source.coin_index,
|
coinIndex: backupCoin.coin_source.coin_index,
|
||||||
walletTipId: backupCoin.coin_source.wallet_tip_id,
|
walletRewardId: backupCoin.coin_source.wallet_tip_id,
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case BackupCoinSourceType.Withdraw:
|
case BackupCoinSourceType.Withdraw:
|
||||||
@ -311,7 +311,7 @@ export async function importBackup(
|
|||||||
x.purchases,
|
x.purchases,
|
||||||
x.refreshGroups,
|
x.refreshGroups,
|
||||||
x.backupProviders,
|
x.backupProviders,
|
||||||
x.tips,
|
x.rewards,
|
||||||
x.recoupGroups,
|
x.recoupGroups,
|
||||||
x.withdrawalGroups,
|
x.withdrawalGroups,
|
||||||
x.tombstones,
|
x.tombstones,
|
||||||
@ -812,13 +812,13 @@ export async function importBackup(
|
|||||||
|
|
||||||
for (const backupTip of backupBlob.tips) {
|
for (const backupTip of backupBlob.tips) {
|
||||||
const ts = constructTombstone({
|
const ts = constructTombstone({
|
||||||
tag: TombstoneTag.DeleteTip,
|
tag: TombstoneTag.DeleteReward,
|
||||||
walletTipId: backupTip.wallet_tip_id,
|
walletTipId: backupTip.wallet_tip_id,
|
||||||
});
|
});
|
||||||
if (tombstoneSet.has(ts)) {
|
if (tombstoneSet.has(ts)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const existingTip = await tx.tips.get(backupTip.wallet_tip_id);
|
const existingTip = await tx.rewards.get(backupTip.wallet_tip_id);
|
||||||
if (!existingTip) {
|
if (!existingTip) {
|
||||||
const tipAmountRaw = Amounts.parseOrThrow(backupTip.tip_amount_raw);
|
const tipAmountRaw = Amounts.parseOrThrow(backupTip.tip_amount_raw);
|
||||||
const denomsSel = await getDenomSelStateFromBackup(
|
const denomsSel = await getDenomSelStateFromBackup(
|
||||||
@ -827,22 +827,22 @@ export async function importBackup(
|
|||||||
backupTip.exchange_base_url,
|
backupTip.exchange_base_url,
|
||||||
backupTip.selected_denoms,
|
backupTip.selected_denoms,
|
||||||
);
|
);
|
||||||
await tx.tips.put({
|
await tx.rewards.put({
|
||||||
acceptedTimestamp: backupTip.timestamp_accepted,
|
acceptedTimestamp: backupTip.timestamp_accepted,
|
||||||
createdTimestamp: backupTip.timestamp_created,
|
createdTimestamp: backupTip.timestamp_created,
|
||||||
denomsSel,
|
denomsSel,
|
||||||
next_url: backupTip.next_url,
|
next_url: backupTip.next_url,
|
||||||
exchangeBaseUrl: backupTip.exchange_base_url,
|
exchangeBaseUrl: backupTip.exchange_base_url,
|
||||||
merchantBaseUrl: backupTip.exchange_base_url,
|
merchantBaseUrl: backupTip.exchange_base_url,
|
||||||
merchantTipId: backupTip.merchant_tip_id,
|
merchantRewardId: backupTip.merchant_tip_id,
|
||||||
pickedUpTimestamp: backupTip.timestamp_finished,
|
pickedUpTimestamp: backupTip.timestamp_finished,
|
||||||
secretSeed: backupTip.secret_seed,
|
secretSeed: backupTip.secret_seed,
|
||||||
tipAmountEffective: Amounts.stringify(denomsSel.totalCoinValue),
|
rewardAmountEffective: Amounts.stringify(denomsSel.totalCoinValue),
|
||||||
tipAmountRaw: Amounts.stringify(tipAmountRaw),
|
rewardAmountRaw: Amounts.stringify(tipAmountRaw),
|
||||||
tipExpiration: backupTip.timestamp_expiration,
|
rewardExpiration: backupTip.timestamp_expiration,
|
||||||
walletTipId: backupTip.wallet_tip_id,
|
walletRewardId: backupTip.wallet_tip_id,
|
||||||
denomSelUid: backupTip.selected_denoms_uid,
|
denomSelUid: backupTip.selected_denoms_uid,
|
||||||
status: TipRecordStatus.Done, // FIXME!
|
status: RewardRecordStatus.Done, // FIXME!
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -863,8 +863,8 @@ export async function importBackup(
|
|||||||
} else if (type === TombstoneTag.DeleteRefund) {
|
} else if (type === TombstoneTag.DeleteRefund) {
|
||||||
// Nothing required, will just prevent display
|
// Nothing required, will just prevent display
|
||||||
// in the transactions list
|
// in the transactions list
|
||||||
} else if (type === TombstoneTag.DeleteTip) {
|
} else if (type === TombstoneTag.DeleteReward) {
|
||||||
await tx.tips.delete(rest[0]);
|
await tx.rewards.delete(rest[0]);
|
||||||
} else if (type === TombstoneTag.DeleteWithdrawalGroup) {
|
} else if (type === TombstoneTag.DeleteWithdrawalGroup) {
|
||||||
await tx.withdrawalGroups.delete(rest[0]);
|
await tx.withdrawalGroups.delete(rest[0]);
|
||||||
} else {
|
} else {
|
||||||
|
@ -57,7 +57,7 @@ import {
|
|||||||
PurchaseRecord,
|
PurchaseRecord,
|
||||||
RecoupGroupRecord,
|
RecoupGroupRecord,
|
||||||
RefreshGroupRecord,
|
RefreshGroupRecord,
|
||||||
TipRecord,
|
RewardRecord,
|
||||||
WithdrawalGroupRecord,
|
WithdrawalGroupRecord,
|
||||||
} from "../db.js";
|
} from "../db.js";
|
||||||
import { makeErrorDetail, TalerError } from "@gnu-taler/taler-util";
|
import { makeErrorDetail, TalerError } from "@gnu-taler/taler-util";
|
||||||
@ -293,10 +293,10 @@ function convertTaskToTransactionId(
|
|||||||
tag: TransactionType.Refresh,
|
tag: TransactionType.Refresh,
|
||||||
refreshGroupId: parsedTaskId.refreshGroupId,
|
refreshGroupId: parsedTaskId.refreshGroupId,
|
||||||
});
|
});
|
||||||
case PendingTaskType.TipPickup:
|
case PendingTaskType.RewardPickup:
|
||||||
return constructTransactionIdentifier({
|
return constructTransactionIdentifier({
|
||||||
tag: TransactionType.Tip,
|
tag: TransactionType.Reward,
|
||||||
walletTipId: parsedTaskId.walletTipId,
|
walletRewardId: parsedTaskId.walletRewardId,
|
||||||
});
|
});
|
||||||
case PendingTaskType.PeerPushDebit:
|
case PendingTaskType.PeerPushDebit:
|
||||||
return constructTransactionIdentifier({
|
return constructTransactionIdentifier({
|
||||||
@ -515,7 +515,7 @@ export enum TombstoneTag {
|
|||||||
DeleteWithdrawalGroup = "delete-withdrawal-group",
|
DeleteWithdrawalGroup = "delete-withdrawal-group",
|
||||||
DeleteReserve = "delete-reserve",
|
DeleteReserve = "delete-reserve",
|
||||||
DeletePayment = "delete-payment",
|
DeletePayment = "delete-payment",
|
||||||
DeleteTip = "delete-tip",
|
DeleteReward = "delete-reward",
|
||||||
DeleteRefreshGroup = "delete-refresh-group",
|
DeleteRefreshGroup = "delete-refresh-group",
|
||||||
DeleteDepositGroup = "delete-deposit-group",
|
DeleteDepositGroup = "delete-deposit-group",
|
||||||
DeleteRefund = "delete-refund",
|
DeleteRefund = "delete-refund",
|
||||||
@ -601,7 +601,9 @@ export function runLongpollAsync(
|
|||||||
};
|
};
|
||||||
res = await reqFn(cts.token);
|
res = await reqFn(cts.token);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await storePendingTaskError(ws, retryTag, getErrorDetailFromException(e));
|
const errDetail = getErrorDetailFromException(e);
|
||||||
|
logger.warn(`got error during long-polling: ${j2s(errDetail)}`);
|
||||||
|
await storePendingTaskError(ws, retryTag, errDetail);
|
||||||
return;
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
delete ws.activeLongpoll[retryTag];
|
delete ws.activeLongpoll[retryTag];
|
||||||
@ -622,7 +624,7 @@ export type ParsedTombstone =
|
|||||||
| { tag: TombstoneTag.DeleteRefund; refundGroupId: string }
|
| { tag: TombstoneTag.DeleteRefund; refundGroupId: string }
|
||||||
| { tag: TombstoneTag.DeleteReserve; reservePub: string }
|
| { tag: TombstoneTag.DeleteReserve; reservePub: string }
|
||||||
| { tag: TombstoneTag.DeleteRefreshGroup; refreshGroupId: string }
|
| { tag: TombstoneTag.DeleteRefreshGroup; refreshGroupId: string }
|
||||||
| { tag: TombstoneTag.DeleteTip; walletTipId: string }
|
| { tag: TombstoneTag.DeleteReward; walletTipId: string }
|
||||||
| { tag: TombstoneTag.DeletePayment; proposalId: string };
|
| { tag: TombstoneTag.DeletePayment; proposalId: string };
|
||||||
|
|
||||||
export function constructTombstone(p: ParsedTombstone): TombstoneIdStr {
|
export function constructTombstone(p: ParsedTombstone): TombstoneIdStr {
|
||||||
@ -637,7 +639,7 @@ export function constructTombstone(p: ParsedTombstone): TombstoneIdStr {
|
|||||||
return `tmb:${p.tag}:${p.proposalId}` as TombstoneIdStr;
|
return `tmb:${p.tag}:${p.proposalId}` as TombstoneIdStr;
|
||||||
case TombstoneTag.DeleteRefreshGroup:
|
case TombstoneTag.DeleteRefreshGroup:
|
||||||
return `tmb:${p.tag}:${p.refreshGroupId}` as TombstoneIdStr;
|
return `tmb:${p.tag}:${p.refreshGroupId}` as TombstoneIdStr;
|
||||||
case TombstoneTag.DeleteTip:
|
case TombstoneTag.DeleteReward:
|
||||||
return `tmb:${p.tag}:${p.walletTipId}` as TombstoneIdStr;
|
return `tmb:${p.tag}:${p.walletTipId}` as TombstoneIdStr;
|
||||||
default:
|
default:
|
||||||
assertUnreachable(p);
|
assertUnreachable(p);
|
||||||
@ -810,7 +812,7 @@ export type ParsedTaskIdentifier =
|
|||||||
| { tag: PendingTaskType.PeerPushDebit; pursePub: string }
|
| { tag: PendingTaskType.PeerPushDebit; pursePub: string }
|
||||||
| { tag: PendingTaskType.Purchase; proposalId: string }
|
| { tag: PendingTaskType.Purchase; proposalId: string }
|
||||||
| { tag: PendingTaskType.Recoup; recoupGroupId: string }
|
| { tag: PendingTaskType.Recoup; recoupGroupId: string }
|
||||||
| { tag: PendingTaskType.TipPickup; walletTipId: string }
|
| { tag: PendingTaskType.RewardPickup; walletRewardId: string }
|
||||||
| { tag: PendingTaskType.Refresh; refreshGroupId: string };
|
| { tag: PendingTaskType.Refresh; refreshGroupId: string };
|
||||||
|
|
||||||
export function parseTaskIdentifier(x: string): ParsedTaskIdentifier {
|
export function parseTaskIdentifier(x: string): ParsedTaskIdentifier {
|
||||||
@ -844,8 +846,8 @@ export function parseTaskIdentifier(x: string): ParsedTaskIdentifier {
|
|||||||
return { tag: type, recoupGroupId: rest[0] };
|
return { tag: type, recoupGroupId: rest[0] };
|
||||||
case PendingTaskType.Refresh:
|
case PendingTaskType.Refresh:
|
||||||
return { tag: type, refreshGroupId: rest[0] };
|
return { tag: type, refreshGroupId: rest[0] };
|
||||||
case PendingTaskType.TipPickup:
|
case PendingTaskType.RewardPickup:
|
||||||
return { tag: type, walletTipId: rest[0] };
|
return { tag: type, walletRewardId: rest[0] };
|
||||||
case PendingTaskType.Withdraw:
|
case PendingTaskType.Withdraw:
|
||||||
return { tag: type, withdrawalGroupId: rest[0] };
|
return { tag: type, withdrawalGroupId: rest[0] };
|
||||||
default:
|
default:
|
||||||
@ -877,8 +879,8 @@ export function constructTaskIdentifier(p: ParsedTaskIdentifier): TaskId {
|
|||||||
return `${p.tag}:${p.recoupGroupId}` as TaskId;
|
return `${p.tag}:${p.recoupGroupId}` as TaskId;
|
||||||
case PendingTaskType.Refresh:
|
case PendingTaskType.Refresh:
|
||||||
return `${p.tag}:${p.refreshGroupId}` as TaskId;
|
return `${p.tag}:${p.refreshGroupId}` as TaskId;
|
||||||
case PendingTaskType.TipPickup:
|
case PendingTaskType.RewardPickup:
|
||||||
return `${p.tag}:${p.walletTipId}` as TaskId;
|
return `${p.tag}:${p.walletRewardId}` as TaskId;
|
||||||
case PendingTaskType.Withdraw:
|
case PendingTaskType.Withdraw:
|
||||||
return `${p.tag}:${p.withdrawalGroupId}` as TaskId;
|
return `${p.tag}:${p.withdrawalGroupId}` as TaskId;
|
||||||
default:
|
default:
|
||||||
@ -899,8 +901,8 @@ export namespace TaskIdentifiers {
|
|||||||
export function forExchangeCheckRefresh(exch: ExchangeRecord): TaskId {
|
export function forExchangeCheckRefresh(exch: ExchangeRecord): TaskId {
|
||||||
return `${PendingTaskType.ExchangeCheckRefresh}:${exch.baseUrl}` as TaskId;
|
return `${PendingTaskType.ExchangeCheckRefresh}:${exch.baseUrl}` as TaskId;
|
||||||
}
|
}
|
||||||
export function forTipPickup(tipRecord: TipRecord): TaskId {
|
export function forTipPickup(tipRecord: RewardRecord): TaskId {
|
||||||
return `${PendingTaskType.TipPickup}:${tipRecord.walletTipId}` as TaskId;
|
return `${PendingTaskType.RewardPickup}:${tipRecord.walletRewardId}` as TaskId;
|
||||||
}
|
}
|
||||||
export function forRefresh(refreshGroupRecord: RefreshGroupRecord): TaskId {
|
export function forRefresh(refreshGroupRecord: RefreshGroupRecord): TaskId {
|
||||||
return `${PendingTaskType.Refresh}:${refreshGroupRecord.refreshGroupId}` as TaskId;
|
return `${PendingTaskType.Refresh}:${refreshGroupRecord.refreshGroupId}` as TaskId;
|
||||||
|
@ -32,7 +32,7 @@ import {
|
|||||||
PeerPushPaymentIncomingStatus,
|
PeerPushPaymentIncomingStatus,
|
||||||
PeerPullPaymentInitiationStatus,
|
PeerPullPaymentInitiationStatus,
|
||||||
WithdrawalGroupStatus,
|
WithdrawalGroupStatus,
|
||||||
TipRecordStatus,
|
RewardRecordStatus,
|
||||||
DepositOperationStatus,
|
DepositOperationStatus,
|
||||||
} from "../db.js";
|
} from "../db.js";
|
||||||
import {
|
import {
|
||||||
@ -232,17 +232,17 @@ async function gatherDepositPending(
|
|||||||
async function gatherTipPending(
|
async function gatherTipPending(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
tx: GetReadOnlyAccess<{
|
tx: GetReadOnlyAccess<{
|
||||||
tips: typeof WalletStoresV1.tips;
|
rewards: typeof WalletStoresV1.rewards;
|
||||||
operationRetries: typeof WalletStoresV1.operationRetries;
|
operationRetries: typeof WalletStoresV1.operationRetries;
|
||||||
}>,
|
}>,
|
||||||
now: AbsoluteTime,
|
now: AbsoluteTime,
|
||||||
resp: PendingOperationsResponse,
|
resp: PendingOperationsResponse,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const range = GlobalIDB.KeyRange.bound(
|
const range = GlobalIDB.KeyRange.bound(
|
||||||
TipRecordStatus.PendingPickup,
|
RewardRecordStatus.PendingPickup,
|
||||||
TipRecordStatus.PendingPickup,
|
RewardRecordStatus.PendingPickup,
|
||||||
);
|
);
|
||||||
await tx.tips.indexes.byStatus.iter(range).forEachAsync(async (tip) => {
|
await tx.rewards.indexes.byStatus.iter(range).forEachAsync(async (tip) => {
|
||||||
// FIXME: The tip record needs a proper status field!
|
// FIXME: The tip record needs a proper status field!
|
||||||
if (tip.pickedUpTimestamp) {
|
if (tip.pickedUpTimestamp) {
|
||||||
return;
|
return;
|
||||||
@ -252,13 +252,13 @@ async function gatherTipPending(
|
|||||||
const timestampDue = retryRecord?.retryInfo.nextRetry ?? AbsoluteTime.now();
|
const timestampDue = retryRecord?.retryInfo.nextRetry ?? AbsoluteTime.now();
|
||||||
if (tip.acceptedTimestamp) {
|
if (tip.acceptedTimestamp) {
|
||||||
resp.pendingOperations.push({
|
resp.pendingOperations.push({
|
||||||
type: PendingTaskType.TipPickup,
|
type: PendingTaskType.RewardPickup,
|
||||||
...getPendingCommon(ws, opId, timestampDue),
|
...getPendingCommon(ws, opId, timestampDue),
|
||||||
givesLifeness: true,
|
givesLifeness: true,
|
||||||
timestampDue: retryRecord?.retryInfo.nextRetry ?? AbsoluteTime.now(),
|
timestampDue: retryRecord?.retryInfo.nextRetry ?? AbsoluteTime.now(),
|
||||||
merchantBaseUrl: tip.merchantBaseUrl,
|
merchantBaseUrl: tip.merchantBaseUrl,
|
||||||
tipId: tip.walletTipId,
|
tipId: tip.walletRewardId,
|
||||||
merchantTipId: tip.merchantTipId,
|
merchantTipId: tip.merchantRewardId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -494,7 +494,7 @@ export async function getPendingOperations(
|
|||||||
x.refreshGroups,
|
x.refreshGroups,
|
||||||
x.coins,
|
x.coins,
|
||||||
x.withdrawalGroups,
|
x.withdrawalGroups,
|
||||||
x.tips,
|
x.rewards,
|
||||||
x.purchases,
|
x.purchases,
|
||||||
x.planchets,
|
x.planchets,
|
||||||
x.depositGroups,
|
x.depositGroups,
|
||||||
|
@ -82,7 +82,7 @@ async function putGroupAsFinished(
|
|||||||
await tx.recoupGroups.put(recoupGroup);
|
await tx.recoupGroups.put(recoupGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function recoupTipCoin(
|
async function recoupRewardCoin(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
recoupGroupId: string,
|
recoupGroupId: string,
|
||||||
coinIdx: number,
|
coinIdx: number,
|
||||||
@ -482,8 +482,8 @@ async function processRecoup(
|
|||||||
const cs = coin.coinSource;
|
const cs = coin.coinSource;
|
||||||
|
|
||||||
switch (cs.type) {
|
switch (cs.type) {
|
||||||
case CoinSourceType.Tip:
|
case CoinSourceType.Reward:
|
||||||
return recoupTipCoin(ws, recoupGroupId, coinIdx, coin);
|
return recoupRewardCoin(ws, recoupGroupId, coinIdx, coin);
|
||||||
case CoinSourceType.Refresh:
|
case CoinSourceType.Refresh:
|
||||||
return recoupRefreshCoin(ws, recoupGroupId, coinIdx, coin, cs);
|
return recoupRefreshCoin(ws, recoupGroupId, coinIdx, coin, cs);
|
||||||
case CoinSourceType.Withdraw:
|
case CoinSourceType.Withdraw:
|
||||||
|
@ -48,8 +48,8 @@ import {
|
|||||||
CoinRecord,
|
CoinRecord,
|
||||||
CoinSourceType,
|
CoinSourceType,
|
||||||
DenominationRecord,
|
DenominationRecord,
|
||||||
TipRecord,
|
RewardRecord,
|
||||||
TipRecordStatus,
|
RewardRecordStatus,
|
||||||
} from "../db.js";
|
} from "../db.js";
|
||||||
import { makeErrorDetail } from "@gnu-taler/taler-util";
|
import { makeErrorDetail } from "@gnu-taler/taler-util";
|
||||||
import { InternalWalletState } from "../internal-wallet-state.js";
|
import { InternalWalletState } from "../internal-wallet-state.js";
|
||||||
@ -84,31 +84,31 @@ const logger = new Logger("operations/tip.ts");
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the (DD37-style) transaction status based on the
|
* Get the (DD37-style) transaction status based on the
|
||||||
* database record of a tip.
|
* database record of a reward.
|
||||||
*/
|
*/
|
||||||
export function computeTipTransactionStatus(
|
export function computeRewardTransactionStatus(
|
||||||
tipRecord: TipRecord,
|
tipRecord: RewardRecord,
|
||||||
): TransactionState {
|
): TransactionState {
|
||||||
switch (tipRecord.status) {
|
switch (tipRecord.status) {
|
||||||
case TipRecordStatus.Done:
|
case RewardRecordStatus.Done:
|
||||||
return {
|
return {
|
||||||
major: TransactionMajorState.Done,
|
major: TransactionMajorState.Done,
|
||||||
};
|
};
|
||||||
case TipRecordStatus.Aborted:
|
case RewardRecordStatus.Aborted:
|
||||||
return {
|
return {
|
||||||
major: TransactionMajorState.Aborted,
|
major: TransactionMajorState.Aborted,
|
||||||
};
|
};
|
||||||
case TipRecordStatus.PendingPickup:
|
case RewardRecordStatus.PendingPickup:
|
||||||
return {
|
return {
|
||||||
major: TransactionMajorState.Pending,
|
major: TransactionMajorState.Pending,
|
||||||
minor: TransactionMinorState.Pickup,
|
minor: TransactionMinorState.Pickup,
|
||||||
};
|
};
|
||||||
case TipRecordStatus.DialogAccept:
|
case RewardRecordStatus.DialogAccept:
|
||||||
return {
|
return {
|
||||||
major: TransactionMajorState.Dialog,
|
major: TransactionMajorState.Dialog,
|
||||||
minor: TransactionMinorState.Proposed,
|
minor: TransactionMinorState.Proposed,
|
||||||
};
|
};
|
||||||
case TipRecordStatus.SuspendidPickup:
|
case RewardRecordStatus.SuspendidPickup:
|
||||||
return {
|
return {
|
||||||
major: TransactionMajorState.Pending,
|
major: TransactionMajorState.Pending,
|
||||||
minor: TransactionMinorState.Pickup,
|
minor: TransactionMinorState.Pickup,
|
||||||
@ -119,18 +119,18 @@ export function computeTipTransactionStatus(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function computeTipTransactionActions(
|
export function computeTipTransactionActions(
|
||||||
tipRecord: TipRecord,
|
tipRecord: RewardRecord,
|
||||||
): TransactionAction[] {
|
): TransactionAction[] {
|
||||||
switch (tipRecord.status) {
|
switch (tipRecord.status) {
|
||||||
case TipRecordStatus.Done:
|
case RewardRecordStatus.Done:
|
||||||
return [TransactionAction.Delete];
|
return [TransactionAction.Delete];
|
||||||
case TipRecordStatus.Aborted:
|
case RewardRecordStatus.Aborted:
|
||||||
return [TransactionAction.Delete];
|
return [TransactionAction.Delete];
|
||||||
case TipRecordStatus.PendingPickup:
|
case RewardRecordStatus.PendingPickup:
|
||||||
return [TransactionAction.Suspend, TransactionAction.Fail];
|
return [TransactionAction.Suspend, TransactionAction.Fail];
|
||||||
case TipRecordStatus.SuspendidPickup:
|
case RewardRecordStatus.SuspendidPickup:
|
||||||
return [TransactionAction.Resume, TransactionAction.Fail];
|
return [TransactionAction.Resume, TransactionAction.Fail];
|
||||||
case TipRecordStatus.DialogAccept:
|
case RewardRecordStatus.DialogAccept:
|
||||||
return [TransactionAction.Abort];
|
return [TransactionAction.Abort];
|
||||||
default:
|
default:
|
||||||
assertUnreachable(tipRecord.status);
|
assertUnreachable(tipRecord.status);
|
||||||
@ -147,9 +147,9 @@ export async function prepareTip(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let tipRecord = await ws.db
|
let tipRecord = await ws.db
|
||||||
.mktx((x) => [x.tips])
|
.mktx((x) => [x.rewards])
|
||||||
.runReadOnly(async (tx) => {
|
.runReadOnly(async (tx) => {
|
||||||
return tx.tips.indexes.byMerchantTipIdAndBaseUrl.get([
|
return tx.rewards.indexes.byMerchantTipIdAndBaseUrl.get([
|
||||||
res.merchantTipId,
|
res.merchantTipId,
|
||||||
res.merchantBaseUrl,
|
res.merchantBaseUrl,
|
||||||
]);
|
]);
|
||||||
@ -194,44 +194,44 @@ export async function prepareTip(
|
|||||||
const secretSeed = encodeCrock(getRandomBytes(64));
|
const secretSeed = encodeCrock(getRandomBytes(64));
|
||||||
const denomSelUid = encodeCrock(getRandomBytes(32));
|
const denomSelUid = encodeCrock(getRandomBytes(32));
|
||||||
|
|
||||||
const newTipRecord: TipRecord = {
|
const newTipRecord: RewardRecord = {
|
||||||
walletTipId: walletTipId,
|
walletRewardId: walletTipId,
|
||||||
acceptedTimestamp: undefined,
|
acceptedTimestamp: undefined,
|
||||||
status: TipRecordStatus.DialogAccept,
|
status: RewardRecordStatus.DialogAccept,
|
||||||
tipAmountRaw: Amounts.stringify(amount),
|
rewardAmountRaw: Amounts.stringify(amount),
|
||||||
tipExpiration: tipPickupStatus.expiration,
|
rewardExpiration: tipPickupStatus.expiration,
|
||||||
exchangeBaseUrl: tipPickupStatus.exchange_url,
|
exchangeBaseUrl: tipPickupStatus.exchange_url,
|
||||||
next_url: tipPickupStatus.next_url,
|
next_url: tipPickupStatus.next_url,
|
||||||
merchantBaseUrl: res.merchantBaseUrl,
|
merchantBaseUrl: res.merchantBaseUrl,
|
||||||
createdTimestamp: TalerPreciseTimestamp.now(),
|
createdTimestamp: TalerPreciseTimestamp.now(),
|
||||||
merchantTipId: res.merchantTipId,
|
merchantRewardId: res.merchantTipId,
|
||||||
tipAmountEffective: Amounts.stringify(selectedDenoms.totalCoinValue),
|
rewardAmountEffective: Amounts.stringify(selectedDenoms.totalCoinValue),
|
||||||
denomsSel: selectedDenoms,
|
denomsSel: selectedDenoms,
|
||||||
pickedUpTimestamp: undefined,
|
pickedUpTimestamp: undefined,
|
||||||
secretSeed,
|
secretSeed,
|
||||||
denomSelUid,
|
denomSelUid,
|
||||||
};
|
};
|
||||||
await ws.db
|
await ws.db
|
||||||
.mktx((x) => [x.tips])
|
.mktx((x) => [x.rewards])
|
||||||
.runReadWrite(async (tx) => {
|
.runReadWrite(async (tx) => {
|
||||||
await tx.tips.put(newTipRecord);
|
await tx.rewards.put(newTipRecord);
|
||||||
});
|
});
|
||||||
tipRecord = newTipRecord;
|
tipRecord = newTipRecord;
|
||||||
}
|
}
|
||||||
|
|
||||||
const transactionId = constructTransactionIdentifier({
|
const transactionId = constructTransactionIdentifier({
|
||||||
tag: TransactionType.Tip,
|
tag: TransactionType.Reward,
|
||||||
walletTipId: tipRecord.walletTipId,
|
walletRewardId: tipRecord.walletRewardId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const tipStatus: PrepareTipResult = {
|
const tipStatus: PrepareTipResult = {
|
||||||
accepted: !!tipRecord && !!tipRecord.acceptedTimestamp,
|
accepted: !!tipRecord && !!tipRecord.acceptedTimestamp,
|
||||||
tipAmountRaw: Amounts.stringify(tipRecord.tipAmountRaw),
|
rewardAmountRaw: Amounts.stringify(tipRecord.rewardAmountRaw),
|
||||||
exchangeBaseUrl: tipRecord.exchangeBaseUrl,
|
exchangeBaseUrl: tipRecord.exchangeBaseUrl,
|
||||||
merchantBaseUrl: tipRecord.merchantBaseUrl,
|
merchantBaseUrl: tipRecord.merchantBaseUrl,
|
||||||
expirationTimestamp: tipRecord.tipExpiration,
|
expirationTimestamp: tipRecord.rewardExpiration,
|
||||||
tipAmountEffective: Amounts.stringify(tipRecord.tipAmountEffective),
|
rewardAmountEffective: Amounts.stringify(tipRecord.rewardAmountEffective),
|
||||||
walletTipId: tipRecord.walletTipId,
|
walletRewardId: tipRecord.walletRewardId,
|
||||||
transactionId,
|
transactionId,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -243,25 +243,25 @@ export async function processTip(
|
|||||||
walletTipId: string,
|
walletTipId: string,
|
||||||
): Promise<TaskRunResult> {
|
): Promise<TaskRunResult> {
|
||||||
const tipRecord = await ws.db
|
const tipRecord = await ws.db
|
||||||
.mktx((x) => [x.tips])
|
.mktx((x) => [x.rewards])
|
||||||
.runReadOnly(async (tx) => {
|
.runReadOnly(async (tx) => {
|
||||||
return tx.tips.get(walletTipId);
|
return tx.rewards.get(walletTipId);
|
||||||
});
|
});
|
||||||
if (!tipRecord) {
|
if (!tipRecord) {
|
||||||
return TaskRunResult.finished();
|
return TaskRunResult.finished();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (tipRecord.status) {
|
switch (tipRecord.status) {
|
||||||
case TipRecordStatus.Aborted:
|
case RewardRecordStatus.Aborted:
|
||||||
case TipRecordStatus.DialogAccept:
|
case RewardRecordStatus.DialogAccept:
|
||||||
case TipRecordStatus.Done:
|
case RewardRecordStatus.Done:
|
||||||
case TipRecordStatus.SuspendidPickup:
|
case RewardRecordStatus.SuspendidPickup:
|
||||||
return TaskRunResult.finished();
|
return TaskRunResult.finished();
|
||||||
}
|
}
|
||||||
|
|
||||||
const transactionId = constructTransactionIdentifier({
|
const transactionId = constructTransactionIdentifier({
|
||||||
tag: TransactionType.Tip,
|
tag: TransactionType.Reward,
|
||||||
walletTipId,
|
walletRewardId: walletTipId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const denomsForWithdraw = tipRecord.denomsSel;
|
const denomsForWithdraw = tipRecord.denomsSel;
|
||||||
@ -300,7 +300,7 @@ export async function processTip(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const tipStatusUrl = new URL(
|
const tipStatusUrl = new URL(
|
||||||
`tips/${tipRecord.merchantTipId}/pickup`,
|
`tips/${tipRecord.merchantRewardId}/pickup`,
|
||||||
tipRecord.merchantBaseUrl,
|
tipRecord.merchantBaseUrl,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -384,9 +384,9 @@ export async function processTip(
|
|||||||
coinPriv: planchet.coinPriv,
|
coinPriv: planchet.coinPriv,
|
||||||
coinPub: planchet.coinPub,
|
coinPub: planchet.coinPub,
|
||||||
coinSource: {
|
coinSource: {
|
||||||
type: CoinSourceType.Tip,
|
type: CoinSourceType.Reward,
|
||||||
coinIndex: i,
|
coinIndex: i,
|
||||||
walletTipId: walletTipId,
|
walletRewardId: walletTipId,
|
||||||
},
|
},
|
||||||
sourceTransactionId: transactionId,
|
sourceTransactionId: transactionId,
|
||||||
denomPubHash: denom.denomPubHash,
|
denomPubHash: denom.denomPubHash,
|
||||||
@ -401,20 +401,20 @@ export async function processTip(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const transitionInfo = await ws.db
|
const transitionInfo = await ws.db
|
||||||
.mktx((x) => [x.coins, x.coinAvailability, x.denominations, x.tips])
|
.mktx((x) => [x.coins, x.coinAvailability, x.denominations, x.rewards])
|
||||||
.runReadWrite(async (tx) => {
|
.runReadWrite(async (tx) => {
|
||||||
const tr = await tx.tips.get(walletTipId);
|
const tr = await tx.rewards.get(walletTipId);
|
||||||
if (!tr) {
|
if (!tr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (tr.status !== TipRecordStatus.PendingPickup) {
|
if (tr.status !== RewardRecordStatus.PendingPickup) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const oldTxState = computeTipTransactionStatus(tr);
|
const oldTxState = computeRewardTransactionStatus(tr);
|
||||||
tr.pickedUpTimestamp = TalerPreciseTimestamp.now();
|
tr.pickedUpTimestamp = TalerPreciseTimestamp.now();
|
||||||
tr.status = TipRecordStatus.Done;
|
tr.status = RewardRecordStatus.Done;
|
||||||
await tx.tips.put(tr);
|
await tx.rewards.put(tr);
|
||||||
const newTxState = computeTipTransactionStatus(tr);
|
const newTxState = computeRewardTransactionStatus(tr);
|
||||||
for (const cr of newCoinRecords) {
|
for (const cr of newCoinRecords) {
|
||||||
await makeCoinAvailable(ws, tx, cr);
|
await makeCoinAvailable(ws, tx, cr);
|
||||||
}
|
}
|
||||||
@ -432,26 +432,26 @@ export async function acceptTip(
|
|||||||
walletTipId: string,
|
walletTipId: string,
|
||||||
): Promise<AcceptTipResponse> {
|
): Promise<AcceptTipResponse> {
|
||||||
const transactionId = constructTransactionIdentifier({
|
const transactionId = constructTransactionIdentifier({
|
||||||
tag: TransactionType.Tip,
|
tag: TransactionType.Reward,
|
||||||
walletTipId,
|
walletRewardId: walletTipId,
|
||||||
});
|
});
|
||||||
const dbRes = await ws.db
|
const dbRes = await ws.db
|
||||||
.mktx((x) => [x.tips])
|
.mktx((x) => [x.rewards])
|
||||||
.runReadWrite(async (tx) => {
|
.runReadWrite(async (tx) => {
|
||||||
const tipRecord = await tx.tips.get(walletTipId);
|
const tipRecord = await tx.rewards.get(walletTipId);
|
||||||
if (!tipRecord) {
|
if (!tipRecord) {
|
||||||
logger.error("tip not found");
|
logger.error("tip not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (tipRecord.status != TipRecordStatus.DialogAccept) {
|
if (tipRecord.status != RewardRecordStatus.DialogAccept) {
|
||||||
logger.warn("Unable to accept tip in the current state");
|
logger.warn("Unable to accept tip in the current state");
|
||||||
return { tipRecord };
|
return { tipRecord };
|
||||||
}
|
}
|
||||||
const oldTxState = computeTipTransactionStatus(tipRecord);
|
const oldTxState = computeRewardTransactionStatus(tipRecord);
|
||||||
tipRecord.acceptedTimestamp = TalerPreciseTimestamp.now();
|
tipRecord.acceptedTimestamp = TalerPreciseTimestamp.now();
|
||||||
tipRecord.status = TipRecordStatus.PendingPickup;
|
tipRecord.status = RewardRecordStatus.PendingPickup;
|
||||||
await tx.tips.put(tipRecord);
|
await tx.rewards.put(tipRecord);
|
||||||
const newTxState = computeTipTransactionStatus(tipRecord);
|
const newTxState = computeRewardTransactionStatus(tipRecord);
|
||||||
return { tipRecord, transitionInfo: { oldTxState, newTxState } };
|
return { tipRecord, transitionInfo: { oldTxState, newTxState } };
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -465,53 +465,53 @@ export async function acceptTip(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
transactionId: constructTransactionIdentifier({
|
transactionId: constructTransactionIdentifier({
|
||||||
tag: TransactionType.Tip,
|
tag: TransactionType.Reward,
|
||||||
walletTipId: walletTipId,
|
walletRewardId: walletTipId,
|
||||||
}),
|
}),
|
||||||
next_url: tipRecord.next_url,
|
next_url: tipRecord.next_url,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function suspendTipTransaction(
|
export async function suspendRewardTransaction(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
walletTipId: string,
|
walletRewardId: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const taskId = constructTaskIdentifier({
|
const taskId = constructTaskIdentifier({
|
||||||
tag: PendingTaskType.TipPickup,
|
tag: PendingTaskType.RewardPickup,
|
||||||
walletTipId,
|
walletRewardId: walletRewardId,
|
||||||
});
|
});
|
||||||
const transactionId = constructTransactionIdentifier({
|
const transactionId = constructTransactionIdentifier({
|
||||||
tag: TransactionType.Tip,
|
tag: TransactionType.Reward,
|
||||||
walletTipId,
|
walletRewardId: walletRewardId,
|
||||||
});
|
});
|
||||||
stopLongpolling(ws, taskId);
|
stopLongpolling(ws, taskId);
|
||||||
const transitionInfo = await ws.db
|
const transitionInfo = await ws.db
|
||||||
.mktx((x) => [x.tips])
|
.mktx((x) => [x.rewards])
|
||||||
.runReadWrite(async (tx) => {
|
.runReadWrite(async (tx) => {
|
||||||
const tipRec = await tx.tips.get(walletTipId);
|
const tipRec = await tx.rewards.get(walletRewardId);
|
||||||
if (!tipRec) {
|
if (!tipRec) {
|
||||||
logger.warn(`transaction tip ${walletTipId} not found`);
|
logger.warn(`transaction tip ${walletRewardId} not found`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let newStatus: TipRecordStatus | undefined = undefined;
|
let newStatus: RewardRecordStatus | undefined = undefined;
|
||||||
switch (tipRec.status) {
|
switch (tipRec.status) {
|
||||||
case TipRecordStatus.Done:
|
case RewardRecordStatus.Done:
|
||||||
case TipRecordStatus.SuspendidPickup:
|
case RewardRecordStatus.SuspendidPickup:
|
||||||
case TipRecordStatus.Aborted:
|
case RewardRecordStatus.Aborted:
|
||||||
case TipRecordStatus.DialogAccept:
|
case RewardRecordStatus.DialogAccept:
|
||||||
break;
|
break;
|
||||||
case TipRecordStatus.PendingPickup:
|
case RewardRecordStatus.PendingPickup:
|
||||||
newStatus = TipRecordStatus.SuspendidPickup;
|
newStatus = RewardRecordStatus.SuspendidPickup;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assertUnreachable(tipRec.status);
|
assertUnreachable(tipRec.status);
|
||||||
}
|
}
|
||||||
if (newStatus != null) {
|
if (newStatus != null) {
|
||||||
const oldTxState = computeTipTransactionStatus(tipRec);
|
const oldTxState = computeRewardTransactionStatus(tipRec);
|
||||||
tipRec.status = newStatus;
|
tipRec.status = newStatus;
|
||||||
const newTxState = computeTipTransactionStatus(tipRec);
|
const newTxState = computeRewardTransactionStatus(tipRec);
|
||||||
await tx.tips.put(tipRec);
|
await tx.rewards.put(tipRec);
|
||||||
return {
|
return {
|
||||||
oldTxState,
|
oldTxState,
|
||||||
newTxState,
|
newTxState,
|
||||||
@ -525,43 +525,43 @@ export async function suspendTipTransaction(
|
|||||||
|
|
||||||
export async function resumeTipTransaction(
|
export async function resumeTipTransaction(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
walletTipId: string,
|
walletRewardId: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const taskId = constructTaskIdentifier({
|
const taskId = constructTaskIdentifier({
|
||||||
tag: PendingTaskType.TipPickup,
|
tag: PendingTaskType.RewardPickup,
|
||||||
walletTipId,
|
walletRewardId: walletRewardId,
|
||||||
});
|
});
|
||||||
const transactionId = constructTransactionIdentifier({
|
const transactionId = constructTransactionIdentifier({
|
||||||
tag: TransactionType.Tip,
|
tag: TransactionType.Reward,
|
||||||
walletTipId,
|
walletRewardId: walletRewardId,
|
||||||
});
|
});
|
||||||
stopLongpolling(ws, taskId);
|
stopLongpolling(ws, taskId);
|
||||||
const transitionInfo = await ws.db
|
const transitionInfo = await ws.db
|
||||||
.mktx((x) => [x.tips])
|
.mktx((x) => [x.rewards])
|
||||||
.runReadWrite(async (tx) => {
|
.runReadWrite(async (tx) => {
|
||||||
const tipRec = await tx.tips.get(walletTipId);
|
const rewardRec = await tx.rewards.get(walletRewardId);
|
||||||
if (!tipRec) {
|
if (!rewardRec) {
|
||||||
logger.warn(`transaction tip ${walletTipId} not found`);
|
logger.warn(`transaction reward ${walletRewardId} not found`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let newStatus: TipRecordStatus | undefined = undefined;
|
let newStatus: RewardRecordStatus | undefined = undefined;
|
||||||
switch (tipRec.status) {
|
switch (rewardRec.status) {
|
||||||
case TipRecordStatus.Done:
|
case RewardRecordStatus.Done:
|
||||||
case TipRecordStatus.PendingPickup:
|
case RewardRecordStatus.PendingPickup:
|
||||||
case TipRecordStatus.Aborted:
|
case RewardRecordStatus.Aborted:
|
||||||
case TipRecordStatus.DialogAccept:
|
case RewardRecordStatus.DialogAccept:
|
||||||
break;
|
break;
|
||||||
case TipRecordStatus.SuspendidPickup:
|
case RewardRecordStatus.SuspendidPickup:
|
||||||
newStatus = TipRecordStatus.PendingPickup;
|
newStatus = RewardRecordStatus.PendingPickup;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assertUnreachable(tipRec.status);
|
assertUnreachable(rewardRec.status);
|
||||||
}
|
}
|
||||||
if (newStatus != null) {
|
if (newStatus != null) {
|
||||||
const oldTxState = computeTipTransactionStatus(tipRec);
|
const oldTxState = computeRewardTransactionStatus(rewardRec);
|
||||||
tipRec.status = newStatus;
|
rewardRec.status = newStatus;
|
||||||
const newTxState = computeTipTransactionStatus(tipRec);
|
const newTxState = computeRewardTransactionStatus(rewardRec);
|
||||||
await tx.tips.put(tipRec);
|
await tx.rewards.put(rewardRec);
|
||||||
return {
|
return {
|
||||||
oldTxState,
|
oldTxState,
|
||||||
newTxState,
|
newTxState,
|
||||||
@ -582,43 +582,43 @@ export async function failTipTransaction(
|
|||||||
|
|
||||||
export async function abortTipTransaction(
|
export async function abortTipTransaction(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
walletTipId: string,
|
walletRewardId: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const taskId = constructTaskIdentifier({
|
const taskId = constructTaskIdentifier({
|
||||||
tag: PendingTaskType.TipPickup,
|
tag: PendingTaskType.RewardPickup,
|
||||||
walletTipId,
|
walletRewardId: walletRewardId,
|
||||||
});
|
});
|
||||||
const transactionId = constructTransactionIdentifier({
|
const transactionId = constructTransactionIdentifier({
|
||||||
tag: TransactionType.Tip,
|
tag: TransactionType.Reward,
|
||||||
walletTipId,
|
walletRewardId: walletRewardId,
|
||||||
});
|
});
|
||||||
stopLongpolling(ws, taskId);
|
stopLongpolling(ws, taskId);
|
||||||
const transitionInfo = await ws.db
|
const transitionInfo = await ws.db
|
||||||
.mktx((x) => [x.tips])
|
.mktx((x) => [x.rewards])
|
||||||
.runReadWrite(async (tx) => {
|
.runReadWrite(async (tx) => {
|
||||||
const tipRec = await tx.tips.get(walletTipId);
|
const tipRec = await tx.rewards.get(walletRewardId);
|
||||||
if (!tipRec) {
|
if (!tipRec) {
|
||||||
logger.warn(`transaction tip ${walletTipId} not found`);
|
logger.warn(`transaction tip ${walletRewardId} not found`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let newStatus: TipRecordStatus | undefined = undefined;
|
let newStatus: RewardRecordStatus | undefined = undefined;
|
||||||
switch (tipRec.status) {
|
switch (tipRec.status) {
|
||||||
case TipRecordStatus.Done:
|
case RewardRecordStatus.Done:
|
||||||
case TipRecordStatus.Aborted:
|
case RewardRecordStatus.Aborted:
|
||||||
case TipRecordStatus.PendingPickup:
|
case RewardRecordStatus.PendingPickup:
|
||||||
case TipRecordStatus.DialogAccept:
|
case RewardRecordStatus.DialogAccept:
|
||||||
break;
|
break;
|
||||||
case TipRecordStatus.SuspendidPickup:
|
case RewardRecordStatus.SuspendidPickup:
|
||||||
newStatus = TipRecordStatus.Aborted;
|
newStatus = RewardRecordStatus.Aborted;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assertUnreachable(tipRec.status);
|
assertUnreachable(tipRec.status);
|
||||||
}
|
}
|
||||||
if (newStatus != null) {
|
if (newStatus != null) {
|
||||||
const oldTxState = computeTipTransactionStatus(tipRec);
|
const oldTxState = computeRewardTransactionStatus(tipRec);
|
||||||
tipRec.status = newStatus;
|
tipRec.status = newStatus;
|
||||||
const newTxState = computeTipTransactionStatus(tipRec);
|
const newTxState = computeRewardTransactionStatus(tipRec);
|
||||||
await tx.tips.put(tipRec);
|
await tx.rewards.put(tipRec);
|
||||||
return {
|
return {
|
||||||
oldTxState,
|
oldTxState,
|
||||||
newTxState,
|
newTxState,
|
@ -58,7 +58,7 @@ import {
|
|||||||
RefreshGroupRecord,
|
RefreshGroupRecord,
|
||||||
RefreshOperationStatus,
|
RefreshOperationStatus,
|
||||||
RefundGroupRecord,
|
RefundGroupRecord,
|
||||||
TipRecord,
|
RewardRecord,
|
||||||
WalletContractData,
|
WalletContractData,
|
||||||
WithdrawalGroupRecord,
|
WithdrawalGroupRecord,
|
||||||
WithdrawalGroupStatus,
|
WithdrawalGroupStatus,
|
||||||
@ -107,11 +107,11 @@ import {
|
|||||||
import {
|
import {
|
||||||
abortTipTransaction,
|
abortTipTransaction,
|
||||||
failTipTransaction,
|
failTipTransaction,
|
||||||
computeTipTransactionStatus,
|
computeRewardTransactionStatus,
|
||||||
resumeTipTransaction,
|
resumeTipTransaction,
|
||||||
suspendTipTransaction,
|
suspendRewardTransaction,
|
||||||
computeTipTransactionActions,
|
computeTipTransactionActions,
|
||||||
} from "./tip.js";
|
} from "./reward.js";
|
||||||
import {
|
import {
|
||||||
abortWithdrawalTransaction,
|
abortWithdrawalTransaction,
|
||||||
augmentPaytoUrisForWithdrawal,
|
augmentPaytoUrisForWithdrawal,
|
||||||
@ -187,7 +187,7 @@ function shouldSkipSearch(
|
|||||||
*/
|
*/
|
||||||
const txOrder: { [t in TransactionType]: number } = {
|
const txOrder: { [t in TransactionType]: number } = {
|
||||||
[TransactionType.Withdrawal]: 1,
|
[TransactionType.Withdrawal]: 1,
|
||||||
[TransactionType.Tip]: 2,
|
[TransactionType.Reward]: 2,
|
||||||
[TransactionType.Payment]: 3,
|
[TransactionType.Payment]: 3,
|
||||||
[TransactionType.PeerPullCredit]: 4,
|
[TransactionType.PeerPullCredit]: 4,
|
||||||
[TransactionType.PeerPullDebit]: 5,
|
[TransactionType.PeerPullDebit]: 5,
|
||||||
@ -284,12 +284,12 @@ export async function getTransactionById(
|
|||||||
throw Error(`no tx for refresh`);
|
throw Error(`no tx for refresh`);
|
||||||
}
|
}
|
||||||
|
|
||||||
case TransactionType.Tip: {
|
case TransactionType.Reward: {
|
||||||
const tipId = parsedTx.walletTipId;
|
const tipId = parsedTx.walletRewardId;
|
||||||
return await ws.db
|
return await ws.db
|
||||||
.mktx((x) => [x.tips, x.operationRetries])
|
.mktx((x) => [x.rewards, x.operationRetries])
|
||||||
.runReadWrite(async (tx) => {
|
.runReadWrite(async (tx) => {
|
||||||
const tipRecord = await tx.tips.get(tipId);
|
const tipRecord = await tx.rewards.get(tipId);
|
||||||
if (!tipRecord) throw Error("not found");
|
if (!tipRecord) throw Error("not found");
|
||||||
|
|
||||||
const retries = await tx.operationRetries.get(
|
const retries = await tx.operationRetries.get(
|
||||||
@ -818,21 +818,21 @@ function buildTransactionForDeposit(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildTransactionForTip(
|
function buildTransactionForTip(
|
||||||
tipRecord: TipRecord,
|
tipRecord: RewardRecord,
|
||||||
ort?: OperationRetryRecord,
|
ort?: OperationRetryRecord,
|
||||||
): Transaction {
|
): Transaction {
|
||||||
checkLogicInvariant(!!tipRecord.acceptedTimestamp);
|
checkLogicInvariant(!!tipRecord.acceptedTimestamp);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: TransactionType.Tip,
|
type: TransactionType.Reward,
|
||||||
txState: computeTipTransactionStatus(tipRecord),
|
txState: computeRewardTransactionStatus(tipRecord),
|
||||||
txActions: computeTipTransactionActions(tipRecord),
|
txActions: computeTipTransactionActions(tipRecord),
|
||||||
amountEffective: Amounts.stringify(tipRecord.tipAmountEffective),
|
amountEffective: Amounts.stringify(tipRecord.rewardAmountEffective),
|
||||||
amountRaw: Amounts.stringify(tipRecord.tipAmountRaw),
|
amountRaw: Amounts.stringify(tipRecord.rewardAmountRaw),
|
||||||
timestamp: tipRecord.acceptedTimestamp,
|
timestamp: tipRecord.acceptedTimestamp,
|
||||||
transactionId: constructTransactionIdentifier({
|
transactionId: constructTransactionIdentifier({
|
||||||
tag: TransactionType.Tip,
|
tag: TransactionType.Reward,
|
||||||
walletTipId: tipRecord.walletTipId,
|
walletRewardId: tipRecord.walletRewardId,
|
||||||
}),
|
}),
|
||||||
merchantBaseUrl: tipRecord.merchantBaseUrl,
|
merchantBaseUrl: tipRecord.merchantBaseUrl,
|
||||||
...(ort?.lastError ? { error: ort.lastError } : {}),
|
...(ort?.lastError ? { error: ort.lastError } : {}),
|
||||||
@ -945,7 +945,7 @@ export async function getTransactions(
|
|||||||
x.purchases,
|
x.purchases,
|
||||||
x.contractTerms,
|
x.contractTerms,
|
||||||
x.recoupGroups,
|
x.recoupGroups,
|
||||||
x.tips,
|
x.rewards,
|
||||||
x.tombstones,
|
x.tombstones,
|
||||||
x.withdrawalGroups,
|
x.withdrawalGroups,
|
||||||
x.refreshGroups,
|
x.refreshGroups,
|
||||||
@ -1200,11 +1200,11 @@ export async function getTransactions(
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
tx.tips.iter().forEachAsync(async (tipRecord) => {
|
tx.rewards.iter().forEachAsync(async (tipRecord) => {
|
||||||
if (
|
if (
|
||||||
shouldSkipCurrency(
|
shouldSkipCurrency(
|
||||||
transactionsRequest,
|
transactionsRequest,
|
||||||
Amounts.parseOrThrow(tipRecord.tipAmountRaw).currency,
|
Amounts.parseOrThrow(tipRecord.rewardAmountRaw).currency,
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
@ -1267,7 +1267,7 @@ export type ParsedTransactionIdentifier =
|
|||||||
| { tag: TransactionType.PeerPushDebit; pursePub: string }
|
| { tag: TransactionType.PeerPushDebit; pursePub: string }
|
||||||
| { tag: TransactionType.Refresh; refreshGroupId: string }
|
| { tag: TransactionType.Refresh; refreshGroupId: string }
|
||||||
| { tag: TransactionType.Refund; refundGroupId: string }
|
| { tag: TransactionType.Refund; refundGroupId: string }
|
||||||
| { tag: TransactionType.Tip; walletTipId: string }
|
| { tag: TransactionType.Reward; walletRewardId: string }
|
||||||
| { tag: TransactionType.Withdrawal; withdrawalGroupId: string }
|
| { tag: TransactionType.Withdrawal; withdrawalGroupId: string }
|
||||||
| { tag: TransactionType.InternalWithdrawal; withdrawalGroupId: string };
|
| { tag: TransactionType.InternalWithdrawal; withdrawalGroupId: string };
|
||||||
|
|
||||||
@ -1291,8 +1291,8 @@ export function constructTransactionIdentifier(
|
|||||||
return `txn:${pTxId.tag}:${pTxId.refreshGroupId}` as TransactionIdStr;
|
return `txn:${pTxId.tag}:${pTxId.refreshGroupId}` as TransactionIdStr;
|
||||||
case TransactionType.Refund:
|
case TransactionType.Refund:
|
||||||
return `txn:${pTxId.tag}:${pTxId.refundGroupId}` as TransactionIdStr;
|
return `txn:${pTxId.tag}:${pTxId.refundGroupId}` as TransactionIdStr;
|
||||||
case TransactionType.Tip:
|
case TransactionType.Reward:
|
||||||
return `txn:${pTxId.tag}:${pTxId.walletTipId}` as TransactionIdStr;
|
return `txn:${pTxId.tag}:${pTxId.walletRewardId}` as TransactionIdStr;
|
||||||
case TransactionType.Withdrawal:
|
case TransactionType.Withdrawal:
|
||||||
return `txn:${pTxId.tag}:${pTxId.withdrawalGroupId}` as TransactionIdStr;
|
return `txn:${pTxId.tag}:${pTxId.withdrawalGroupId}` as TransactionIdStr;
|
||||||
case TransactionType.InternalWithdrawal:
|
case TransactionType.InternalWithdrawal:
|
||||||
@ -1346,10 +1346,10 @@ export function parseTransactionIdentifier(
|
|||||||
tag: TransactionType.Refund,
|
tag: TransactionType.Refund,
|
||||||
refundGroupId: rest[0],
|
refundGroupId: rest[0],
|
||||||
};
|
};
|
||||||
case TransactionType.Tip:
|
case TransactionType.Reward:
|
||||||
return {
|
return {
|
||||||
tag: TransactionType.Tip,
|
tag: TransactionType.Reward,
|
||||||
walletTipId: rest[0],
|
walletRewardId: rest[0],
|
||||||
};
|
};
|
||||||
case TransactionType.Withdrawal:
|
case TransactionType.Withdrawal:
|
||||||
return {
|
return {
|
||||||
@ -1427,10 +1427,10 @@ export async function retryTransaction(
|
|||||||
stopLongpolling(ws, taskId);
|
stopLongpolling(ws, taskId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TransactionType.Tip: {
|
case TransactionType.Reward: {
|
||||||
const taskId = constructTaskIdentifier({
|
const taskId = constructTaskIdentifier({
|
||||||
tag: PendingTaskType.TipPickup,
|
tag: PendingTaskType.RewardPickup,
|
||||||
walletTipId: parsedTx.walletTipId,
|
walletRewardId: parsedTx.walletRewardId,
|
||||||
});
|
});
|
||||||
await resetPendingTaskTimeout(ws, taskId);
|
await resetPendingTaskTimeout(ws, taskId);
|
||||||
stopLongpolling(ws, taskId);
|
stopLongpolling(ws, taskId);
|
||||||
@ -1522,8 +1522,8 @@ export async function suspendTransaction(
|
|||||||
break;
|
break;
|
||||||
case TransactionType.Refund:
|
case TransactionType.Refund:
|
||||||
throw Error("refund transactions can't be suspended or resumed");
|
throw Error("refund transactions can't be suspended or resumed");
|
||||||
case TransactionType.Tip:
|
case TransactionType.Reward:
|
||||||
await suspendTipTransaction(ws, tx.walletTipId);
|
await suspendRewardTransaction(ws, tx.walletRewardId);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assertUnreachable(tx);
|
assertUnreachable(tx);
|
||||||
@ -1551,8 +1551,8 @@ export async function failTransaction(
|
|||||||
return;
|
return;
|
||||||
case TransactionType.Refund:
|
case TransactionType.Refund:
|
||||||
throw Error("can't do cancel-aborting on refund transaction");
|
throw Error("can't do cancel-aborting on refund transaction");
|
||||||
case TransactionType.Tip:
|
case TransactionType.Reward:
|
||||||
await failTipTransaction(ws, tx.walletTipId);
|
await failTipTransaction(ws, tx.walletRewardId);
|
||||||
return;
|
return;
|
||||||
case TransactionType.Refresh:
|
case TransactionType.Refresh:
|
||||||
await failRefreshGroup(ws, tx.refreshGroupId);
|
await failRefreshGroup(ws, tx.refreshGroupId);
|
||||||
@ -1613,8 +1613,8 @@ export async function resumeTransaction(
|
|||||||
break;
|
break;
|
||||||
case TransactionType.Refund:
|
case TransactionType.Refund:
|
||||||
throw Error("refund transactions can't be suspended or resumed");
|
throw Error("refund transactions can't be suspended or resumed");
|
||||||
case TransactionType.Tip:
|
case TransactionType.Reward:
|
||||||
await resumeTipTransaction(ws, tx.walletTipId);
|
await resumeTipTransaction(ws, tx.walletRewardId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1763,16 +1763,16 @@ export async function deleteTransaction(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TransactionType.Tip: {
|
case TransactionType.Reward: {
|
||||||
const tipId = parsedTx.walletTipId;
|
const tipId = parsedTx.walletRewardId;
|
||||||
await ws.db
|
await ws.db
|
||||||
.mktx((x) => [x.tips, x.tombstones])
|
.mktx((x) => [x.rewards, x.tombstones])
|
||||||
.runReadWrite(async (tx) => {
|
.runReadWrite(async (tx) => {
|
||||||
const tipRecord = await tx.tips.get(tipId);
|
const tipRecord = await tx.rewards.get(tipId);
|
||||||
if (tipRecord) {
|
if (tipRecord) {
|
||||||
await tx.tips.delete(tipId);
|
await tx.rewards.delete(tipId);
|
||||||
await tx.tombstones.put({
|
await tx.tombstones.put({
|
||||||
id: TombstoneTag.DeleteTip + ":" + tipId,
|
id: TombstoneTag.DeleteReward + ":" + tipId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -1856,8 +1856,8 @@ export async function abortTransaction(
|
|||||||
case TransactionType.Deposit:
|
case TransactionType.Deposit:
|
||||||
await abortDepositGroup(ws, txId.depositGroupId);
|
await abortDepositGroup(ws, txId.depositGroupId);
|
||||||
break;
|
break;
|
||||||
case TransactionType.Tip:
|
case TransactionType.Reward:
|
||||||
await abortTipTransaction(ws, txId.walletTipId);
|
await abortTipTransaction(ws, txId.walletRewardId);
|
||||||
break;
|
break;
|
||||||
case TransactionType.Refund:
|
case TransactionType.Refund:
|
||||||
throw Error("can't abort refund transactions");
|
throw Error("can't abort refund transactions");
|
||||||
|
@ -33,7 +33,7 @@ export enum PendingTaskType {
|
|||||||
Purchase = "purchase",
|
Purchase = "purchase",
|
||||||
Refresh = "refresh",
|
Refresh = "refresh",
|
||||||
Recoup = "recoup",
|
Recoup = "recoup",
|
||||||
TipPickup = "tip-pickup",
|
RewardPickup = "reward-pickup",
|
||||||
Withdraw = "withdraw",
|
Withdraw = "withdraw",
|
||||||
Deposit = "deposit",
|
Deposit = "deposit",
|
||||||
Backup = "backup",
|
Backup = "backup",
|
||||||
@ -144,7 +144,7 @@ export interface PendingRefreshTask {
|
|||||||
* The wallet is picking up a tip that the user has accepted.
|
* The wallet is picking up a tip that the user has accepted.
|
||||||
*/
|
*/
|
||||||
export interface PendingTipPickupTask {
|
export interface PendingTipPickupTask {
|
||||||
type: PendingTaskType.TipPickup;
|
type: PendingTaskType.RewardPickup;
|
||||||
tipId: string;
|
tipId: string;
|
||||||
merchantBaseUrl: string;
|
merchantBaseUrl: string;
|
||||||
merchantTipId: string;
|
merchantTipId: string;
|
||||||
|
@ -29,7 +29,7 @@ import {
|
|||||||
AcceptExchangeTosRequest,
|
AcceptExchangeTosRequest,
|
||||||
AcceptManualWithdrawalRequest,
|
AcceptManualWithdrawalRequest,
|
||||||
AcceptManualWithdrawalResult,
|
AcceptManualWithdrawalResult,
|
||||||
AcceptTipRequest,
|
AcceptRewardRequest,
|
||||||
AcceptTipResponse,
|
AcceptTipResponse,
|
||||||
AcceptWithdrawalResponse,
|
AcceptWithdrawalResponse,
|
||||||
AddExchangeRequest,
|
AddExchangeRequest,
|
||||||
@ -85,8 +85,8 @@ import {
|
|||||||
PreparePeerPushCreditRequest,
|
PreparePeerPushCreditRequest,
|
||||||
PreparePeerPushCreditResponse,
|
PreparePeerPushCreditResponse,
|
||||||
PrepareRefundRequest,
|
PrepareRefundRequest,
|
||||||
PrepareTipRequest,
|
PrepareRewardRequest as PrepareRewardRequest,
|
||||||
PrepareTipResult,
|
PrepareTipResult as PrepareRewardResult,
|
||||||
RecoveryLoadRequest,
|
RecoveryLoadRequest,
|
||||||
RetryTransactionRequest,
|
RetryTransactionRequest,
|
||||||
SetCoinSuspendedRequest,
|
SetCoinSuspendedRequest,
|
||||||
@ -178,8 +178,8 @@ export enum WalletApiOperation {
|
|||||||
DumpCoins = "dumpCoins",
|
DumpCoins = "dumpCoins",
|
||||||
SetCoinSuspended = "setCoinSuspended",
|
SetCoinSuspended = "setCoinSuspended",
|
||||||
ForceRefresh = "forceRefresh",
|
ForceRefresh = "forceRefresh",
|
||||||
PrepareTip = "prepareTip",
|
PrepareReward = "prepareReward",
|
||||||
AcceptTip = "acceptTip",
|
AcceptReward = "acceptReward",
|
||||||
ExportBackup = "exportBackup",
|
ExportBackup = "exportBackup",
|
||||||
AddBackupProvider = "addBackupProvider",
|
AddBackupProvider = "addBackupProvider",
|
||||||
RemoveBackupProvider = "removeBackupProvider",
|
RemoveBackupProvider = "removeBackupProvider",
|
||||||
@ -507,23 +507,23 @@ export type StartRefundQueryOp = {
|
|||||||
response: EmptyObject;
|
response: EmptyObject;
|
||||||
};
|
};
|
||||||
|
|
||||||
// group: Tipping
|
// group: Rewards
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query and store information about a tip.
|
* Query and store information about a reward.
|
||||||
*/
|
*/
|
||||||
export type PrepareTipOp = {
|
export type PrepareTipOp = {
|
||||||
op: WalletApiOperation.PrepareTip;
|
op: WalletApiOperation.PrepareReward;
|
||||||
request: PrepareTipRequest;
|
request: PrepareRewardRequest;
|
||||||
response: PrepareTipResult;
|
response: PrepareRewardResult;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accept a tip.
|
* Accept a reward.
|
||||||
*/
|
*/
|
||||||
export type AcceptTipOp = {
|
export type AcceptTipOp = {
|
||||||
op: WalletApiOperation.AcceptTip;
|
op: WalletApiOperation.AcceptReward;
|
||||||
request: AcceptTipRequest;
|
request: AcceptRewardRequest;
|
||||||
response: AcceptTipResponse;
|
response: AcceptTipResponse;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1023,8 +1023,8 @@ export type WalletOperations = {
|
|||||||
[WalletApiOperation.ForceRefresh]: ForceRefreshOp;
|
[WalletApiOperation.ForceRefresh]: ForceRefreshOp;
|
||||||
[WalletApiOperation.DeleteTransaction]: DeleteTransactionOp;
|
[WalletApiOperation.DeleteTransaction]: DeleteTransactionOp;
|
||||||
[WalletApiOperation.RetryTransaction]: RetryTransactionOp;
|
[WalletApiOperation.RetryTransaction]: RetryTransactionOp;
|
||||||
[WalletApiOperation.PrepareTip]: PrepareTipOp;
|
[WalletApiOperation.PrepareReward]: PrepareTipOp;
|
||||||
[WalletApiOperation.AcceptTip]: AcceptTipOp;
|
[WalletApiOperation.AcceptReward]: AcceptTipOp;
|
||||||
[WalletApiOperation.StartRefundQueryForUri]: StartRefundQueryForUriOp;
|
[WalletApiOperation.StartRefundQueryForUri]: StartRefundQueryForUriOp;
|
||||||
[WalletApiOperation.StartRefundQuery]: StartRefundQueryOp;
|
[WalletApiOperation.StartRefundQuery]: StartRefundQueryOp;
|
||||||
[WalletApiOperation.ListCurrencies]: ListCurrenciesOp;
|
[WalletApiOperation.ListCurrencies]: ListCurrenciesOp;
|
||||||
|
@ -93,7 +93,7 @@ import {
|
|||||||
codecForPreparePeerPullPaymentRequest,
|
codecForPreparePeerPullPaymentRequest,
|
||||||
codecForPreparePeerPushCreditRequest,
|
codecForPreparePeerPushCreditRequest,
|
||||||
codecForPrepareRefundRequest,
|
codecForPrepareRefundRequest,
|
||||||
codecForPrepareTipRequest,
|
codecForPrepareRewardRequest,
|
||||||
codecForResumeTransaction,
|
codecForResumeTransaction,
|
||||||
codecForRetryTransactionRequest,
|
codecForRetryTransactionRequest,
|
||||||
codecForSetCoinSuspendedRequest,
|
codecForSetCoinSuspendedRequest,
|
||||||
@ -249,10 +249,10 @@ import {
|
|||||||
} from "./operations/testing.js";
|
} from "./operations/testing.js";
|
||||||
import {
|
import {
|
||||||
acceptTip,
|
acceptTip,
|
||||||
computeTipTransactionStatus,
|
computeRewardTransactionStatus,
|
||||||
prepareTip,
|
prepareTip,
|
||||||
processTip,
|
processTip,
|
||||||
} from "./operations/tip.js";
|
} from "./operations/reward.js";
|
||||||
import {
|
import {
|
||||||
abortTransaction,
|
abortTransaction,
|
||||||
deleteTransaction,
|
deleteTransaction,
|
||||||
@ -329,7 +329,7 @@ async function callOperationHandler(
|
|||||||
return await processRefreshGroup(ws, pending.refreshGroupId);
|
return await processRefreshGroup(ws, pending.refreshGroupId);
|
||||||
case PendingTaskType.Withdraw:
|
case PendingTaskType.Withdraw:
|
||||||
return await processWithdrawalGroup(ws, pending.withdrawalGroupId);
|
return await processWithdrawalGroup(ws, pending.withdrawalGroupId);
|
||||||
case PendingTaskType.TipPickup:
|
case PendingTaskType.RewardPickup:
|
||||||
return await processTip(ws, pending.tipId);
|
return await processTip(ws, pending.tipId);
|
||||||
case PendingTaskType.Purchase:
|
case PendingTaskType.Purchase:
|
||||||
return await processPurchase(ws, pending.proposalId);
|
return await processPurchase(ws, pending.proposalId);
|
||||||
@ -1350,9 +1350,9 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>(
|
|||||||
refreshGroupId,
|
refreshGroupId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case WalletApiOperation.PrepareTip: {
|
case WalletApiOperation.PrepareReward: {
|
||||||
const req = codecForPrepareTipRequest().decode(payload);
|
const req = codecForPrepareRewardRequest().decode(payload);
|
||||||
return await prepareTip(ws, req.talerTipUri);
|
return await prepareTip(ws, req.talerRewardUri);
|
||||||
}
|
}
|
||||||
case WalletApiOperation.StartRefundQueryForUri: {
|
case WalletApiOperation.StartRefundQueryForUri: {
|
||||||
const req = codecForPrepareRefundRequest().decode(payload);
|
const req = codecForPrepareRefundRequest().decode(payload);
|
||||||
@ -1370,9 +1370,9 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>(
|
|||||||
await startQueryRefund(ws, txIdParsed.proposalId);
|
await startQueryRefund(ws, txIdParsed.proposalId);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
case WalletApiOperation.AcceptTip: {
|
case WalletApiOperation.AcceptReward: {
|
||||||
const req = codecForAcceptTipRequest().decode(payload);
|
const req = codecForAcceptTipRequest().decode(payload);
|
||||||
return await acceptTip(ws, req.walletTipId);
|
return await acceptTip(ws, req.walletRewardId);
|
||||||
}
|
}
|
||||||
case WalletApiOperation.ExportBackupPlain: {
|
case WalletApiOperation.ExportBackupPlain: {
|
||||||
return exportBackup(ws);
|
return exportBackup(ws);
|
||||||
@ -1884,12 +1884,12 @@ class InternalWalletStateImpl implements InternalWalletState {
|
|||||||
}
|
}
|
||||||
return computeRefreshTransactionState(rec);
|
return computeRefreshTransactionState(rec);
|
||||||
}
|
}
|
||||||
case TransactionType.Tip: {
|
case TransactionType.Reward: {
|
||||||
const rec = await tx.tips.get(parsedTxId.walletTipId);
|
const rec = await tx.rewards.get(parsedTxId.walletRewardId);
|
||||||
if (!rec) {
|
if (!rec) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return computeTipTransactionStatus(rec);
|
return computeRewardTransactionStatus(rec);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
assertUnreachable(parsedTxId);
|
assertUnreachable(parsedTxId);
|
||||||
|
@ -134,7 +134,7 @@ export function HistoryItem(props: { tx: Transaction }): VNode {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case TransactionType.Tip:
|
case TransactionType.Reward:
|
||||||
return (
|
return (
|
||||||
<Layout
|
<Layout
|
||||||
id={tx.transactionId}
|
id={tx.transactionId}
|
||||||
|
@ -23,7 +23,7 @@ import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js";
|
|||||||
import { Props, State } from "./index.js";
|
import { Props, State } from "./index.js";
|
||||||
|
|
||||||
export function useComponentState({
|
export function useComponentState({
|
||||||
talerTipUri,
|
talerTipUri: talerRewardUri,
|
||||||
onCancel,
|
onCancel,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
}: Props): State {
|
}: Props): State {
|
||||||
@ -31,9 +31,9 @@ export function useComponentState({
|
|||||||
const { i18n } = useTranslationContext();
|
const { i18n } = useTranslationContext();
|
||||||
const { pushAlertOnError } = useAlertContext();
|
const { pushAlertOnError } = useAlertContext();
|
||||||
const tipInfo = useAsyncAsHook(async () => {
|
const tipInfo = useAsyncAsHook(async () => {
|
||||||
if (!talerTipUri) throw Error("ERROR_NO-URI-FOR-TIP");
|
if (!talerRewardUri) throw Error("ERROR_NO-URI-FOR-TIP");
|
||||||
const tip = await api.wallet.call(WalletApiOperation.PrepareTip, {
|
const tip = await api.wallet.call(WalletApiOperation.PrepareReward, {
|
||||||
talerTipUri,
|
talerRewardUri,
|
||||||
});
|
});
|
||||||
return { tip };
|
return { tip };
|
||||||
});
|
});
|
||||||
@ -63,8 +63,8 @@ export function useComponentState({
|
|||||||
const { tip } = tipInfo.response;
|
const { tip } = tipInfo.response;
|
||||||
|
|
||||||
const doAccept = async (): Promise<void> => {
|
const doAccept = async (): Promise<void> => {
|
||||||
const res = await api.wallet.call(WalletApiOperation.AcceptTip, {
|
const res = await api.wallet.call(WalletApiOperation.AcceptReward, {
|
||||||
walletTipId: tip.walletTipId,
|
walletRewardId: tip.walletRewardId,
|
||||||
});
|
});
|
||||||
|
|
||||||
//FIX: this may not be seen since we are moving to the success also
|
//FIX: this may not be seen since we are moving to the success also
|
||||||
@ -75,7 +75,7 @@ export function useComponentState({
|
|||||||
const baseInfo = {
|
const baseInfo = {
|
||||||
merchantBaseUrl: tip.merchantBaseUrl,
|
merchantBaseUrl: tip.merchantBaseUrl,
|
||||||
exchangeBaseUrl: tip.exchangeBaseUrl,
|
exchangeBaseUrl: tip.exchangeBaseUrl,
|
||||||
amount: Amounts.parseOrThrow(tip.tipAmountEffective),
|
amount: Amounts.parseOrThrow(tip.rewardAmountEffective),
|
||||||
error: undefined,
|
error: undefined,
|
||||||
cancel: {
|
cancel: {
|
||||||
onClick: pushAlertOnError(onCancel),
|
onClick: pushAlertOnError(onCancel),
|
@ -62,17 +62,17 @@ describe("Tip CTA states", () => {
|
|||||||
it("should be ready for accepting the tip", async () => {
|
it("should be ready for accepting the tip", async () => {
|
||||||
const { handler, TestingContext } = createWalletApiMock();
|
const { handler, TestingContext } = createWalletApiMock();
|
||||||
|
|
||||||
handler.addWalletCallResponse(WalletApiOperation.PrepareTip, undefined, {
|
handler.addWalletCallResponse(WalletApiOperation.PrepareReward, undefined, {
|
||||||
accepted: false,
|
accepted: false,
|
||||||
exchangeBaseUrl: "exchange url",
|
exchangeBaseUrl: "exchange url",
|
||||||
merchantBaseUrl: "merchant url",
|
merchantBaseUrl: "merchant url",
|
||||||
tipAmountEffective: "EUR:1",
|
rewardAmountEffective: "EUR:1",
|
||||||
walletTipId: "tip_id",
|
walletRewardId: "tip_id",
|
||||||
transactionId: "txn:tip:ABC1234",
|
transactionId: "txn:tip:ABC1234",
|
||||||
expirationTimestamp: {
|
expirationTimestamp: {
|
||||||
t_s: 1,
|
t_s: 1,
|
||||||
},
|
},
|
||||||
tipAmountRaw: "",
|
rewardAmountRaw: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
const props: Props = {
|
const props: Props = {
|
||||||
@ -100,23 +100,23 @@ describe("Tip CTA states", () => {
|
|||||||
expect(state.exchangeBaseUrl).eq("exchange url");
|
expect(state.exchangeBaseUrl).eq("exchange url");
|
||||||
if (state.accept.onClick === undefined) expect.fail();
|
if (state.accept.onClick === undefined) expect.fail();
|
||||||
|
|
||||||
handler.addWalletCallResponse(WalletApiOperation.AcceptTip);
|
handler.addWalletCallResponse(WalletApiOperation.AcceptReward);
|
||||||
state.accept.onClick();
|
state.accept.onClick();
|
||||||
|
|
||||||
handler.addWalletCallResponse(
|
handler.addWalletCallResponse(
|
||||||
WalletApiOperation.PrepareTip,
|
WalletApiOperation.PrepareReward,
|
||||||
undefined,
|
undefined,
|
||||||
{
|
{
|
||||||
accepted: true,
|
accepted: true,
|
||||||
exchangeBaseUrl: "exchange url",
|
exchangeBaseUrl: "exchange url",
|
||||||
merchantBaseUrl: "merchant url",
|
merchantBaseUrl: "merchant url",
|
||||||
tipAmountEffective: "EUR:1",
|
rewardAmountEffective: "EUR:1",
|
||||||
walletTipId: "tip_id",
|
walletRewardId: "tip_id",
|
||||||
transactionId: "txn:tip:ABC1234",
|
transactionId: "txn:tip:ABC1234",
|
||||||
expirationTimestamp: {
|
expirationTimestamp: {
|
||||||
t_s: 1,
|
t_s: 1,
|
||||||
},
|
},
|
||||||
tipAmountRaw: "",
|
rewardAmountRaw: "",
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -137,17 +137,17 @@ describe("Tip CTA states", () => {
|
|||||||
|
|
||||||
it.skip("should be ignored after clicking the ignore button", async () => {
|
it.skip("should be ignored after clicking the ignore button", async () => {
|
||||||
const { handler, TestingContext } = createWalletApiMock();
|
const { handler, TestingContext } = createWalletApiMock();
|
||||||
handler.addWalletCallResponse(WalletApiOperation.PrepareTip, undefined, {
|
handler.addWalletCallResponse(WalletApiOperation.PrepareReward, undefined, {
|
||||||
exchangeBaseUrl: "exchange url",
|
exchangeBaseUrl: "exchange url",
|
||||||
merchantBaseUrl: "merchant url",
|
merchantBaseUrl: "merchant url",
|
||||||
tipAmountEffective: "EUR:1",
|
rewardAmountEffective: "EUR:1",
|
||||||
walletTipId: "tip_id",
|
walletRewardId: "tip_id",
|
||||||
transactionId: "txn:tip:ABC1234",
|
transactionId: "txn:tip:ABC1234",
|
||||||
accepted: false,
|
accepted: false,
|
||||||
expirationTimestamp: {
|
expirationTimestamp: {
|
||||||
t_s: 1,
|
t_s: 1,
|
||||||
},
|
},
|
||||||
tipAmountRaw: "",
|
rewardAmountRaw: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
const props: Props = {
|
const props: Props = {
|
||||||
@ -184,17 +184,17 @@ describe("Tip CTA states", () => {
|
|||||||
it("should render accepted if the tip has been used previously", async () => {
|
it("should render accepted if the tip has been used previously", async () => {
|
||||||
const { handler, TestingContext } = createWalletApiMock();
|
const { handler, TestingContext } = createWalletApiMock();
|
||||||
|
|
||||||
handler.addWalletCallResponse(WalletApiOperation.PrepareTip, undefined, {
|
handler.addWalletCallResponse(WalletApiOperation.PrepareReward, undefined, {
|
||||||
accepted: true,
|
accepted: true,
|
||||||
exchangeBaseUrl: "exchange url",
|
exchangeBaseUrl: "exchange url",
|
||||||
merchantBaseUrl: "merchant url",
|
merchantBaseUrl: "merchant url",
|
||||||
tipAmountEffective: "EUR:1",
|
rewardAmountEffective: "EUR:1",
|
||||||
walletTipId: "tip_id",
|
walletRewardId: "tip_id",
|
||||||
transactionId: "txn:tip:ABC1234",
|
transactionId: "txn:tip:ABC1234",
|
||||||
expirationTimestamp: {
|
expirationTimestamp: {
|
||||||
t_s: 1,
|
t_s: 1,
|
||||||
},
|
},
|
||||||
tipAmountRaw: "",
|
rewardAmountRaw: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
const props: Props = {
|
const props: Props = {
|
@ -22,7 +22,7 @@
|
|||||||
export * as a1 from "./Deposit/stories.jsx";
|
export * as a1 from "./Deposit/stories.jsx";
|
||||||
export * as a3 from "./Payment/stories.jsx";
|
export * as a3 from "./Payment/stories.jsx";
|
||||||
export * as a4 from "./Refund/stories.jsx";
|
export * as a4 from "./Refund/stories.jsx";
|
||||||
export * as a5 from "./Tip/stories.jsx";
|
export * as a5 from "./Reward/stories.js";
|
||||||
export * as a6 from "./Withdraw/stories.jsx";
|
export * as a6 from "./Withdraw/stories.jsx";
|
||||||
export * as a8 from "./InvoiceCreate/stories.js";
|
export * as a8 from "./InvoiceCreate/stories.js";
|
||||||
export * as a9 from "./InvoicePay/stories.js";
|
export * as a9 from "./InvoicePay/stories.js";
|
||||||
|
@ -58,7 +58,7 @@ import { PaymentPage } from "../cta/Payment/index.js";
|
|||||||
import { PaymentTemplatePage } from "../cta/PaymentTemplate/index.js";
|
import { PaymentTemplatePage } from "../cta/PaymentTemplate/index.js";
|
||||||
import { RecoveryPage } from "../cta/Recovery/index.js";
|
import { RecoveryPage } from "../cta/Recovery/index.js";
|
||||||
import { RefundPage } from "../cta/Refund/index.js";
|
import { RefundPage } from "../cta/Refund/index.js";
|
||||||
import { TipPage } from "../cta/Tip/index.js";
|
import { TipPage } from "../cta/Reward/index.js";
|
||||||
import { TransferCreatePage } from "../cta/TransferCreate/index.js";
|
import { TransferCreatePage } from "../cta/TransferCreate/index.js";
|
||||||
import { TransferPickupPage } from "../cta/TransferPickup/index.js";
|
import { TransferPickupPage } from "../cta/TransferPickup/index.js";
|
||||||
import {
|
import {
|
||||||
|
@ -34,7 +34,7 @@ import {
|
|||||||
TransactionPeerPushDebit,
|
TransactionPeerPushDebit,
|
||||||
TransactionRefresh,
|
TransactionRefresh,
|
||||||
TransactionRefund,
|
TransactionRefund,
|
||||||
TransactionTip,
|
TransactionReward,
|
||||||
TransactionType,
|
TransactionType,
|
||||||
TransactionWithdrawal,
|
TransactionWithdrawal,
|
||||||
WithdrawalType,
|
WithdrawalType,
|
||||||
@ -113,9 +113,9 @@ const exampleData = {
|
|||||||
} as TransactionRefresh,
|
} as TransactionRefresh,
|
||||||
tip: {
|
tip: {
|
||||||
...commonTransaction(),
|
...commonTransaction(),
|
||||||
type: TransactionType.Tip,
|
type: TransactionType.Reward,
|
||||||
merchantBaseUrl: "http://ads.merchant.taler.net/",
|
merchantBaseUrl: "http://ads.merchant.taler.net/",
|
||||||
} as TransactionTip,
|
} as TransactionReward,
|
||||||
refund: {
|
refund: {
|
||||||
...commonTransaction(),
|
...commonTransaction(),
|
||||||
type: TransactionType.Refund,
|
type: TransactionType.Refund,
|
||||||
|
@ -37,7 +37,7 @@ import {
|
|||||||
TransactionPeerPushDebit,
|
TransactionPeerPushDebit,
|
||||||
TransactionRefresh,
|
TransactionRefresh,
|
||||||
TransactionRefund,
|
TransactionRefund,
|
||||||
TransactionTip,
|
TransactionReward,
|
||||||
TransactionType,
|
TransactionType,
|
||||||
TransactionWithdrawal,
|
TransactionWithdrawal,
|
||||||
WithdrawalDetails,
|
WithdrawalDetails,
|
||||||
@ -138,7 +138,7 @@ const exampleData = {
|
|||||||
} as TransactionRefresh,
|
} as TransactionRefresh,
|
||||||
tip: {
|
tip: {
|
||||||
...commonTransaction,
|
...commonTransaction,
|
||||||
type: TransactionType.Tip,
|
type: TransactionType.Reward,
|
||||||
// merchant: {
|
// merchant: {
|
||||||
// name: "the merchant",
|
// name: "the merchant",
|
||||||
// logo: merchantIcon,
|
// logo: merchantIcon,
|
||||||
@ -146,7 +146,7 @@ const exampleData = {
|
|||||||
// email: "contact@merchant.taler",
|
// email: "contact@merchant.taler",
|
||||||
// },
|
// },
|
||||||
merchantBaseUrl: "http://merchant.taler",
|
merchantBaseUrl: "http://merchant.taler",
|
||||||
} as TransactionTip,
|
} as TransactionReward,
|
||||||
refund: {
|
refund: {
|
||||||
...commonTransaction,
|
...commonTransaction,
|
||||||
type: TransactionType.Refund,
|
type: TransactionType.Refund,
|
||||||
|
@ -745,7 +745,7 @@ export function TransactionView({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transaction.type === TransactionType.Tip) {
|
if (transaction.type === TransactionType.Reward) {
|
||||||
return (
|
return (
|
||||||
<TransactionTemplate
|
<TransactionTemplate
|
||||||
transaction={transaction}
|
transaction={transaction}
|
||||||
|
Loading…
Reference in New Issue
Block a user