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": {
const wallet = await this.wp.promise;
return await wallet.getWithdrawDetailsForAmount(args.exchangeBaseUrl, args.amount);
return await wallet.getWithdrawalDetailsForAmount(args.exchangeBaseUrl, args.amount);
}
case "withdrawTestkudos": {
const wallet = await this.wp.promise;

View File

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

View File

@ -41,6 +41,7 @@ import {
makeCodecOptional,
Codec,
} from "../util/codec";
import { AmountString } from "./talerTypes";
/**
* Response for the create reserve request to the wallet.
@ -489,3 +490,26 @@ export interface ExchangeListItem {
currency: 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,
AcceptWithdrawalResponse,
PurchaseDetails,
ExchangeWithdrawDetails,
ExchangeWithdrawDetails as ExchangeWithdrawalDetails,
RefreshReason,
ExchangeListItem,
ExchangesListRespose,
ManualWithdrawalDetails,
} from "./types/walletTypes";
import { Logger } from "./util/logging";
@ -166,11 +167,21 @@ export class Wallet {
return getExchangePaytoUri(this.ws, exchangeBaseUrl, supportedTargetTypes);
}
getWithdrawDetailsForAmount(
async getWithdrawalDetailsForAmount(
exchangeBaseUrl: string,
amount: AmountJson,
): Promise<ExchangeWithdrawDetails> {
return getExchangeWithdrawalInfo(this.ws, exchangeBaseUrl, amount);
): Promise<ManualWithdrawalDetails> {
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 {

View File

@ -73,10 +73,6 @@ export interface MessageMap {
request: { baseUrl: string };
response: dbTypes.ExchangeRecord;
};
"reserve-creation-info": {
request: { baseUrl: string; amount: AmountJson };
response: walletTypes.ExchangeWithdrawDetails;
};
"get-history": {
request: {};
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.
*/

View File

@ -139,13 +139,6 @@ async function handleMessage(
}
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": {
// TODO: limit history length
return needsWallet().getHistory();