android APIs for withdrawal and exchange listing
This commit is contained in:
parent
2efe743950
commit
63ebe1b2e2
@ -184,6 +184,19 @@ class AndroidWalletMessageHandler {
|
|||||||
const wallet = await this.wp.promise;
|
const wallet = await this.wp.promise;
|
||||||
return await wallet.getPendingOperations();
|
return await wallet.getPendingOperations();
|
||||||
}
|
}
|
||||||
|
case "listExchanges": {
|
||||||
|
const wallet = await this.wp.promise;
|
||||||
|
return await wallet.getExchanges();
|
||||||
|
}
|
||||||
|
case "addExchange": {
|
||||||
|
const wallet = await this.wp.promise;
|
||||||
|
await wallet.updateExchangeFromUrl(args.exchangeBaseUrl);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
case "getWithdrawalDetailsForAmount": {
|
||||||
|
const wallet = await this.wp.promise;
|
||||||
|
return await wallet.getWithdrawDetailsForAmount(args.exchangeBaseUrl, args.amount);
|
||||||
|
}
|
||||||
case "withdrawTestkudos": {
|
case "withdrawTestkudos": {
|
||||||
const wallet = await this.wp.promise;
|
const wallet = await this.wp.promise;
|
||||||
try {
|
try {
|
||||||
|
@ -7,7 +7,7 @@ import { openDatabase, Database, Store, Index } from "./util/query";
|
|||||||
* with each major change. When incrementing the major version,
|
* with each major change. When incrementing the major version,
|
||||||
* the wallet should import data from the previous version.
|
* the wallet should import data from the previous version.
|
||||||
*/
|
*/
|
||||||
const TALER_DB_NAME = "taler-walletdb-v4";
|
const TALER_DB_NAME = "taler-walletdb-v5";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current database minor version, should be incremented
|
* Current database minor version, should be incremented
|
||||||
@ -16,7 +16,7 @@ const TALER_DB_NAME = "taler-walletdb-v4";
|
|||||||
* backwards-compatible way or object stores and indices
|
* backwards-compatible way or object stores and indices
|
||||||
* are added.
|
* are added.
|
||||||
*/
|
*/
|
||||||
export const WALLET_DB_VERSION = 1;
|
export const WALLET_DB_MINOR_VERSION = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a promise that resolves
|
* Return a promise that resolves
|
||||||
@ -54,7 +54,7 @@ export function openTalerDatabase(
|
|||||||
return openDatabase(
|
return openDatabase(
|
||||||
idbFactory,
|
idbFactory,
|
||||||
TALER_DB_NAME,
|
TALER_DB_NAME,
|
||||||
WALLET_DB_VERSION,
|
WALLET_DB_MINOR_VERSION,
|
||||||
onVersionChange,
|
onVersionChange,
|
||||||
onUpgradeNeeded,
|
onUpgradeNeeded,
|
||||||
);
|
);
|
||||||
|
@ -337,7 +337,7 @@ exchangesCli
|
|||||||
console.log("Listing exchanges ...");
|
console.log("Listing exchanges ...");
|
||||||
await withWallet(args, async (wallet) => {
|
await withWallet(args, async (wallet) => {
|
||||||
const exchanges = await wallet.getExchanges();
|
const exchanges = await wallet.getExchanges();
|
||||||
console.log("exchanges", exchanges);
|
console.log(JSON.stringify(exchanges, undefined, 2));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -358,11 +358,42 @@ exchangesCli
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
exchangesCli
|
||||||
|
.subcommand("exchangesAddCmd", "add", {
|
||||||
|
help: "Add an exchange by base URL.",
|
||||||
|
})
|
||||||
|
.requiredArgument("url", clk.STRING, {
|
||||||
|
help: "Base URL of the exchange.",
|
||||||
|
})
|
||||||
|
.action(async (args) => {
|
||||||
|
await withWallet(args, async (wallet) => {
|
||||||
|
await wallet.updateExchangeFromUrl(
|
||||||
|
args.exchangesAddCmd.url,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const advancedCli = walletCli.subcommand("advancedArgs", "advanced", {
|
const advancedCli = walletCli.subcommand("advancedArgs", "advanced", {
|
||||||
help:
|
help:
|
||||||
"Subcommands for advanced operations (only use if you know what you're doing!).",
|
"Subcommands for advanced operations (only use if you know what you're doing!).",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
advancedCli
|
||||||
|
.subcommand("manualWithdrawalDetails", "manual-withdrawal-details", {
|
||||||
|
help: "Query withdrawal fees.",
|
||||||
|
})
|
||||||
|
.requiredArgument("exchange", clk.STRING)
|
||||||
|
.requiredArgument("amount", clk.STRING)
|
||||||
|
.action(async (args) => {
|
||||||
|
await withWallet(args, async (wallet) => {
|
||||||
|
const details = await wallet.getWithdrawDetailsForAmount(
|
||||||
|
args.manualWithdrawalDetails.exchange,
|
||||||
|
Amounts.parseOrThrow(args.manualWithdrawalDetails.amount),
|
||||||
|
);
|
||||||
|
console.log(JSON.stringify(details, undefined, 2));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
advancedCli
|
advancedCli
|
||||||
.subcommand("decode", "decode", {
|
.subcommand("decode", "decode", {
|
||||||
help: "Decode base32-crockford.",
|
help: "Decode base32-crockford.",
|
||||||
|
@ -301,6 +301,7 @@ async function updateExchangeFinalize(
|
|||||||
if (r.updateStatus != ExchangeUpdateStatus.FinalizeUpdate) {
|
if (r.updateStatus != ExchangeUpdateStatus.FinalizeUpdate) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
r.addComplete = true;
|
||||||
r.updateStatus = ExchangeUpdateStatus.Finished;
|
r.updateStatus = ExchangeUpdateStatus.Finished;
|
||||||
await tx.put(Stores.exchanges, r);
|
await tx.put(Stores.exchanges, r);
|
||||||
const updateEvent: ExchangeUpdatedEventRecord = {
|
const updateEvent: ExchangeUpdatedEventRecord = {
|
||||||
@ -485,6 +486,8 @@ async function updateExchangeFromUrlImpl(
|
|||||||
if (!r) {
|
if (!r) {
|
||||||
const newExchangeRecord: ExchangeRecord = {
|
const newExchangeRecord: ExchangeRecord = {
|
||||||
builtIn: false,
|
builtIn: false,
|
||||||
|
addComplete: false,
|
||||||
|
permanent: true,
|
||||||
baseUrl: baseUrl,
|
baseUrl: baseUrl,
|
||||||
details: undefined,
|
details: undefined,
|
||||||
wireInfo: undefined,
|
wireInfo: undefined,
|
||||||
|
@ -555,6 +555,16 @@ export interface ExchangeRecord {
|
|||||||
*/
|
*/
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Did we finish adding the exchange?
|
||||||
|
*/
|
||||||
|
addComplete: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this a permanent or temporary exchange record?
|
||||||
|
*/
|
||||||
|
permanent: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Was the exchange added as a built-in exchange?
|
* Was the exchange added as a built-in exchange?
|
||||||
*/
|
*/
|
||||||
@ -601,6 +611,9 @@ export interface ExchangeRecord {
|
|||||||
*/
|
*/
|
||||||
updateStarted: Timestamp | undefined;
|
updateStarted: Timestamp | undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Status of updating the info about the exchange.
|
||||||
|
*/
|
||||||
updateStatus: ExchangeUpdateStatus;
|
updateStatus: ExchangeUpdateStatus;
|
||||||
|
|
||||||
updateReason?: ExchangeUpdateReason;
|
updateReason?: ExchangeUpdateReason;
|
||||||
|
@ -479,3 +479,13 @@ export interface DepositInfo {
|
|||||||
export interface ExtendedPermissionsResponse {
|
export interface ExtendedPermissionsResponse {
|
||||||
newValue: boolean;
|
newValue: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ExchangesListRespose {
|
||||||
|
exchanges: ExchangeListItem[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ExchangeListItem {
|
||||||
|
exchangeBaseUrl: string;
|
||||||
|
currency: string;
|
||||||
|
paytoUris: string[];
|
||||||
|
}
|
||||||
|
@ -69,6 +69,8 @@ import {
|
|||||||
PurchaseDetails,
|
PurchaseDetails,
|
||||||
ExchangeWithdrawDetails,
|
ExchangeWithdrawDetails,
|
||||||
RefreshReason,
|
RefreshReason,
|
||||||
|
ExchangeListItem,
|
||||||
|
ExchangesListRespose,
|
||||||
} from "./types/walletTypes";
|
} from "./types/walletTypes";
|
||||||
import { Logger } from "./util/logging";
|
import { Logger } from "./util/logging";
|
||||||
|
|
||||||
@ -549,10 +551,40 @@ export class Wallet {
|
|||||||
return denoms;
|
return denoms;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getExchanges(): Promise<ExchangeRecord[]> {
|
/**
|
||||||
|
* Get all exchanges known to the exchange.
|
||||||
|
*
|
||||||
|
* @deprecated Use getExchanges instead
|
||||||
|
*/
|
||||||
|
async getExchangeRecords(): Promise<ExchangeRecord[]> {
|
||||||
return await this.db.iter(Stores.exchanges).toArray();
|
return await this.db.iter(Stores.exchanges).toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getExchanges(): Promise<ExchangesListRespose> {
|
||||||
|
const exchanges: (ExchangeListItem | undefined)[] = await this.db
|
||||||
|
.iter(Stores.exchanges)
|
||||||
|
.map((x) => {
|
||||||
|
const details = x.details;
|
||||||
|
if (!details) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
if (!x.addComplete) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
if (!x.wireInfo) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
exchangeBaseUrl: x.baseUrl,
|
||||||
|
currency: details.currency,
|
||||||
|
paytoUris: x.wireInfo.accounts.map(x => x.payto_uri),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
exchanges: exchanges.filter((x) => !!x) as ExchangeListItem[],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
async getCurrencies(): Promise<CurrencyRecord[]> {
|
async getCurrencies(): Promise<CurrencyRecord[]> {
|
||||||
return await this.db.iter(Stores.currencies).toArray();
|
return await this.db.iter(Stores.currencies).toArray();
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ import { BrowserCryptoWorkerFactory } from "../crypto/workers/cryptoApi";
|
|||||||
import {
|
import {
|
||||||
deleteTalerDatabase,
|
deleteTalerDatabase,
|
||||||
openTalerDatabase,
|
openTalerDatabase,
|
||||||
WALLET_DB_VERSION,
|
WALLET_DB_MINOR_VERSION,
|
||||||
} from "../db";
|
} from "../db";
|
||||||
import {
|
import {
|
||||||
ReturnCoinsRequest,
|
ReturnCoinsRequest,
|
||||||
@ -151,7 +151,7 @@ async function handleMessage(
|
|||||||
return needsWallet().getHistory();
|
return needsWallet().getHistory();
|
||||||
}
|
}
|
||||||
case "get-exchanges": {
|
case "get-exchanges": {
|
||||||
return needsWallet().getExchanges();
|
return needsWallet().getExchangeRecords();
|
||||||
}
|
}
|
||||||
case "get-currencies": {
|
case "get-currencies": {
|
||||||
return needsWallet().getCurrencies();
|
return needsWallet().getCurrencies();
|
||||||
@ -201,7 +201,7 @@ async function handleMessage(
|
|||||||
dbResetRequired = true;
|
dbResetRequired = true;
|
||||||
}
|
}
|
||||||
const resp: wxApi.UpgradeResponse = {
|
const resp: wxApi.UpgradeResponse = {
|
||||||
currentDbVersion: WALLET_DB_VERSION.toString(),
|
currentDbVersion: WALLET_DB_MINOR_VERSION.toString(),
|
||||||
dbResetRequired,
|
dbResetRequired,
|
||||||
oldDbVersion: (outdatedDbVersion || "unknown").toString(),
|
oldDbVersion: (outdatedDbVersion || "unknown").toString(),
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user