fix deposit navigation
This commit is contained in:
parent
767f1a9d67
commit
8e8bada643
@ -49,13 +49,16 @@ type Type = {
|
|||||||
pushAlert: (n: Alert) => void;
|
pushAlert: (n: Alert) => void;
|
||||||
removeAlert: (n: Alert) => void;
|
removeAlert: (n: Alert) => void;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param h
|
* @param h
|
||||||
* @returns
|
* @returns
|
||||||
* @deprecated use safely
|
* @deprecated use safely
|
||||||
*/
|
*/
|
||||||
pushAlertOnError: <T>(h: (p: T) => Promise<void>) => SafeHandler<T>;
|
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 = {
|
const initial: Type = {
|
||||||
@ -112,7 +115,7 @@ export const AlertProvider = ({ children }: Props): VNode => {
|
|||||||
|
|
||||||
function safely<T>(
|
function safely<T>(
|
||||||
handler: (p: T) => Promise<void>,
|
handler: (p: T) => Promise<void>,
|
||||||
message: TranslatedString
|
message: TranslatedString,
|
||||||
): SafeHandler<T> {
|
): SafeHandler<T> {
|
||||||
return withSafe(handler, (e) => {
|
return withSafe(handler, (e) => {
|
||||||
const a = alertFromError(message, e);
|
const a = alertFromError(message, e);
|
||||||
|
@ -207,9 +207,10 @@ export function Application(): VNode {
|
|||||||
|
|
||||||
<Route
|
<Route
|
||||||
path={Pages.balanceDeposit.pattern}
|
path={Pages.balanceDeposit.pattern}
|
||||||
component={() => (
|
component={({ amount }: { amount: string }) => (
|
||||||
<WalletTemplate path="balance">
|
<WalletTemplate path="balance">
|
||||||
<DepositPage
|
<DepositPage
|
||||||
|
amount={amount}
|
||||||
onCancel={(currency: string) => {
|
onCancel={(currency: string) => {
|
||||||
redirectTo(Pages.balanceHistory({ currency }));
|
redirectTo(Pages.balanceHistory({ currency }));
|
||||||
}}
|
}}
|
||||||
|
@ -35,7 +35,6 @@ import {
|
|||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
amount?: string;
|
amount?: string;
|
||||||
currency?: string;
|
|
||||||
onCancel: (currency: string) => void;
|
onCancel: (currency: string) => void;
|
||||||
onSuccess: (currency: string) => void;
|
onSuccess: (currency: string) => void;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,6 @@ import { Props, State } from "./index.js";
|
|||||||
|
|
||||||
export function useComponentState({
|
export function useComponentState({
|
||||||
amount: amountStr,
|
amount: amountStr,
|
||||||
currency: currencyStr,
|
|
||||||
onCancel,
|
onCancel,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
}: Props): State {
|
}: Props): State {
|
||||||
@ -41,7 +40,7 @@ export function useComponentState({
|
|||||||
const { i18n } = useTranslationContext();
|
const { i18n } = useTranslationContext();
|
||||||
const { pushAlertOnError } = useAlertContext();
|
const { pushAlertOnError } = useAlertContext();
|
||||||
const parsed = amountStr === undefined ? undefined : Amounts.parse(amountStr);
|
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 hook = useAsyncAsHook(async () => {
|
||||||
const { balances } = await api.wallet.call(
|
const { balances } = await api.wallet.call(
|
||||||
|
@ -34,6 +34,7 @@ import { createWalletApiMock } from "../../test-utils.js";
|
|||||||
import { useComponentState } from "./state.js";
|
import { useComponentState } from "./state.js";
|
||||||
|
|
||||||
const currency = "EUR";
|
const currency = "EUR";
|
||||||
|
const amount = `${currency}:0`;
|
||||||
const withoutFee = (): DepositGroupFees => ({
|
const withoutFee = (): DepositGroupFees => ({
|
||||||
coin: Amounts.stringify(`${currency}:0`),
|
coin: Amounts.stringify(`${currency}:0`),
|
||||||
wire: Amounts.stringify(`${currency}:0`),
|
wire: Amounts.stringify(`${currency}:0`),
|
||||||
@ -49,7 +50,7 @@ const withSomeFee = (): DepositGroupFees => ({
|
|||||||
describe("DepositPage states", () => {
|
describe("DepositPage states", () => {
|
||||||
it("should have status 'no-enough-balance' when balance is empty", async () => {
|
it("should have status 'no-enough-balance' when balance is empty", async () => {
|
||||||
const { handler, TestingContext } = createWalletApiMock();
|
const { handler, TestingContext } = createWalletApiMock();
|
||||||
const props = { currency, onCancel: nullFunction, onSuccess: nullFunction };
|
const props = { amount, onCancel: nullFunction, onSuccess: nullFunction };
|
||||||
|
|
||||||
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
|
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
|
||||||
balances: [
|
balances: [
|
||||||
@ -90,7 +91,7 @@ describe("DepositPage states", () => {
|
|||||||
|
|
||||||
it("should have status 'no-accounts' when balance is not empty and accounts is empty", async () => {
|
it("should have status 'no-accounts' when balance is not empty and accounts is empty", async () => {
|
||||||
const { handler, TestingContext } = createWalletApiMock();
|
const { handler, TestingContext } = createWalletApiMock();
|
||||||
const props = { currency, onCancel: nullFunction, onSuccess: nullFunction };
|
const props = { amount, onCancel: nullFunction, onSuccess: nullFunction };
|
||||||
|
|
||||||
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
|
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
|
||||||
balances: [
|
balances: [
|
||||||
@ -144,7 +145,7 @@ describe("DepositPage states", () => {
|
|||||||
|
|
||||||
it("should have status 'ready' but unable to deposit ", async () => {
|
it("should have status 'ready' but unable to deposit ", async () => {
|
||||||
const { handler, TestingContext } = createWalletApiMock();
|
const { handler, TestingContext } = createWalletApiMock();
|
||||||
const props = { currency, onCancel: nullFunction, onSuccess: nullFunction };
|
const props = { amount, onCancel: nullFunction, onSuccess: nullFunction };
|
||||||
|
|
||||||
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
|
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
|
||||||
balances: [
|
balances: [
|
||||||
@ -198,7 +199,7 @@ describe("DepositPage states", () => {
|
|||||||
|
|
||||||
it("should not be able to deposit more than the balance ", async () => {
|
it("should not be able to deposit more than the balance ", async () => {
|
||||||
const { handler, TestingContext } = createWalletApiMock();
|
const { handler, TestingContext } = createWalletApiMock();
|
||||||
const props = { currency, onCancel: nullFunction, onSuccess: nullFunction };
|
const props = { amount, onCancel: nullFunction, onSuccess: nullFunction };
|
||||||
|
|
||||||
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
|
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
|
||||||
balances: [
|
balances: [
|
||||||
@ -273,7 +274,7 @@ describe("DepositPage states", () => {
|
|||||||
|
|
||||||
it("should calculate the fee upon entering amount ", async () => {
|
it("should calculate the fee upon entering amount ", async () => {
|
||||||
const { handler, TestingContext } = createWalletApiMock();
|
const { handler, TestingContext } = createWalletApiMock();
|
||||||
const props = { currency, onCancel: nullFunction, onSuccess: nullFunction };
|
const props = { amount, onCancel: nullFunction, onSuccess: nullFunction };
|
||||||
|
|
||||||
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
|
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
|
||||||
balances: [
|
balances: [
|
||||||
|
Loading…
Reference in New Issue
Block a user