updated getWithdrawalDetailsForAmount

This commit is contained in:
Florian Dold 2020-07-11 13:26:07 +05:30
parent 6e688975c7
commit afda237e5f
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
7 changed files with 41 additions and 28 deletions

View File

@ -195,7 +195,7 @@ class AndroidWalletMessageHandler {
} }
case "getWithdrawalDetailsForAmount": { case "getWithdrawalDetailsForAmount": {
const wallet = await this.wp.promise; const wallet = await this.wp.promise;
return await wallet.getWithdrawDetailsForAmount(args.exchangeBaseUrl, args.amount); return await wallet.getWithdrawalDetailsForAmount(args.exchangeBaseUrl, args.amount);
} }
case "withdrawTestkudos": { case "withdrawTestkudos": {
const wallet = await this.wp.promise; const wallet = await this.wp.promise;

View File

@ -386,7 +386,7 @@ advancedCli
.requiredArgument("amount", clk.STRING) .requiredArgument("amount", clk.STRING)
.action(async (args) => { .action(async (args) => {
await withWallet(args, async (wallet) => { await withWallet(args, async (wallet) => {
const details = await wallet.getWithdrawDetailsForAmount( const details = await wallet.getWithdrawalDetailsForAmount(
args.manualWithdrawalDetails.exchange, args.manualWithdrawalDetails.exchange,
Amounts.parseOrThrow(args.manualWithdrawalDetails.amount), Amounts.parseOrThrow(args.manualWithdrawalDetails.amount),
); );

View File

@ -41,6 +41,7 @@ import {
makeCodecOptional, makeCodecOptional,
Codec, Codec,
} from "../util/codec"; } from "../util/codec";
import { AmountString } from "./talerTypes";
/** /**
* Response for the create reserve request to the wallet. * Response for the create reserve request to the wallet.
@ -489,3 +490,26 @@ export interface ExchangeListItem {
currency: string; currency: string;
paytoUris: string[]; paytoUris: string[];
} }
export interface ManualWithdrawalDetails {
/**
* Did the user accept the current version of the exchange's
* terms of service?
*/
tosAccepted: boolean;
/**
* Amount that the user will transfer to the exchange.
*/
rawAmount: AmountString;
/**
* Amount that will be added to the user's wallet balance.
*/
effectiveAmount: AmountString;
/**
* Ways to pay the exchange.
*/
paytoUris: string[];
}

View File

@ -67,10 +67,11 @@ import {
WithdrawDetails, WithdrawDetails,
AcceptWithdrawalResponse, AcceptWithdrawalResponse,
PurchaseDetails, PurchaseDetails,
ExchangeWithdrawDetails, ExchangeWithdrawDetails as ExchangeWithdrawalDetails,
RefreshReason, RefreshReason,
ExchangeListItem, ExchangeListItem,
ExchangesListRespose, ExchangesListRespose,
ManualWithdrawalDetails,
} from "./types/walletTypes"; } from "./types/walletTypes";
import { Logger } from "./util/logging"; import { Logger } from "./util/logging";
@ -166,11 +167,21 @@ export class Wallet {
return getExchangePaytoUri(this.ws, exchangeBaseUrl, supportedTargetTypes); return getExchangePaytoUri(this.ws, exchangeBaseUrl, supportedTargetTypes);
} }
getWithdrawDetailsForAmount( async getWithdrawalDetailsForAmount(
exchangeBaseUrl: string, exchangeBaseUrl: string,
amount: AmountJson, amount: AmountJson,
): Promise<ExchangeWithdrawDetails> { ): Promise<ManualWithdrawalDetails> {
return getExchangeWithdrawalInfo(this.ws, exchangeBaseUrl, amount); const wi = await getExchangeWithdrawalInfo(this.ws, exchangeBaseUrl, amount);
const paytoUris = wi.exchangeInfo.wireInfo?.accounts.map((x) => x.payto_uri);
if (!paytoUris) {
throw Error("exchange is in invalid state");
}
return {
rawAmount: Amounts.stringify(amount),
effectiveAmount: Amounts.stringify(wi.selectedDenoms.totalCoinValue),
paytoUris,
tosAccepted: wi.termsOfServiceAccepted,
};
} }
addNotificationListener(f: (n: WalletNotification) => void): void { addNotificationListener(f: (n: WalletNotification) => void): void {

View File

@ -73,10 +73,6 @@ export interface MessageMap {
request: { baseUrl: string }; request: { baseUrl: string };
response: dbTypes.ExchangeRecord; response: dbTypes.ExchangeRecord;
}; };
"reserve-creation-info": {
request: { baseUrl: string; amount: AmountJson };
response: walletTypes.ExchangeWithdrawDetails;
};
"get-history": { "get-history": {
request: {}; request: {};
response: HistoryEvent[]; response: HistoryEvent[];

View File

@ -103,17 +103,6 @@ async function callBackend<T extends MessageType>(
}); });
} }
/**
* Query the wallet for the coins that would be used to withdraw
* from a given reserve.
*/
export function getReserveCreationInfo(
baseUrl: string,
amount: AmountJson,
): Promise<ExchangeWithdrawDetails> {
return callBackend("reserve-creation-info", { baseUrl, amount });
}
/** /**
* Get all exchanges the wallet knows about. * Get all exchanges the wallet knows about.
*/ */

View File

@ -139,13 +139,6 @@ async function handleMessage(
} }
return needsWallet().updateExchangeFromUrl(detail.baseUrl); return needsWallet().updateExchangeFromUrl(detail.baseUrl);
} }
case "reserve-creation-info": {
if (!detail.baseUrl || typeof detail.baseUrl !== "string") {
return Promise.resolve({ error: "bad url" });
}
const amount = codecForAmountJson().decode(detail.amount);
return needsWallet().getWithdrawDetailsForAmount(detail.baseUrl, amount);
}
case "get-history": { case "get-history": {
// TODO: limit history length // TODO: limit history length
return needsWallet().getHistory(); return needsWallet().getHistory();