2016-02-19 04:23:00 +01:00
|
|
|
/*
|
2022-06-06 17:05:26 +02:00
|
|
|
This file is part of GNU Taler
|
|
|
|
(C) 2022 Taler Systems S.A.
|
2016-02-19 04:23:00 +01:00
|
|
|
|
2022-06-06 17:05:26 +02:00
|
|
|
GNU Taler is free software; you can redistribute it and/or modify it under the
|
2016-02-19 04:23:00 +01:00
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 3, or (at your option) any later version.
|
|
|
|
|
2022-06-06 17:05:26 +02:00
|
|
|
GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
|
2016-02-19 04:23:00 +01:00
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
2022-06-06 17:05:26 +02:00
|
|
|
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
2016-02-19 04:23:00 +01:00
|
|
|
*/
|
|
|
|
|
2017-05-28 16:27:34 +02:00
|
|
|
/**
|
|
|
|
* Interface to the wallet through WebExtension messaging.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Imports.
|
|
|
|
*/
|
2020-08-13 20:43:51 +02:00
|
|
|
import {
|
2021-09-13 20:32:06 +02:00
|
|
|
AcceptExchangeTosRequest,
|
2022-03-22 21:16:38 +01:00
|
|
|
AcceptManualWithdrawalResult,
|
2022-10-14 16:40:38 +02:00
|
|
|
AcceptPeerPullPaymentRequest,
|
|
|
|
AcceptPeerPullPaymentResponse,
|
|
|
|
AcceptPeerPushPaymentRequest,
|
|
|
|
AcceptPeerPushPaymentResponse,
|
|
|
|
AcceptTipRequest,
|
|
|
|
AcceptTipResponse,
|
|
|
|
AcceptWithdrawalResponse,
|
|
|
|
AddExchangeRequest,
|
|
|
|
AddKnownBankAccountsRequest,
|
|
|
|
AmountString,
|
2022-03-22 21:16:38 +01:00
|
|
|
ApplyRefundResponse,
|
|
|
|
BalancesResponse,
|
2022-08-31 05:20:35 +02:00
|
|
|
CheckPeerPullPaymentRequest,
|
|
|
|
CheckPeerPullPaymentResponse,
|
|
|
|
CheckPeerPushPaymentRequest,
|
|
|
|
CheckPeerPushPaymentResponse,
|
2022-03-22 21:16:38 +01:00
|
|
|
CoinDumpJson,
|
|
|
|
ConfirmPayResult,
|
|
|
|
CoreApiResponse,
|
|
|
|
CreateDepositGroupRequest,
|
|
|
|
CreateDepositGroupResponse,
|
2022-10-14 16:40:38 +02:00
|
|
|
DeleteTransactionRequest,
|
|
|
|
DepositGroupFees,
|
|
|
|
ExchangeFullDetails,
|
|
|
|
ExchangesListResponse,
|
|
|
|
ForgetKnownBankAccountsRequest,
|
|
|
|
GetExchangeTosResult,
|
2021-12-23 19:17:36 +01:00
|
|
|
GetFeeForDepositRequest,
|
2022-10-14 18:40:04 +02:00
|
|
|
GetWithdrawalDetailsForAmountRequest,
|
2022-03-22 21:16:38 +01:00
|
|
|
GetWithdrawalDetailsForUriRequest,
|
2022-08-31 05:20:35 +02:00
|
|
|
InitiatePeerPullPaymentRequest,
|
|
|
|
InitiatePeerPullPaymentResponse,
|
|
|
|
InitiatePeerPushPaymentRequest,
|
|
|
|
InitiatePeerPushPaymentResponse,
|
2022-03-22 21:16:38 +01:00
|
|
|
KnownBankAccounts,
|
2022-06-09 19:16:28 +02:00
|
|
|
Logger,
|
2022-10-14 18:40:04 +02:00
|
|
|
ManualWithdrawalDetails,
|
2022-10-14 16:40:38 +02:00
|
|
|
NotificationType,
|
|
|
|
PaytoUri,
|
|
|
|
PrepareDepositRequest,
|
2022-05-03 05:16:03 +02:00
|
|
|
PrepareDepositResponse,
|
2022-03-22 21:16:38 +01:00
|
|
|
PreparePayResult,
|
2022-05-03 00:21:34 +02:00
|
|
|
PrepareRefundRequest,
|
|
|
|
PrepareRefundResult,
|
2022-03-22 21:16:38 +01:00
|
|
|
PrepareTipRequest,
|
|
|
|
PrepareTipResult,
|
|
|
|
RetryTransactionRequest,
|
2022-10-14 16:40:38 +02:00
|
|
|
SetWalletDeviceIdRequest,
|
|
|
|
stringifyPaytoUri,
|
|
|
|
Transaction,
|
|
|
|
TransactionsResponse,
|
|
|
|
WalletCoreVersion,
|
|
|
|
WalletDiagnostics,
|
|
|
|
WithdrawUriInfoResponse,
|
2021-03-27 14:35:58 +01:00
|
|
|
} from "@gnu-taler/taler-util";
|
2021-11-15 15:18:58 +01:00
|
|
|
import {
|
2022-03-22 21:16:38 +01:00
|
|
|
AddBackupProviderRequest,
|
|
|
|
BackupInfo,
|
2021-11-29 17:33:01 +01:00
|
|
|
PendingOperationsResponse,
|
2022-03-22 21:16:38 +01:00
|
|
|
RemoveBackupProviderRequest,
|
|
|
|
TalerError,
|
2022-10-16 23:11:34 +02:00
|
|
|
WalletApiOperation,
|
2022-10-14 16:40:38 +02:00
|
|
|
WalletContractData,
|
2022-10-16 23:11:34 +02:00
|
|
|
WalletCoreApiClient,
|
|
|
|
WalletCoreOpKeys,
|
|
|
|
WalletCoreRequestType,
|
|
|
|
WalletCoreResponseType,
|
2021-11-15 15:18:58 +01:00
|
|
|
} from "@gnu-taler/taler-wallet-core";
|
2022-09-23 20:18:18 +02:00
|
|
|
import { MessageFromBackend, platform } from "./platform/api.js";
|
2020-08-03 09:30:48 +02:00
|
|
|
|
2022-02-23 19:18:37 +01:00
|
|
|
/**
|
2022-03-22 21:16:38 +01:00
|
|
|
*
|
2022-06-26 20:52:32 +02:00
|
|
|
* @author Florian Dold
|
|
|
|
* @author sebasjm
|
2022-02-23 19:18:37 +01:00
|
|
|
*/
|
|
|
|
|
2020-08-03 09:30:48 +02:00
|
|
|
export interface ExtendedPermissionsResponse {
|
|
|
|
newValue: boolean;
|
|
|
|
}
|
2022-06-09 19:16:28 +02:00
|
|
|
const logger = new Logger("wxApi");
|
2020-08-03 09:30:48 +02:00
|
|
|
|
2017-06-05 03:20:28 +02:00
|
|
|
/**
|
|
|
|
* Response with information about available version upgrades.
|
|
|
|
*/
|
|
|
|
export interface UpgradeResponse {
|
|
|
|
/**
|
|
|
|
* Is a reset required because of a new DB version
|
2021-04-27 23:42:25 +02:00
|
|
|
* that can't be automatically upgraded?
|
2017-06-05 03:20:28 +02:00
|
|
|
*/
|
|
|
|
dbResetRequired: boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Current database version.
|
|
|
|
*/
|
|
|
|
currentDbVersion: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Old db version (if applicable).
|
|
|
|
*/
|
|
|
|
oldDbVersion: string;
|
|
|
|
}
|
|
|
|
|
2022-10-16 23:11:34 +02:00
|
|
|
/**
|
|
|
|
* @deprecated Use {@link WxWalletCoreApiClient} instead.
|
|
|
|
*/
|
2020-08-13 20:43:51 +02:00
|
|
|
async function callBackend(operation: string, payload: any): Promise<any> {
|
2022-03-23 14:50:12 +01:00
|
|
|
let response: CoreApiResponse;
|
|
|
|
try {
|
2022-03-25 20:57:27 +01:00
|
|
|
response = await platform.sendMessageToWalletBackground(operation, payload);
|
2022-03-23 14:50:12 +01:00
|
|
|
} catch (e) {
|
|
|
|
console.log("Error calling backend");
|
2022-03-23 21:24:23 +01:00
|
|
|
throw new Error(`Error contacting backend: ${e}`);
|
2022-03-23 14:50:12 +01:00
|
|
|
}
|
2022-06-09 19:16:28 +02:00
|
|
|
logger.info("got response", response);
|
2022-03-23 14:50:12 +01:00
|
|
|
if (response.type === "error") {
|
2022-03-23 20:20:39 +01:00
|
|
|
throw TalerError.fromUncheckedDetail(response.error);
|
2022-03-23 14:50:12 +01:00
|
|
|
}
|
|
|
|
return response.result;
|
2016-10-12 02:55:53 +02:00
|
|
|
}
|
|
|
|
|
2022-10-16 23:11:34 +02:00
|
|
|
export class WxWalletCoreApiClient implements WalletCoreApiClient {
|
|
|
|
async call<Op extends WalletCoreOpKeys>(
|
|
|
|
operation: Op,
|
|
|
|
payload: WalletCoreRequestType<Op>,
|
|
|
|
): Promise<WalletCoreResponseType<Op>> {
|
|
|
|
let response: CoreApiResponse;
|
|
|
|
try {
|
|
|
|
response = await platform.sendMessageToWalletBackground(
|
|
|
|
operation,
|
|
|
|
payload,
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
console.log("Error calling backend");
|
|
|
|
throw new Error(`Error contacting backend: ${e}`);
|
|
|
|
}
|
|
|
|
logger.info("got response", response);
|
|
|
|
if (response.type === "error") {
|
|
|
|
throw TalerError.fromUncheckedDetail(response.error);
|
|
|
|
}
|
|
|
|
return response.result as any;
|
|
|
|
}
|
2016-11-13 08:16:12 +01:00
|
|
|
}
|
2017-05-01 04:33:47 +02:00
|
|
|
|
2022-10-16 23:11:34 +02:00
|
|
|
const wxClient = new WxWalletCoreApiClient();
|
|
|
|
|
2017-05-29 16:27:53 +02:00
|
|
|
/**
|
2017-05-31 16:04:14 +02:00
|
|
|
* Pay for a proposal.
|
2017-05-29 16:27:53 +02:00
|
|
|
*/
|
2020-03-11 20:14:28 +01:00
|
|
|
export function confirmPay(
|
|
|
|
proposalId: string,
|
|
|
|
sessionId: string | undefined,
|
2020-08-12 09:11:00 +02:00
|
|
|
): Promise<ConfirmPayResult> {
|
2022-10-16 23:11:34 +02:00
|
|
|
return wxClient.call(WalletApiOperation.ConfirmPay, {
|
|
|
|
proposalId,
|
|
|
|
sessionId,
|
|
|
|
});
|
2017-05-30 18:33:28 +02:00
|
|
|
}
|
|
|
|
|
2017-06-05 03:20:28 +02:00
|
|
|
/**
|
|
|
|
* Check upgrade information
|
|
|
|
*/
|
|
|
|
export function checkUpgrade(): Promise<UpgradeResponse> {
|
2020-03-11 20:14:28 +01:00
|
|
|
return callBackend("check-upgrade", {});
|
2017-06-05 03:20:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset database
|
|
|
|
*/
|
|
|
|
export function resetDb(): Promise<void> {
|
2020-03-11 20:14:28 +01:00
|
|
|
return callBackend("reset-db", {});
|
2017-06-05 03:20:28 +02:00
|
|
|
}
|
2017-08-14 04:16:12 +02:00
|
|
|
|
2022-04-29 18:16:29 +02:00
|
|
|
/**
|
|
|
|
* Reset database
|
|
|
|
*/
|
|
|
|
export function runGarbageCollector(): Promise<void> {
|
|
|
|
return callBackend("run-gc", {});
|
|
|
|
}
|
|
|
|
|
2022-03-22 21:16:38 +01:00
|
|
|
export function getFeeForDeposit(
|
|
|
|
depositPaytoUri: string,
|
|
|
|
amount: AmountString,
|
2022-03-29 13:47:32 +02:00
|
|
|
): Promise<DepositGroupFees> {
|
2021-12-23 19:17:36 +01:00
|
|
|
return callBackend("getFeeForDeposit", {
|
2022-03-22 21:16:38 +01:00
|
|
|
depositPaytoUri,
|
|
|
|
amount,
|
2021-12-23 19:17:36 +01:00
|
|
|
} as GetFeeForDepositRequest);
|
|
|
|
}
|
|
|
|
|
2022-05-03 05:16:03 +02:00
|
|
|
export function prepareDeposit(
|
|
|
|
depositPaytoUri: string,
|
|
|
|
amount: AmountString,
|
|
|
|
): Promise<PrepareDepositResponse> {
|
|
|
|
return callBackend("prepareDeposit", {
|
|
|
|
depositPaytoUri,
|
|
|
|
amount,
|
|
|
|
} as PrepareDepositRequest);
|
|
|
|
}
|
|
|
|
|
2022-03-22 21:16:38 +01:00
|
|
|
export function createDepositGroup(
|
|
|
|
depositPaytoUri: string,
|
|
|
|
amount: AmountString,
|
|
|
|
): Promise<CreateDepositGroupResponse> {
|
2021-12-23 19:17:36 +01:00
|
|
|
return callBackend("createDepositGroup", {
|
2022-03-22 21:16:38 +01:00
|
|
|
depositPaytoUri,
|
|
|
|
amount,
|
2021-12-23 19:17:36 +01:00
|
|
|
} as CreateDepositGroupRequest);
|
|
|
|
}
|
|
|
|
|
2017-08-14 04:16:12 +02:00
|
|
|
/**
|
|
|
|
* Get balances for all currencies/exchanges.
|
|
|
|
*/
|
2020-08-12 09:11:00 +02:00
|
|
|
export function getBalance(): Promise<BalancesResponse> {
|
2020-08-13 20:43:51 +02:00
|
|
|
return callBackend("getBalances", {});
|
2017-08-14 04:16:12 +02:00
|
|
|
}
|
|
|
|
|
2022-09-05 21:09:28 +02:00
|
|
|
export function getContractTermsDetails(
|
|
|
|
proposalId: string,
|
|
|
|
): Promise<WalletContractData> {
|
2022-08-08 19:09:28 +02:00
|
|
|
return callBackend("getContractTermsDetails", { proposalId });
|
|
|
|
}
|
|
|
|
|
2020-08-20 08:29:06 +02:00
|
|
|
/**
|
2021-06-30 23:24:08 +02:00
|
|
|
* Retrieve the full event history for this wallet.
|
2020-08-20 08:29:06 +02:00
|
|
|
*/
|
|
|
|
export function getTransactions(): Promise<TransactionsResponse> {
|
|
|
|
return callBackend("getTransactions", {});
|
|
|
|
}
|
|
|
|
|
2021-07-01 05:35:41 +02:00
|
|
|
interface CurrencyInfo {
|
|
|
|
name: string;
|
|
|
|
baseUrl: string;
|
|
|
|
pub: string;
|
|
|
|
}
|
|
|
|
interface ListOfKnownCurrencies {
|
2021-11-15 15:18:58 +01:00
|
|
|
auditors: CurrencyInfo[];
|
|
|
|
exchanges: CurrencyInfo[];
|
2021-07-01 05:35:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of currencies from known auditors and exchanges
|
|
|
|
*/
|
|
|
|
export function listKnownCurrencies(): Promise<ListOfKnownCurrencies> {
|
2021-11-15 15:18:58 +01:00
|
|
|
return callBackend("listCurrencies", {}).then((result) => {
|
|
|
|
const auditors = result.trustedAuditors.map(
|
|
|
|
(a: Record<string, string>) => ({
|
|
|
|
name: a.currency,
|
|
|
|
baseUrl: a.auditorBaseUrl,
|
|
|
|
pub: a.auditorPub,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
const exchanges = result.trustedExchanges.map(
|
|
|
|
(a: Record<string, string>) => ({
|
|
|
|
name: a.currency,
|
|
|
|
baseUrl: a.exchangeBaseUrl,
|
|
|
|
pub: a.exchangeMasterPub,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
return { auditors, exchanges };
|
2021-07-01 05:35:41 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-09-06 22:17:44 +02:00
|
|
|
export function listExchanges(): Promise<ExchangesListResponse> {
|
2021-11-15 15:18:58 +01:00
|
|
|
return callBackend("listExchanges", {});
|
2021-10-11 20:59:55 +02:00
|
|
|
}
|
2022-09-05 21:09:28 +02:00
|
|
|
|
2022-09-16 19:29:35 +02:00
|
|
|
export function getExchangeDetailedInfo(
|
|
|
|
exchangeBaseUrl: string,
|
|
|
|
): Promise<ExchangeFullDetails> {
|
2022-09-06 22:17:44 +02:00
|
|
|
return callBackend("getExchangeDetailedInfo", {
|
2022-09-16 19:29:35 +02:00
|
|
|
exchangeBaseUrl,
|
2022-09-06 22:17:44 +02:00
|
|
|
});
|
2022-09-05 21:09:28 +02:00
|
|
|
}
|
|
|
|
|
2022-09-05 15:04:56 +02:00
|
|
|
export function getVersion(): Promise<WalletCoreVersion> {
|
|
|
|
return callBackend("getVersion", {});
|
|
|
|
}
|
2022-09-05 21:09:28 +02:00
|
|
|
|
2022-03-22 21:16:38 +01:00
|
|
|
export function listKnownBankAccounts(
|
|
|
|
currency?: string,
|
|
|
|
): Promise<KnownBankAccounts> {
|
2021-12-23 19:17:36 +01:00
|
|
|
return callBackend("listKnownBankAccounts", { currency });
|
|
|
|
}
|
2021-10-11 20:59:55 +02:00
|
|
|
|
2022-09-23 20:18:18 +02:00
|
|
|
export function addKnownBankAccounts(
|
|
|
|
payto: PaytoUri,
|
|
|
|
currency: string,
|
|
|
|
alias: string,
|
|
|
|
): Promise<void> {
|
|
|
|
return callBackend("addKnownBankAccounts", {
|
|
|
|
payto: stringifyPaytoUri(payto),
|
|
|
|
currency,
|
2022-10-14 16:40:38 +02:00
|
|
|
alias,
|
2022-09-23 20:18:18 +02:00
|
|
|
} as AddKnownBankAccountsRequest);
|
|
|
|
}
|
2022-10-14 16:40:38 +02:00
|
|
|
export function forgetKnownBankAccounts(payto: string): Promise<void> {
|
|
|
|
return callBackend("forgetKnownBankAccounts", {
|
|
|
|
payto,
|
|
|
|
} as ForgetKnownBankAccountsRequest);
|
2022-09-23 20:18:18 +02:00
|
|
|
}
|
|
|
|
|
2021-06-30 23:24:08 +02:00
|
|
|
/**
|
2021-07-01 05:35:41 +02:00
|
|
|
* Get information about the current state of wallet backups.
|
2021-06-30 23:24:08 +02:00
|
|
|
*/
|
2021-07-01 16:33:26 +02:00
|
|
|
export function getBackupInfo(): Promise<BackupInfo> {
|
2021-11-15 15:18:58 +01:00
|
|
|
return callBackend("getBackupInfo", {});
|
2021-06-30 23:24:08 +02:00
|
|
|
}
|
2021-07-01 16:33:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a backup provider and activate it
|
|
|
|
*/
|
2021-11-15 15:18:58 +01:00
|
|
|
export function addBackupProvider(
|
|
|
|
backupProviderBaseUrl: string,
|
|
|
|
name: string,
|
|
|
|
): Promise<void> {
|
2021-07-01 16:33:26 +02:00
|
|
|
return callBackend("addBackupProvider", {
|
2021-11-15 15:18:58 +01:00
|
|
|
backupProviderBaseUrl,
|
|
|
|
activate: true,
|
|
|
|
name,
|
|
|
|
} as AddBackupProviderRequest);
|
2021-07-01 16:33:26 +02:00
|
|
|
}
|
|
|
|
|
2021-07-06 17:44:25 +02:00
|
|
|
export function setWalletDeviceId(walletDeviceId: string): Promise<void> {
|
|
|
|
return callBackend("setWalletDeviceId", {
|
2021-11-15 15:18:58 +01:00
|
|
|
walletDeviceId,
|
|
|
|
} as SetWalletDeviceIdRequest);
|
2021-07-06 17:44:25 +02:00
|
|
|
}
|
|
|
|
|
2021-07-01 16:33:26 +02:00
|
|
|
export function syncAllProviders(): Promise<void> {
|
2021-11-15 15:18:58 +01:00
|
|
|
return callBackend("runBackupCycle", {});
|
2021-07-01 16:33:26 +02:00
|
|
|
}
|
|
|
|
|
2021-07-08 20:23:53 +02:00
|
|
|
export function syncOneProvider(url: string): Promise<void> {
|
2021-11-15 15:18:58 +01:00
|
|
|
return callBackend("runBackupCycle", { providers: [url] });
|
2021-07-08 20:23:53 +02:00
|
|
|
}
|
|
|
|
export function removeProvider(url: string): Promise<void> {
|
2021-11-15 15:18:58 +01:00
|
|
|
return callBackend("removeBackupProvider", {
|
|
|
|
provider: url,
|
|
|
|
} as RemoveBackupProviderRequest);
|
2021-07-08 20:23:53 +02:00
|
|
|
}
|
|
|
|
export function extendedProvider(url: string): Promise<void> {
|
2021-11-15 15:18:58 +01:00
|
|
|
return callBackend("extendBackupProvider", { provider: url });
|
2021-07-08 20:23:53 +02:00
|
|
|
}
|
2021-07-01 16:33:26 +02:00
|
|
|
|
2021-06-03 06:07:29 +02:00
|
|
|
/**
|
2021-06-28 16:38:29 +02:00
|
|
|
* Retry a transaction
|
2021-11-15 15:18:58 +01:00
|
|
|
* @param transactionId
|
|
|
|
* @returns
|
2021-06-28 16:38:29 +02:00
|
|
|
*/
|
2021-07-01 05:35:41 +02:00
|
|
|
export function retryTransaction(transactionId: string): Promise<void> {
|
2021-06-28 16:38:29 +02:00
|
|
|
return callBackend("retryTransaction", {
|
2021-11-15 15:18:58 +01:00
|
|
|
transactionId,
|
2021-06-28 16:38:29 +02:00
|
|
|
} as RetryTransactionRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Permanently delete a transaction from the transaction list
|
2021-06-03 06:07:29 +02:00
|
|
|
*/
|
|
|
|
export function deleteTransaction(transactionId: string): Promise<void> {
|
|
|
|
return callBackend("deleteTransaction", {
|
2021-11-15 15:18:58 +01:00
|
|
|
transactionId,
|
2021-06-03 06:07:29 +02:00
|
|
|
} as DeleteTransactionRequest);
|
|
|
|
}
|
|
|
|
|
2018-01-22 01:12:08 +01:00
|
|
|
/**
|
|
|
|
* Download a refund and accept it.
|
|
|
|
*/
|
2020-05-15 09:23:35 +02:00
|
|
|
export function applyRefund(
|
2020-08-21 17:26:25 +02:00
|
|
|
talerRefundUri: string,
|
2020-09-09 09:15:49 +02:00
|
|
|
): Promise<ApplyRefundResponse> {
|
2020-08-21 17:26:25 +02:00
|
|
|
return callBackend("applyRefund", { talerRefundUri });
|
2018-09-20 02:56:13 +02:00
|
|
|
}
|
2019-08-29 23:12:55 +02:00
|
|
|
|
2022-05-29 06:23:15 +02:00
|
|
|
/**
|
|
|
|
* Do refund for purchase.
|
|
|
|
*/
|
|
|
|
export function applyRefundFromPurchaseId(
|
|
|
|
purchaseId: string,
|
|
|
|
): Promise<ApplyRefundResponse> {
|
|
|
|
return callBackend("applyRefundFromPurchaseId", { purchaseId });
|
|
|
|
}
|
|
|
|
|
2019-08-29 23:12:55 +02:00
|
|
|
/**
|
|
|
|
* Get details about a pay operation.
|
|
|
|
*/
|
2020-08-12 09:11:00 +02:00
|
|
|
export function preparePay(talerPayUri: string): Promise<PreparePayResult> {
|
2020-08-19 16:09:21 +02:00
|
|
|
return callBackend("preparePay", { talerPayUri });
|
2019-08-29 23:12:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get details about a withdraw operation.
|
|
|
|
*/
|
2020-03-11 20:14:28 +01:00
|
|
|
export function acceptWithdrawal(
|
|
|
|
talerWithdrawUri: string,
|
|
|
|
selectedExchange: string,
|
2022-05-04 21:25:53 +02:00
|
|
|
restrictAge?: number,
|
2020-08-12 09:11:00 +02:00
|
|
|
): Promise<AcceptWithdrawalResponse> {
|
2020-08-19 16:09:21 +02:00
|
|
|
return callBackend("acceptBankIntegratedWithdrawal", {
|
2020-03-11 20:14:28 +01:00
|
|
|
talerWithdrawUri,
|
2020-08-19 16:09:21 +02:00
|
|
|
exchangeBaseUrl: selectedExchange,
|
2022-06-06 05:09:25 +02:00
|
|
|
restrictAge,
|
2020-03-11 20:14:28 +01:00
|
|
|
});
|
2019-08-30 17:27:59 +02:00
|
|
|
}
|
2019-09-05 16:10:53 +02:00
|
|
|
|
2021-09-20 19:05:40 +02:00
|
|
|
/**
|
|
|
|
* Create a reserve into the exchange that expect the amount indicated
|
2021-11-15 15:18:58 +01:00
|
|
|
* @param exchangeBaseUrl
|
|
|
|
* @param amount
|
|
|
|
* @returns
|
2021-09-20 19:05:40 +02:00
|
|
|
*/
|
|
|
|
export function acceptManualWithdrawal(
|
|
|
|
exchangeBaseUrl: string,
|
|
|
|
amount: string,
|
2022-05-04 21:25:53 +02:00
|
|
|
restrictAge?: number,
|
2021-09-20 19:05:40 +02:00
|
|
|
): Promise<AcceptManualWithdrawalResult> {
|
|
|
|
return callBackend("acceptManualWithdrawal", {
|
2021-11-15 15:18:58 +01:00
|
|
|
amount,
|
|
|
|
exchangeBaseUrl,
|
2022-06-06 05:09:25 +02:00
|
|
|
restrictAge,
|
2021-09-20 19:05:40 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-13 20:32:06 +02:00
|
|
|
export function setExchangeTosAccepted(
|
|
|
|
exchangeBaseUrl: string,
|
2021-11-15 15:18:58 +01:00
|
|
|
etag: string | undefined,
|
2021-09-13 20:32:06 +02:00
|
|
|
): Promise<void> {
|
|
|
|
return callBackend("setExchangeTosAccepted", {
|
2021-11-15 15:18:58 +01:00
|
|
|
exchangeBaseUrl,
|
|
|
|
etag,
|
|
|
|
} as AcceptExchangeTosRequest);
|
2021-09-13 20:32:06 +02:00
|
|
|
}
|
|
|
|
|
2019-09-05 16:10:53 +02:00
|
|
|
/**
|
|
|
|
* Get diagnostics information
|
|
|
|
*/
|
2020-08-12 09:11:00 +02:00
|
|
|
export function getDiagnostics(): Promise<WalletDiagnostics> {
|
2020-08-21 17:26:25 +02:00
|
|
|
return callBackend("wxGetDiagnostics", {});
|
2019-09-05 16:10:53 +02:00
|
|
|
}
|
2020-05-01 10:46:56 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get diagnostics information
|
|
|
|
*/
|
2022-04-27 19:33:52 +02:00
|
|
|
export function toggleHeaderListener(
|
2020-05-15 09:23:35 +02:00
|
|
|
value: boolean,
|
|
|
|
): Promise<ExtendedPermissionsResponse> {
|
2022-04-27 19:33:52 +02:00
|
|
|
return callBackend("toggleHeaderListener", { value });
|
2020-05-01 10:46:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get diagnostics information
|
|
|
|
*/
|
2022-04-27 19:33:52 +02:00
|
|
|
export function containsHeaderListener(): Promise<ExtendedPermissionsResponse> {
|
|
|
|
return callBackend("containsHeaderListener", {});
|
2020-05-01 10:46:56 +02:00
|
|
|
}
|
2020-05-04 15:22:54 +02:00
|
|
|
|
2020-08-13 20:43:51 +02:00
|
|
|
/**
|
|
|
|
* Get diagnostics information
|
|
|
|
*/
|
|
|
|
export function getWithdrawalDetailsForUri(
|
|
|
|
req: GetWithdrawalDetailsForUriRequest,
|
|
|
|
): Promise<WithdrawUriInfoResponse> {
|
|
|
|
return callBackend("getWithdrawalDetailsForUri", req);
|
|
|
|
}
|
|
|
|
|
2022-10-14 18:40:04 +02:00
|
|
|
export function getWithdrawalDetailsForAmount(
|
|
|
|
req: GetWithdrawalDetailsForAmountRequest,
|
|
|
|
): Promise<ManualWithdrawalDetails> {
|
|
|
|
return callBackend("getWithdrawalDetailsForAmount", req);
|
2021-09-08 20:30:32 +02:00
|
|
|
}
|
2022-10-14 18:40:04 +02:00
|
|
|
|
2021-10-13 19:26:18 +02:00
|
|
|
export function getExchangeTos(
|
|
|
|
exchangeBaseUrl: string,
|
|
|
|
acceptedFormat: string[],
|
|
|
|
): Promise<GetExchangeTosResult> {
|
|
|
|
return callBackend("getExchangeTos", {
|
2021-11-15 15:18:58 +01:00
|
|
|
exchangeBaseUrl,
|
|
|
|
acceptedFormat,
|
2021-10-13 19:26:18 +02:00
|
|
|
});
|
|
|
|
}
|
2021-10-13 11:40:16 +02:00
|
|
|
|
2022-02-22 15:01:47 +01:00
|
|
|
export function dumpCoins(): Promise<CoinDumpJson> {
|
|
|
|
return callBackend("dumpCoins", {});
|
|
|
|
}
|
|
|
|
|
2021-11-29 17:33:01 +01:00
|
|
|
export function getPendingOperations(): Promise<PendingOperationsResponse> {
|
|
|
|
return callBackend("getPendingOperations", {});
|
|
|
|
}
|
|
|
|
|
2021-11-15 15:18:58 +01:00
|
|
|
export function addExchange(req: AddExchangeRequest): Promise<void> {
|
2021-10-13 11:40:16 +02:00
|
|
|
return callBackend("addExchange", req);
|
|
|
|
}
|
|
|
|
|
2022-06-06 05:09:25 +02:00
|
|
|
export function prepareRefund(
|
|
|
|
req: PrepareRefundRequest,
|
|
|
|
): Promise<PrepareRefundResult> {
|
2022-05-03 00:21:34 +02:00
|
|
|
return callBackend("prepareRefund", req);
|
|
|
|
}
|
|
|
|
|
2020-11-18 12:44:06 +01:00
|
|
|
export function prepareTip(req: PrepareTipRequest): Promise<PrepareTipResult> {
|
|
|
|
return callBackend("prepareTip", req);
|
|
|
|
}
|
|
|
|
|
2022-09-16 16:06:55 +02:00
|
|
|
export function acceptTip(req: AcceptTipRequest): Promise<AcceptTipResponse> {
|
2020-11-18 12:44:06 +01:00
|
|
|
return callBackend("acceptTip", req);
|
|
|
|
}
|
|
|
|
|
2021-12-01 18:57:37 +01:00
|
|
|
export function exportDB(): Promise<any> {
|
|
|
|
return callBackend("exportDb", {});
|
|
|
|
}
|
|
|
|
|
2022-01-13 05:33:24 +01:00
|
|
|
export function importDB(dump: any): Promise<void> {
|
2022-03-22 21:16:38 +01:00
|
|
|
return callBackend("importDb", { dump });
|
2022-01-13 05:33:24 +01:00
|
|
|
}
|
|
|
|
|
2022-03-23 21:24:23 +01:00
|
|
|
export function onUpdateNotification(
|
|
|
|
messageTypes: Array<NotificationType>,
|
|
|
|
doCallback: () => void,
|
|
|
|
): () => void {
|
2022-03-25 20:57:27 +01:00
|
|
|
const onNewMessage = (message: MessageFromBackend): void => {
|
2022-03-22 21:16:38 +01:00
|
|
|
const shouldNotify = messageTypes.includes(message.type);
|
2021-11-24 12:57:26 +01:00
|
|
|
if (shouldNotify) {
|
2021-11-19 18:51:27 +01:00
|
|
|
doCallback();
|
|
|
|
}
|
2020-05-04 15:22:54 +02:00
|
|
|
};
|
2022-03-25 20:57:27 +01:00
|
|
|
return platform.listenToWalletBackground(onNewMessage);
|
2020-05-15 09:23:35 +02:00
|
|
|
}
|
2022-08-31 05:20:35 +02:00
|
|
|
|
2022-09-05 21:09:28 +02:00
|
|
|
export function initiatePeerPushPayment(
|
|
|
|
req: InitiatePeerPushPaymentRequest,
|
|
|
|
): Promise<InitiatePeerPushPaymentResponse> {
|
2022-08-31 05:20:35 +02:00
|
|
|
return callBackend("initiatePeerPushPayment", req);
|
|
|
|
}
|
2022-09-05 21:09:28 +02:00
|
|
|
export function checkPeerPushPayment(
|
|
|
|
req: CheckPeerPushPaymentRequest,
|
|
|
|
): Promise<CheckPeerPushPaymentResponse> {
|
2022-08-31 05:20:35 +02:00
|
|
|
return callBackend("checkPeerPushPayment", req);
|
|
|
|
}
|
2022-09-05 21:09:28 +02:00
|
|
|
export function acceptPeerPushPayment(
|
|
|
|
req: AcceptPeerPushPaymentRequest,
|
2022-09-16 16:06:55 +02:00
|
|
|
): Promise<AcceptPeerPushPaymentResponse> {
|
2022-08-31 05:20:35 +02:00
|
|
|
return callBackend("acceptPeerPushPayment", req);
|
|
|
|
}
|
2022-09-05 21:09:28 +02:00
|
|
|
export function initiatePeerPullPayment(
|
|
|
|
req: InitiatePeerPullPaymentRequest,
|
|
|
|
): Promise<InitiatePeerPullPaymentResponse> {
|
2022-08-31 05:20:35 +02:00
|
|
|
return callBackend("initiatePeerPullPayment", req);
|
|
|
|
}
|
2022-09-05 21:09:28 +02:00
|
|
|
export function checkPeerPullPayment(
|
|
|
|
req: CheckPeerPullPaymentRequest,
|
|
|
|
): Promise<CheckPeerPullPaymentResponse> {
|
2022-08-31 05:20:35 +02:00
|
|
|
return callBackend("checkPeerPullPayment", req);
|
|
|
|
}
|
2022-09-05 21:09:28 +02:00
|
|
|
export function acceptPeerPullPayment(
|
|
|
|
req: AcceptPeerPullPaymentRequest,
|
2022-09-16 16:06:55 +02:00
|
|
|
): Promise<AcceptPeerPullPaymentResponse> {
|
2022-08-31 05:20:35 +02:00
|
|
|
return callBackend("acceptPeerPullPayment", req);
|
|
|
|
}
|
2022-09-16 16:06:55 +02:00
|
|
|
|
|
|
|
export function getTransactionById(tid: string): Promise<Transaction> {
|
|
|
|
return callBackend("getTransactionById", {
|
2022-09-16 19:29:35 +02:00
|
|
|
transactionId: tid,
|
|
|
|
});
|
|
|
|
}
|