diff options
Diffstat (limited to 'packages/demobank-ui/src/hooks/circuit.ts')
-rw-r--r-- | packages/demobank-ui/src/hooks/circuit.ts | 63 |
1 files changed, 28 insertions, 35 deletions
diff --git a/packages/demobank-ui/src/hooks/circuit.ts b/packages/demobank-ui/src/hooks/circuit.ts index d0d180a53..c0164d60a 100644 --- a/packages/demobank-ui/src/hooks/circuit.ts +++ b/packages/demobank-ui/src/hooks/circuit.ts @@ -34,9 +34,7 @@ export type TransferCalculation = { }; type EstimatorFunction = ( amount: AmountJson, - currency: string, - sellFee: AmountJson, - sellRate: number, + fee: AmountJson, ) => Promise<TransferCalculation>; type CashoutEstimators = { @@ -73,25 +71,19 @@ export function useEstimator(): CashoutEstimators { const { state } = useBackendState(); const { api } = useBankCoreApiContext(); return { - estimateByCredit: async (fiatAmount, regionalCurrency, fee, rate) => { - // const resp = await api.getConversionInfoAPI().getCashoutRate({ - // credit: amount - // }); - // if (resp.type === "fail") { - // // can't happen - // // not-supported: it should not be able to call this function - // // wrong-calculation: we are using just one parameter - // throw TalerError.fromDetail(resp.detail.code, {}, resp.detail.hint) - // } - const credit = fiatAmount; - const beforeFee = Amounts.sub(credit, fee).amount; - - // const debit = Amounts.parseOrThrow(resp.body.amount_debit); - //FIXME: remove this when endpoint works - const debit = Amounts.add( - Amounts.zeroOfCurrency(regionalCurrency), - beforeFee - ).amount; + estimateByCredit: async (fiatAmount, fee) => { + const resp = await api.getConversionInfoAPI().getCashoutRate({ + credit: fiatAmount + }); + if (resp.type === "fail") { + // can't happen + // not-supported: it should not be able to call this function + // wrong-calculation: we are using just one parameter + throw TalerError.fromDetail(resp.detail.code, {}, resp.detail.hint) + } + const credit = Amounts.parseOrThrow(resp.body.amount_credit); + const debit = Amounts.parseOrThrow(resp.body.amount_debit); + const beforeFee = Amounts.add(credit, fee).amount; return { debit, @@ -99,19 +91,20 @@ export function useEstimator(): CashoutEstimators { credit, }; }, - estimateByDebit: async (regionalAmount, fiatCurrency, fee, rate) => { - // const resp = await api.getConversionInfoAPI().getCashoutRate({ debit: amount }); - // if (resp.type === "fail") { - // // can't happen - // // not-supported: it should not be able to call this function - // // wrong-calculation: we are using just one parameter - // throw TalerError.fromDetail(resp.detail.code, {}, resp.detail.hint) - // } - // const credit = Amounts.parseOrThrow(resp.body.amount_credit); - const debit = regionalAmount; - const _credit = Amounts.parseOrThrow(regionalAmount); - const beforeFee = { ..._credit, currency: fiatCurrency }; - const credit = Amounts.sub(beforeFee, fee).amount; + estimateByDebit: async (regionalAmount, fee) => { + const resp = await api.getConversionInfoAPI().getCashoutRate({ + debit: regionalAmount + }); + if (resp.type === "fail") { + // can't happen + // not-supported: it should not be able to call this function + // wrong-calculation: we are using just one parameter + throw TalerError.fromDetail(resp.detail.code, {}, resp.detail.hint) + } + const credit = Amounts.parseOrThrow(resp.body.amount_credit); + const debit = Amounts.parseOrThrow(resp.body.amount_debit); + const beforeFee = Amounts.add(credit, fee).amount; + return { debit, beforeFee, |