diff options
author | Sebastian <sebasjm@gmail.com> | 2023-01-17 16:01:04 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-01-17 16:01:28 -0300 |
commit | 420493b3e608f3b245ebae308a318883f9f605f7 (patch) | |
tree | 9d30255d66dcda7c7fabc190e3b372369a66540a /packages/taler-wallet-webextension/src | |
parent | 252382a9375ea05f62389e33f111c3fa008d8fff (diff) | |
download | wallet-core-420493b3e608f3b245ebae308a318883f9f605f7.tar.xz |
use payto builder and prevent showing cancel for non-payment
Diffstat (limited to 'packages/taler-wallet-webextension/src')
4 files changed, 41 insertions, 31 deletions
diff --git a/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts b/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts index d7d9f2da7..b744b80e5 100644 --- a/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts @@ -60,8 +60,8 @@ export function useComponentState({ parsed !== undefined ? parsed : currency !== undefined - ? Amounts.zeroOfCurrency(currency) - : undefined; + ? Amounts.zeroOfCurrency(currency) + : undefined; // const [accountIdx, setAccountIdx] = useState<number>(0); const [selectedAccount, setSelectedAccount] = useState<PaytoUri>(); @@ -147,7 +147,7 @@ export function useComponentState({ initialValue ?? ({} as any), ); const amountStr = Amounts.stringify(amount); - const depositPaytoUri = `payto://${currentAccount.targetType}/${currentAccount.targetPath}`; + const depositPaytoUri = stringifyPaytoUri(currentAccount); // eslint-disable-next-line react-hooks/rules-of-hooks const hook = useAsyncAsHook(async () => { @@ -193,8 +193,8 @@ export function useComponentState({ const amountError = !isDirty ? undefined : Amounts.cmp(balance, amount) === -1 - ? `Too much, your current balance is ${Amounts.stringifyValue(balance)}` - : undefined; + ? `Too much, your current balance is ${Amounts.stringifyValue(balance)}` + : undefined; const unableToDeposit = Amounts.isZero(totalToDeposit) || //deposit may be zero because of fee diff --git a/packages/taler-wallet-webextension/src/wallet/ManageAccount/state.ts b/packages/taler-wallet-webextension/src/wallet/ManageAccount/state.ts index f7383d483..50e71c144 100644 --- a/packages/taler-wallet-webextension/src/wallet/ManageAccount/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/ManageAccount/state.ts @@ -128,7 +128,7 @@ export function useComponentState({ }), }, accountByType, - deleteAccount, + deleteAccount: pushAlertOnError(deleteAccount), onAccountAdded: { onClick: unableToAdd ? undefined : pushAlertOnError(addAccount), }, diff --git a/packages/taler-wallet-webextension/src/wallet/ManageAccount/views.tsx b/packages/taler-wallet-webextension/src/wallet/ManageAccount/views.tsx index e5be8d17d..75e1feca4 100644 --- a/packages/taler-wallet-webextension/src/wallet/ManageAccount/views.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ManageAccount/views.tsx @@ -15,10 +15,12 @@ */ import { + buildPayto, KnownBankAccountsInfo, PaytoUriBitcoin, PaytoUriIBAN, PaytoUriTalerBank, + stringifyPaytoUri, } from "@gnu-taler/taler-util"; import { styled } from "@linaria/react"; import { Fragment, h, VNode } from "preact"; @@ -411,7 +413,8 @@ function BitcoinAddressAccount({ field }: { field: TextFieldHandler }): VNode { onChange={(v) => { setValue(v); if (!errors && field.onInput) { - field.onInput(`payto://bitcoin/${v}`); + const p = buildPayto("bitcoin", v, undefined); + field.onInput(stringifyPaytoUri(p)); } }} /> @@ -448,8 +451,9 @@ function TalerBankAddressAccount({ disabled={!field.onInput} onChange={(v) => { setHost(v); - if (!errors && field.onInput) { - field.onInput(`payto://x-taler-bank/${v}/${account}`); + if (!errors && field.onInput && account) { + const p = buildPayto("x-taler-bank", v, account); + field.onInput(stringifyPaytoUri(p)); } }} /> @@ -462,8 +466,9 @@ function TalerBankAddressAccount({ error={account !== undefined ? errors?.account : undefined} onChange={(v) => { setAccount(v || ""); - if (!errors && field.onInput) { - field.onInput(`payto://x-taler-bank/${host}/${v}`); + if (!errors && field.onInput && host) { + const p = buildPayto("x-taler-bank", host, v); + field.onInput(stringifyPaytoUri(p)); } }} /> @@ -500,10 +505,9 @@ function IbanAddressAccount({ field }: { field: TextFieldHandler }): VNode { name: string, ): void { if (!errors && field.onInput) { - const path = bic === undefined ? iban : `${bic}/${iban}`; - field.onInput( - `payto://iban/${path}?receiver-name=${encodeURIComponent(name)}`, - ); + const p = buildPayto("iban", iban, bic); + p.params["receiver-name"] = name; + field.onInput(stringifyPaytoUri(p)); } } return ( diff --git a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx index 7c0682588..397972636 100644 --- a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx @@ -202,20 +202,24 @@ function TransactionTemplate({ const SHOWING_RETRY_THRESHOLD_SECS = 30; const showSend = false; - // (transaction.type === TransactionType.PeerPullCredit || - // transaction.type === TransactionType.PeerPushDebit) && - // !transaction.info.completed; - const showRetry = - transaction.error !== undefined || - transaction.timestamp.t_s === "never" || - (transaction.extendedStatus === ExtendedStatus.Pending && - differenceInSeconds(new Date(), transaction.timestamp.t_s * 1000) > - SHOWING_RETRY_THRESHOLD_SECS); + const hasCancelTransactionImplemented = + transaction.type === TransactionType.Payment; const transactionStillActive = transaction.extendedStatus !== ExtendedStatus.Aborted && transaction.extendedStatus !== ExtendedStatus.Done && transaction.extendedStatus !== ExtendedStatus.Failed; + + // show retry if there is an error in an active state, or after some time + // if it is not aborting + const showRetry = + transactionStillActive && + (transaction.error !== undefined || + (transaction.extendedStatus !== ExtendedStatus.Aborting && + (transaction.timestamp.t_s === "never" || + differenceInSeconds(new Date(), transaction.timestamp.t_s * 1000) > + SHOWING_RETRY_THRESHOLD_SECS))); + return ( <Fragment> <section style={{ padding: 8, textAlign: "center" }}> @@ -353,13 +357,15 @@ function TransactionTemplate({ </Button> ) : null} {transactionStillActive ? ( - <Button - variant="contained" - color="error" - onClick={doCheckBeforeCancel as SafeHandler<void>} - > - <i18n.Translate>Cancel</i18n.Translate> - </Button> + hasCancelTransactionImplemented ? ( + <Button + variant="contained" + color="error" + onClick={doCheckBeforeCancel as SafeHandler<void>} + > + <i18n.Translate>Cancel</i18n.Translate> + </Button> + ) : undefined ) : ( <Button variant="contained" |