fix deposit navigation

This commit is contained in:
Sebastian 2023-01-13 17:31:20 -03:00
parent 767f1a9d67
commit 8e8bada643
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1
5 changed files with 17 additions and 14 deletions

View File

@ -49,13 +49,16 @@ type Type = {
pushAlert: (n: Alert) => void;
removeAlert: (n: Alert) => void;
/**
*
* @param h
* @returns
*
* @param h
* @returns
* @deprecated use safely
*/
pushAlertOnError: <T>(h: (p: T) => Promise<void>) => SafeHandler<T>;
safely: <T>(h: (p: T) => Promise<void>, error: TranslatedString) => SafeHandler<T>;
safely: <T>(
h: (p: T) => Promise<void>,
error: TranslatedString,
) => SafeHandler<T>;
};
const initial: Type = {
@ -112,7 +115,7 @@ export const AlertProvider = ({ children }: Props): VNode => {
function safely<T>(
handler: (p: T) => Promise<void>,
message: TranslatedString
message: TranslatedString,
): SafeHandler<T> {
return withSafe(handler, (e) => {
const a = alertFromError(message, e);

View File

@ -207,9 +207,10 @@ export function Application(): VNode {
<Route
path={Pages.balanceDeposit.pattern}
component={() => (
component={({ amount }: { amount: string }) => (
<WalletTemplate path="balance">
<DepositPage
amount={amount}
onCancel={(currency: string) => {
redirectTo(Pages.balanceHistory({ currency }));
}}

View File

@ -35,7 +35,6 @@ import {
export interface Props {
amount?: string;
currency?: string;
onCancel: (currency: string) => void;
onSuccess: (currency: string) => void;
}

View File

@ -33,7 +33,6 @@ import { Props, State } from "./index.js";
export function useComponentState({
amount: amountStr,
currency: currencyStr,
onCancel,
onSuccess,
}: Props): State {
@ -41,7 +40,7 @@ export function useComponentState({
const { i18n } = useTranslationContext();
const { pushAlertOnError } = useAlertContext();
const parsed = amountStr === undefined ? undefined : Amounts.parse(amountStr);
const currency = parsed !== undefined ? parsed.currency : currencyStr;
const currency = parsed !== undefined ? parsed.currency : undefined;
const hook = useAsyncAsHook(async () => {
const { balances } = await api.wallet.call(

View File

@ -34,6 +34,7 @@ import { createWalletApiMock } from "../../test-utils.js";
import { useComponentState } from "./state.js";
const currency = "EUR";
const amount = `${currency}:0`;
const withoutFee = (): DepositGroupFees => ({
coin: Amounts.stringify(`${currency}:0`),
wire: Amounts.stringify(`${currency}:0`),
@ -49,7 +50,7 @@ const withSomeFee = (): DepositGroupFees => ({
describe("DepositPage states", () => {
it("should have status 'no-enough-balance' when balance is empty", async () => {
const { handler, TestingContext } = createWalletApiMock();
const props = { currency, onCancel: nullFunction, onSuccess: nullFunction };
const props = { amount, onCancel: nullFunction, onSuccess: nullFunction };
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
balances: [
@ -90,7 +91,7 @@ describe("DepositPage states", () => {
it("should have status 'no-accounts' when balance is not empty and accounts is empty", async () => {
const { handler, TestingContext } = createWalletApiMock();
const props = { currency, onCancel: nullFunction, onSuccess: nullFunction };
const props = { amount, onCancel: nullFunction, onSuccess: nullFunction };
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
balances: [
@ -144,7 +145,7 @@ describe("DepositPage states", () => {
it("should have status 'ready' but unable to deposit ", async () => {
const { handler, TestingContext } = createWalletApiMock();
const props = { currency, onCancel: nullFunction, onSuccess: nullFunction };
const props = { amount, onCancel: nullFunction, onSuccess: nullFunction };
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
balances: [
@ -198,7 +199,7 @@ describe("DepositPage states", () => {
it("should not be able to deposit more than the balance ", async () => {
const { handler, TestingContext } = createWalletApiMock();
const props = { currency, onCancel: nullFunction, onSuccess: nullFunction };
const props = { amount, onCancel: nullFunction, onSuccess: nullFunction };
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
balances: [
@ -273,7 +274,7 @@ describe("DepositPage states", () => {
it("should calculate the fee upon entering amount ", async () => {
const { handler, TestingContext } = createWalletApiMock();
const props = { currency, onCancel: nullFunction, onSuccess: nullFunction };
const props = { amount, onCancel: nullFunction, onSuccess: nullFunction };
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
balances: [