revert the Lost payment result
This commit is contained in:
parent
c121eb875e
commit
dcddc4c53a
@ -385,7 +385,6 @@ export enum PreparePayResultType {
|
|||||||
PaymentPossible = "payment-possible",
|
PaymentPossible = "payment-possible",
|
||||||
InsufficientBalance = "insufficient-balance",
|
InsufficientBalance = "insufficient-balance",
|
||||||
AlreadyConfirmed = "already-confirmed",
|
AlreadyConfirmed = "already-confirmed",
|
||||||
Lost = "lost",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const codecForPreparePayResultPaymentPossible =
|
export const codecForPreparePayResultPaymentPossible =
|
||||||
@ -434,12 +433,6 @@ export const codecForPreparePayResultAlreadyConfirmed =
|
|||||||
.property("proposalId", codecForString())
|
.property("proposalId", codecForString())
|
||||||
.build("PreparePayResultAlreadyConfirmed");
|
.build("PreparePayResultAlreadyConfirmed");
|
||||||
|
|
||||||
export const codecForPreparePayResultPaymentLost =
|
|
||||||
(): Codec<PreparePayResultPaymentLost> =>
|
|
||||||
buildCodecForObject<PreparePayResultPaymentLost>()
|
|
||||||
.property("status", codecForConstString(PreparePayResultType.Lost))
|
|
||||||
.build("PreparePayResultLost");
|
|
||||||
|
|
||||||
export const codecForPreparePayResult = (): Codec<PreparePayResult> =>
|
export const codecForPreparePayResult = (): Codec<PreparePayResult> =>
|
||||||
buildCodecForUnion<PreparePayResult>()
|
buildCodecForUnion<PreparePayResult>()
|
||||||
.discriminateOn("status")
|
.discriminateOn("status")
|
||||||
@ -455,10 +448,6 @@ export const codecForPreparePayResult = (): Codec<PreparePayResult> =>
|
|||||||
PreparePayResultType.PaymentPossible,
|
PreparePayResultType.PaymentPossible,
|
||||||
codecForPreparePayResultPaymentPossible(),
|
codecForPreparePayResultPaymentPossible(),
|
||||||
)
|
)
|
||||||
.alternative(
|
|
||||||
PreparePayResultType.Lost,
|
|
||||||
codecForPreparePayResultPaymentLost(),
|
|
||||||
)
|
|
||||||
.build("PreparePayResult");
|
.build("PreparePayResult");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -467,8 +456,7 @@ export const codecForPreparePayResult = (): Codec<PreparePayResult> =>
|
|||||||
export type PreparePayResult =
|
export type PreparePayResult =
|
||||||
| PreparePayResultInsufficientBalance
|
| PreparePayResultInsufficientBalance
|
||||||
| PreparePayResultAlreadyConfirmed
|
| PreparePayResultAlreadyConfirmed
|
||||||
| PreparePayResultPaymentPossible
|
| PreparePayResultPaymentPossible;
|
||||||
| PreparePayResultPaymentLost;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payment is possible.
|
* Payment is possible.
|
||||||
@ -504,10 +492,6 @@ export interface PreparePayResultAlreadyConfirmed {
|
|||||||
talerUri?: string;
|
talerUri?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PreparePayResultPaymentLost {
|
|
||||||
status: PreparePayResultType.Lost;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface BankWithdrawDetails {
|
export interface BankWithdrawDetails {
|
||||||
selectionDone: boolean;
|
selectionDone: boolean;
|
||||||
transferDone: boolean;
|
transferDone: boolean;
|
||||||
|
@ -368,10 +368,7 @@ async function runBackupCycleForProvider(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (res === undefined) {
|
||||||
res === undefined ||
|
|
||||||
res.status === PreparePayResultType.AlreadyConfirmed
|
|
||||||
) {
|
|
||||||
//claimed
|
//claimed
|
||||||
|
|
||||||
await ws.db
|
await ws.db
|
||||||
@ -400,10 +397,6 @@ async function runBackupCycleForProvider(
|
|||||||
}
|
}
|
||||||
const result = res;
|
const result = res;
|
||||||
|
|
||||||
if (result.status === PreparePayResultType.Lost) {
|
|
||||||
throw Error("invalid state, could not get proposal for backup");
|
|
||||||
}
|
|
||||||
|
|
||||||
await ws.db
|
await ws.db
|
||||||
.mktx((x) => [x.backupProviders, x.operationRetries])
|
.mktx((x) => [x.backupProviders, x.operationRetries])
|
||||||
.runReadWrite(async (tx) => {
|
.runReadWrite(async (tx) => {
|
||||||
@ -890,7 +883,13 @@ async function getProviderPaymentInfo(
|
|||||||
const status = await checkPaymentByProposalId(
|
const status = await checkPaymentByProposalId(
|
||||||
ws,
|
ws,
|
||||||
provider.currentPaymentProposalId,
|
provider.currentPaymentProposalId,
|
||||||
);
|
).catch(() => undefined);
|
||||||
|
|
||||||
|
if (!status) {
|
||||||
|
return {
|
||||||
|
type: ProviderPaymentType.Unpaid,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
switch (status.status) {
|
switch (status.status) {
|
||||||
case PreparePayResultType.InsufficientBalance:
|
case PreparePayResultType.InsufficientBalance:
|
||||||
@ -903,10 +902,6 @@ async function getProviderPaymentInfo(
|
|||||||
type: ProviderPaymentType.Pending,
|
type: ProviderPaymentType.Pending,
|
||||||
talerUri: status.talerUri,
|
talerUri: status.talerUri,
|
||||||
};
|
};
|
||||||
case PreparePayResultType.Lost:
|
|
||||||
return {
|
|
||||||
type: ProviderPaymentType.Unpaid,
|
|
||||||
};
|
|
||||||
case PreparePayResultType.AlreadyConfirmed:
|
case PreparePayResultType.AlreadyConfirmed:
|
||||||
if (status.paid) {
|
if (status.paid) {
|
||||||
return {
|
return {
|
||||||
|
@ -1291,10 +1291,7 @@ export async function checkPaymentByProposalId(
|
|||||||
return tx.purchases.get(proposalId);
|
return tx.purchases.get(proposalId);
|
||||||
});
|
});
|
||||||
if (!proposal) {
|
if (!proposal) {
|
||||||
// throw Error(`could not get proposal ${proposalId}`);
|
throw Error(`could not get proposal ${proposalId}`);
|
||||||
return {
|
|
||||||
status: PreparePayResultType.Lost,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
if (proposal.purchaseStatus === PurchaseStatus.RepurchaseDetected) {
|
if (proposal.purchaseStatus === PurchaseStatus.RepurchaseDetected) {
|
||||||
const existingProposalId = proposal.repurchaseProposalId;
|
const existingProposalId = proposal.repurchaseProposalId;
|
||||||
|
@ -27,7 +27,7 @@ import { ButtonHandler } from "../../mui/handlers.js";
|
|||||||
import { compose, StateViewMap } from "../../utils/index.js";
|
import { compose, StateViewMap } from "../../utils/index.js";
|
||||||
import { wxApi } from "../../wxApi.js";
|
import { wxApi } from "../../wxApi.js";
|
||||||
import { useComponentState } from "./state.js";
|
import { useComponentState } from "./state.js";
|
||||||
import { BaseView, LoadingUriView, LostView } from "./views.js";
|
import { BaseView, LoadingUriView } from "./views.js";
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
talerPayUri?: string;
|
talerPayUri?: string;
|
||||||
@ -41,7 +41,6 @@ export type State =
|
|||||||
| State.LoadingUriError
|
| State.LoadingUriError
|
||||||
| State.Ready
|
| State.Ready
|
||||||
| State.NoEnoughBalance
|
| State.NoEnoughBalance
|
||||||
| State.Lost
|
|
||||||
| State.NoBalanceForCurrency
|
| State.NoBalanceForCurrency
|
||||||
| State.Confirmed;
|
| State.Confirmed;
|
||||||
|
|
||||||
@ -64,10 +63,7 @@ export namespace State {
|
|||||||
}
|
}
|
||||||
export interface NoBalanceForCurrency extends BaseInfo {
|
export interface NoBalanceForCurrency extends BaseInfo {
|
||||||
status: "no-balance-for-currency";
|
status: "no-balance-for-currency";
|
||||||
payStatus:
|
payStatus: PreparePayResult;
|
||||||
| PreparePayResultInsufficientBalance
|
|
||||||
| PreparePayResultPaymentPossible
|
|
||||||
| PreparePayResultAlreadyConfirmed;
|
|
||||||
balance: undefined;
|
balance: undefined;
|
||||||
}
|
}
|
||||||
export interface NoEnoughBalance extends BaseInfo {
|
export interface NoEnoughBalance extends BaseInfo {
|
||||||
@ -82,11 +78,6 @@ export namespace State {
|
|||||||
balance: AmountJson;
|
balance: AmountJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Lost {
|
|
||||||
status: "lost";
|
|
||||||
error: undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Confirmed extends BaseInfo {
|
export interface Confirmed extends BaseInfo {
|
||||||
status: "confirmed";
|
status: "confirmed";
|
||||||
payStatus: PreparePayResultAlreadyConfirmed;
|
payStatus: PreparePayResultAlreadyConfirmed;
|
||||||
@ -99,7 +90,6 @@ const viewMapping: StateViewMap<State> = {
|
|||||||
"loading-uri": LoadingUriView,
|
"loading-uri": LoadingUriView,
|
||||||
"no-balance-for-currency": BaseView,
|
"no-balance-for-currency": BaseView,
|
||||||
"no-enough-balance": BaseView,
|
"no-enough-balance": BaseView,
|
||||||
lost: LostView,
|
|
||||||
confirmed: BaseView,
|
confirmed: BaseView,
|
||||||
ready: BaseView,
|
ready: BaseView,
|
||||||
};
|
};
|
||||||
|
@ -83,13 +83,6 @@ export function useComponentState(
|
|||||||
}
|
}
|
||||||
const { payStatus } = hook.response;
|
const { payStatus } = hook.response;
|
||||||
|
|
||||||
if (payStatus.status === PreparePayResultType.Lost) {
|
|
||||||
return {
|
|
||||||
status: "lost",
|
|
||||||
error: undefined,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const amount = Amounts.parseOrThrow(payStatus.amountRaw);
|
const amount = Amounts.parseOrThrow(payStatus.amountRaw);
|
||||||
|
|
||||||
const foundBalance = hook.response.balance.balances.find(
|
const foundBalance = hook.response.balance.balances.find(
|
||||||
|
@ -65,21 +65,6 @@ type SupportedStates =
|
|||||||
| State.NoBalanceForCurrency
|
| State.NoBalanceForCurrency
|
||||||
| State.NoEnoughBalance;
|
| State.NoEnoughBalance;
|
||||||
|
|
||||||
export function LostView(state: State.Lost): VNode {
|
|
||||||
const { i18n } = useTranslationContext();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ErrorMessage
|
|
||||||
title={<i18n.Translate>Could not load pay status</i18n.Translate>}
|
|
||||||
description={
|
|
||||||
<i18n.Translate>
|
|
||||||
The proposal was lost, another should be downloaded
|
|
||||||
</i18n.Translate>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function BaseView(state: SupportedStates): VNode {
|
export function BaseView(state: SupportedStates): VNode {
|
||||||
const { i18n } = useTranslationContext();
|
const { i18n } = useTranslationContext();
|
||||||
|
|
||||||
@ -417,9 +402,6 @@ export function ButtonsSection({
|
|||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (payStatus.status === PreparePayResultType.Lost) {
|
|
||||||
return <Fragment />;
|
|
||||||
}
|
|
||||||
|
|
||||||
assertUnreachable(payStatus);
|
assertUnreachable(payStatus);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user