From 5ff5a686e4f15dea839b18fda9275687557d23a7 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 8 Feb 2021 15:38:34 +0100 Subject: organize imports --- .../taler-wallet-core/src/operations/recoup.ts | 32 ++- .../taler-wallet-core/src/operations/refresh.ts | 63 +++-- .../taler-wallet-core/src/operations/withdraw.ts | 2 +- packages/taler-wallet-core/src/types/talerTypes.ts | 16 -- .../taler-wallet-core/src/types/walletTypes.ts | 73 +++--- packages/taler-wallet-core/src/wallet.ts | 259 ++++++++++----------- 6 files changed, 199 insertions(+), 246 deletions(-) (limited to 'packages') diff --git a/packages/taler-wallet-core/src/operations/recoup.ts b/packages/taler-wallet-core/src/operations/recoup.ts index f6b29536b..a2c7cb6f5 100644 --- a/packages/taler-wallet-core/src/operations/recoup.ts +++ b/packages/taler-wallet-core/src/operations/recoup.ts @@ -24,33 +24,31 @@ /** * Imports. */ -import { InternalWalletState } from "./state"; +import { encodeCrock, getRandomBytes } from "../crypto/talerCrypto"; import { - Stores, - CoinStatus, - CoinSourceType, CoinRecord, - WithdrawCoinSource, + CoinSourceType, + CoinStatus, + RecoupGroupRecord, RefreshCoinSource, ReserveRecordStatus, - RecoupGroupRecord, + Stores, + WithdrawCoinSource, } from "../types/dbTypes"; - -import { codecForRecoupConfirmation } from "../types/talerTypes"; import { NotificationType } from "../types/notifications"; -import { getReserveRequestTimeout, processReserve } from "./reserves"; - -import { Amounts } from "../util/amounts"; -import { createRefreshGroup, processRefreshGroup } from "./refresh"; +import { codecForRecoupConfirmation } from "../types/talerTypes"; import { RefreshReason, TalerErrorDetails } from "../types/walletTypes"; -import { Store, StoreParams, TransactionHandle } from "../util/query"; -import { encodeCrock, getRandomBytes } from "../crypto/talerCrypto"; -import { getTimestampNow } from "../util/time"; -import { guardOperationException } from "./errors"; +import { Amounts } from "../util/amounts"; import { readSuccessResponseJsonOrThrow } from "../util/http"; -import { URL } from "../util/url"; import { Logger } from "../util/logging"; +import { TransactionHandle } from "../util/query"; import { initRetryInfo, updateRetryInfoTimeout } from "../util/retries"; +import { getTimestampNow } from "../util/time"; +import { URL } from "../util/url"; +import { guardOperationException } from "./errors"; +import { createRefreshGroup, processRefreshGroup } from "./refresh"; +import { getReserveRequestTimeout, processReserve } from "./reserves"; +import { InternalWalletState } from "./state"; const logger = new Logger("operations/recoup.ts"); diff --git a/packages/taler-wallet-core/src/operations/refresh.ts b/packages/taler-wallet-core/src/operations/refresh.ts index a6c311f45..621e9a108 100644 --- a/packages/taler-wallet-core/src/operations/refresh.ts +++ b/packages/taler-wallet-core/src/operations/refresh.ts @@ -14,54 +14,51 @@ GNU Taler; see the file COPYING. If not, see */ -import { Amounts, AmountJson } from "../util/amounts"; +import { encodeCrock, getRandomBytes } from "../crypto/talerCrypto"; +import { RefreshNewDenomInfo } from "../types/cryptoTypes"; import { - DenominationRecord, - Stores, - CoinStatus, - RefreshPlanchet, CoinRecord, - RefreshSessionRecord, - RefreshGroupRecord, CoinSourceType, + CoinStatus, + DenominationRecord, + RefreshGroupRecord, + RefreshPlanchet, + Stores, } from "../types/dbTypes"; -import { amountToPretty } from "../util/helpers"; -import { TransactionHandle } from "../util/query"; -import { InternalWalletState, EXCHANGE_COINS_LOCK } from "./state"; -import { Logger } from "../util/logging"; -import { selectWithdrawalDenominations, isWithdrawableDenom } from "./withdraw"; -import { updateExchangeFromUrl } from "./exchanges"; +import { NotificationType } from "../types/notifications"; +import { + codecForExchangeMeltResponse, + codecForExchangeRevealResponse, +} from "../types/talerTypes"; import { - TalerErrorDetails, CoinPublicKey, - RefreshReason, RefreshGroupId, + RefreshReason, + TalerErrorDetails, } from "../types/walletTypes"; -import { guardOperationException } from "./errors"; -import { NotificationType } from "../types/notifications"; -import { getRandomBytes, encodeCrock } from "../crypto/talerCrypto"; +import { AmountJson, Amounts } from "../util/amounts"; +import { amountToPretty } from "../util/helpers"; +import { readSuccessResponseJsonOrThrow } from "../util/http"; +import { checkDbInvariant } from "../util/invariants"; +import { Logger } from "../util/logging"; +import { TransactionHandle } from "../util/query"; +import { initRetryInfo, updateRetryInfoTimeout } from "../util/retries"; import { - getTimestampNow, Duration, - Timestamp, - isTimestampExpired, durationFromSpec, - timestampMin, + durationMul, + getTimestampNow, + isTimestampExpired, + Timestamp, timestampAddDuration, timestampDifference, - durationMax, - durationMul, + timestampMin, } from "../util/time"; -import { readSuccessResponseJsonOrThrow } from "../util/http"; -import { - codecForExchangeMeltResponse, - codecForExchangeRevealResponse, -} from "../types/talerTypes"; import { URL } from "../util/url"; -import { checkDbInvariant } from "../util/invariants"; -import { initRetryInfo, updateRetryInfoTimeout } from "../util/retries"; -import { WALLET_EXCHANGE_PROTOCOL_VERSION } from "./versions"; -import { RefreshNewDenomInfo } from "../types/cryptoTypes"; +import { guardOperationException } from "./errors"; +import { updateExchangeFromUrl } from "./exchanges"; +import { EXCHANGE_COINS_LOCK, InternalWalletState } from "./state"; +import { isWithdrawableDenom, selectWithdrawalDenominations } from "./withdraw"; const logger = new Logger("refresh.ts"); diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts index 936b53954..f8748142f 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.ts @@ -31,11 +31,11 @@ import { ExchangeWithdrawDetails, TalerErrorDetails, ExchangeListItem, + WithdrawUriInfoResponse, } from "../types/walletTypes"; import { codecForWithdrawOperationStatusResponse, codecForWithdrawResponse, - WithdrawUriInfoResponse, WithdrawResponse, codecForTalerConfigResponse, } from "../types/talerTypes"; diff --git a/packages/taler-wallet-core/src/types/talerTypes.ts b/packages/taler-wallet-core/src/types/talerTypes.ts index f3749afe7..fe1370cb7 100644 --- a/packages/taler-wallet-core/src/types/talerTypes.ts +++ b/packages/taler-wallet-core/src/types/talerTypes.ts @@ -47,7 +47,6 @@ import { Duration, codecForDuration, } from "../util/time"; -import { ExchangeListItem, codecForExchangeListItem } from "./walletTypes"; import { codecForAmountString } from "../util/amounts"; /** @@ -983,21 +982,6 @@ export interface MerchantOrderStatusUnpaid { already_paid_order_id?: string; } -export interface WithdrawUriInfoResponse { - amount: AmountString; - defaultExchangeBaseUrl?: string; - possibleExchanges: ExchangeListItem[]; -} - -export const codecForWithdrawUriInfoResponse = (): Codec< - WithdrawUriInfoResponse -> => - buildCodecForObject() - .property("amount", codecForAmountString()) - .property("defaultExchangeBaseUrl", codecOptional(codecForString())) - .property("possibleExchanges", codecForList(codecForExchangeListItem())) - .build("WithdrawUriInfoResponse"); - /** * Response body for the following endpoint: * diff --git a/packages/taler-wallet-core/src/types/walletTypes.ts b/packages/taler-wallet-core/src/types/walletTypes.ts index 022140911..9ecca059b 100644 --- a/packages/taler-wallet-core/src/types/walletTypes.ts +++ b/packages/taler-wallet-core/src/types/walletTypes.ts @@ -225,9 +225,7 @@ export interface ConfirmPayResultPending { export type ConfirmPayResult = ConfirmPayResultDone | ConfirmPayResultPending; -export const codecForConfirmPayResultPending = (): Codec< - ConfirmPayResultPending -> => +export const codecForConfirmPayResultPending = (): Codec => buildCodecForObject() .property("lastError", codecForAny()) .property("type", codecForConstString(ConfirmPayResultType.Pending)) @@ -413,9 +411,7 @@ export enum PreparePayResultType { AlreadyConfirmed = "already-confirmed", } -export const codecForPreparePayResultPaymentPossible = (): Codec< - PreparePayResultPaymentPossible -> => +export const codecForPreparePayResultPaymentPossible = (): Codec => buildCodecForObject() .property("amountEffective", codecForAmountString()) .property("amountRaw", codecForAmountString()) @@ -427,9 +423,7 @@ export const codecForPreparePayResultPaymentPossible = (): Codec< ) .build("PreparePayResultPaymentPossible"); -export const codecForPreparePayResultInsufficientBalance = (): Codec< - PreparePayResultInsufficientBalance -> => +export const codecForPreparePayResultInsufficientBalance = (): Codec => buildCodecForObject() .property("amountRaw", codecForAmountString()) .property("contractTerms", codecForAny()) @@ -440,9 +434,7 @@ export const codecForPreparePayResultInsufficientBalance = (): Codec< ) .build("PreparePayResultInsufficientBalance"); -export const codecForPreparePayResultAlreadyConfirmed = (): Codec< - PreparePayResultAlreadyConfirmed -> => +export const codecForPreparePayResultAlreadyConfirmed = (): Codec => buildCodecForObject() .property( "status", @@ -734,9 +726,7 @@ export interface ForceExchangeUpdateRequest { exchangeBaseUrl: string; } -export const codecForForceExchangeUpdateRequest = (): Codec< - AddExchangeRequest -> => +export const codecForForceExchangeUpdateRequest = (): Codec => buildCodecForObject() .property("exchangeBaseUrl", codecForString()) .build("AddExchangeRequest"); @@ -755,9 +745,7 @@ export interface AcceptManualWithdrawalRequest { amount: string; } -export const codecForAcceptManualWithdrawalRequet = (): Codec< - AcceptManualWithdrawalRequest -> => +export const codecForAcceptManualWithdrawalRequet = (): Codec => buildCodecForObject() .property("exchangeBaseUrl", codecForString()) .property("amount", codecForString()) @@ -773,17 +761,13 @@ export interface AcceptBankIntegratedWithdrawalRequest { exchangeBaseUrl: string; } -export const codecForAcceptBankIntegratedWithdrawalRequest = (): Codec< - AcceptBankIntegratedWithdrawalRequest -> => +export const codecForAcceptBankIntegratedWithdrawalRequest = (): Codec => buildCodecForObject() .property("exchangeBaseUrl", codecForString()) .property("talerWithdrawUri", codecForString()) .build("AcceptBankIntegratedWithdrawalRequest"); -export const codecForGetWithdrawalDetailsForAmountRequest = (): Codec< - GetWithdrawalDetailsForAmountRequest -> => +export const codecForGetWithdrawalDetailsForAmountRequest = (): Codec => buildCodecForObject() .property("exchangeBaseUrl", codecForString()) .property("amount", codecForString()) @@ -794,9 +778,7 @@ export interface AcceptExchangeTosRequest { etag: string; } -export const codecForAcceptExchangeTosRequest = (): Codec< - AcceptExchangeTosRequest -> => +export const codecForAcceptExchangeTosRequest = (): Codec => buildCodecForObject() .property("exchangeBaseUrl", codecForString()) .property("etag", codecForString()) @@ -815,9 +797,7 @@ export interface GetWithdrawalDetailsForUriRequest { talerWithdrawUri: string; } -export const codecForGetWithdrawalDetailsForUri = (): Codec< - GetWithdrawalDetailsForUriRequest -> => +export const codecForGetWithdrawalDetailsForUri = (): Codec => buildCodecForObject() .property("talerWithdrawUri", codecForString()) .build("GetWithdrawalDetailsForUriRequest"); @@ -920,9 +900,7 @@ export interface RecoveryLoadRequest { strategy?: RecoveryMergeStrategy; } -export const codecForWithdrawTestBalance = (): Codec< - WithdrawTestBalanceRequest -> => +export const codecForWithdrawTestBalance = (): Codec => buildCodecForObject() .property("amount", codecForString()) .property("bankBaseUrl", codecForString()) @@ -961,9 +939,7 @@ export interface SetCoinSuspendedRequest { suspended: boolean; } -export const codecForSetCoinSuspendedRequest = (): Codec< - SetCoinSuspendedRequest -> => +export const codecForSetCoinSuspendedRequest = (): Codec => buildCodecForObject() .property("coinPub", codecForString()) .property("suspended", codecForBoolean()) @@ -1000,9 +976,7 @@ export interface AbortPayWithRefundRequest { proposalId: string; } -export const codecForAbortPayWithRefundRequest = (): Codec< - AbortPayWithRefundRequest -> => +export const codecForAbortPayWithRefundRequest = (): Codec => buildCodecForObject() .property("proposalId", codecForString()) .build("AbortPayWithRefundRequest"); @@ -1012,9 +986,7 @@ export interface CreateDepositGroupRequest { amount: string; } -export const codecForCreateDepositGroupRequest = (): Codec< - CreateDepositGroupRequest -> => +export const codecForCreateDepositGroupRequest = (): Codec => buildCodecForObject() .property("amount", codecForAmountString()) .property("depositPaytoUri", codecForString()) @@ -1035,9 +1007,20 @@ export interface TrackDepositGroupResponse { }[]; } -export const codecForTrackDepositGroupRequest = (): Codec< - TrackDepositGroupRequest -> => +export const codecForTrackDepositGroupRequest = (): Codec => buildCodecForObject() .property("depositGroupId", codecForAmountString()) .build("TrackDepositGroupRequest"); + +export interface WithdrawUriInfoResponse { + amount: AmountString; + defaultExchangeBaseUrl?: string; + possibleExchanges: ExchangeListItem[]; +} + +export const codecForWithdrawUriInfoResponse = (): Codec => + buildCodecForObject() + .property("amount", codecForAmountString()) + .property("defaultExchangeBaseUrl", codecOptional(codecForString())) + .property("possibleExchanges", codecForList(codecForExchangeListItem())) + .build("WithdrawUriInfoResponse"); diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 51987c349..5aa951d5f 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -22,169 +22,160 @@ /** * Imports. */ +import { TalerErrorCode } from "."; import { CryptoWorkerFactory } from "./crypto/workers/cryptoApi"; -import { HttpRequestLibrary } from "./util/http"; -import { Database, Store } from "./util/query"; - -import { Amounts, AmountJson } from "./util/amounts"; - import { - getExchangeWithdrawalInfo, - getWithdrawalDetailsForUri, -} from "./operations/withdraw"; - + addBackupProvider, + AddBackupProviderRequest, + BackupInfo, + BackupRecovery, + codecForAddBackupProviderRequest, + exportBackup, + exportBackupEncrypted, + getBackupInfo, + getBackupRecovery, + importBackupEncrypted, + importBackupPlain, + loadBackupRecovery, + runBackupCycle, +} from "./operations/backup"; +import { getBalances } from "./operations/balance"; +import { + createDepositGroup, + processDepositGroup, + trackDepositGroup, +} from "./operations/deposits"; +import { + makeErrorDetails, + OperationFailedAndReportedError, + OperationFailedError, +} from "./operations/errors"; +import { + acceptExchangeTermsOfService, + getExchangePaytoUri, + getExchangeTrust, + updateExchangeFromUrl, +} from "./operations/exchanges"; import { - preparePayForUri, - refuseProposal, confirmPay, + preparePayForUri, processDownloadProposal, processPurchasePay, + refuseProposal, } from "./operations/pay"; - +import { getPendingOperations } from "./operations/pending"; +import { processRecoupGroup } from "./operations/recoup"; +import { + autoRefresh, + createRefreshGroup, + processRefreshGroup, +} from "./operations/refresh"; +import { + abortFailedPayWithRefund, + applyRefund, + processPurchaseQueryRefund, +} from "./operations/refund"; +import { + createReserve, + createTalerWithdrawReserve, + forceQueryReserve, + getFundingPaytoUris, + processReserve, +} from "./operations/reserves"; +import { InternalWalletState } from "./operations/state"; +import { + runIntegrationTest, + testPay, + withdrawTestBalance, +} from "./operations/testing"; +import { acceptTip, prepareTip, processTip } from "./operations/tip"; +import { getTransactions } from "./operations/transactions"; +import { + getExchangeWithdrawalInfo, + getWithdrawalDetailsForUri, + processWithdrawGroup, +} from "./operations/withdraw"; import { CoinRecord, + CoinSourceType, CurrencyRecord, DenominationRecord, ExchangeRecord, PurchaseRecord, + RefundState, ReserveRecord, - Stores, ReserveRecordStatus, - CoinSourceType, - RefundState, - MetaStores, - DepositGroupRecord, + Stores, } from "./types/dbTypes"; -import { CoinDumpJson, WithdrawUriInfoResponse } from "./types/talerTypes"; +import { NotificationType, WalletNotification } from "./types/notifications"; +import { + PendingOperationInfo, + PendingOperationsResponse, + PendingOperationType, +} from "./types/pendingTypes"; +import { CoinDumpJson } from "./types/talerTypes"; +import { + codecForTransactionsRequest, + TransactionsRequest, + TransactionsResponse, +} from "./types/transactionsTypes"; import { - BenchmarkResult, - ConfirmPayResult, - ReturnCoinsRequest, - SenderWireInfos, - PreparePayResult, - AcceptWithdrawalResponse, - PurchaseDetails, - RefreshReason, - ExchangeListItem, - ExchangesListRespose, - ManualWithdrawalDetails, - GetExchangeTosResult, AcceptManualWithdrawalResult, + AcceptWithdrawalResponse, + ApplyRefundResponse, BalancesResponse, - TestPayArgs, - IntegrationTestArgs, - codecForAddExchangeRequest, - codecForGetWithdrawalDetailsForUri, - codecForAcceptManualWithdrawalRequet, - codecForGetWithdrawalDetailsForAmountRequest, + BenchmarkResult, + codecForAbortPayWithRefundRequest, + codecForAcceptBankIntegratedWithdrawalRequest, codecForAcceptExchangeTosRequest, + codecForAcceptManualWithdrawalRequet, + codecForAcceptTipRequest, + codecForAddExchangeRequest, codecForApplyRefundRequest, - codecForAcceptBankIntegratedWithdrawalRequest, - codecForGetExchangeTosRequest, codecForConfirmPayRequest, - CoreApiResponse, - codecForPreparePayRequest, - codecForIntegrationTestArgs, - WithdrawTestBalanceRequest, - codecForWithdrawTestBalance, - codecForTestPayArgs, - codecForSetCoinSuspendedRequest, + codecForCreateDepositGroupRequest, codecForForceExchangeUpdateRequest, codecForForceRefreshRequest, - PrepareTipResult, + codecForGetExchangeTosRequest, + codecForGetWithdrawalDetailsForAmountRequest, + codecForGetWithdrawalDetailsForUri, + codecForIntegrationTestArgs, + codecForPreparePayRequest, codecForPrepareTipRequest, - codecForAcceptTipRequest, - codecForAbortPayWithRefundRequest, - ApplyRefundResponse, - RecoveryLoadRequest, - codecForCreateDepositGroupRequest, + codecForSetCoinSuspendedRequest, + codecForTestPayArgs, + codecForTrackDepositGroupRequest, + codecForWithdrawTestBalance, + ConfirmPayResult, + CoreApiResponse, CreateDepositGroupRequest, CreateDepositGroupResponse, - codecForTrackDepositGroupRequest, + ExchangeListItem, + ExchangesListRespose, + GetExchangeTosResult, + IntegrationTestArgs, + ManualWithdrawalDetails, + PreparePayResult, + PrepareTipResult, + PurchaseDetails, + RecoveryLoadRequest, + RefreshReason, + ReturnCoinsRequest, + TestPayArgs, TrackDepositGroupRequest, TrackDepositGroupResponse, + WithdrawTestBalanceRequest, + WithdrawUriInfoResponse, } from "./types/walletTypes"; -import { Logger } from "./util/logging"; - +import { AmountJson, Amounts } from "./util/amounts"; import { assertUnreachable } from "./util/assertUnreachable"; - -import { - updateExchangeFromUrl, - getExchangeTrust, - getExchangePaytoUri, - acceptExchangeTermsOfService, -} from "./operations/exchanges"; -import { - processReserve, - createTalerWithdrawReserve, - forceQueryReserve, - getFundingPaytoUris, -} from "./operations/reserves"; - -import { InternalWalletState } from "./operations/state"; -import { createReserve } from "./operations/reserves"; -import { - processRefreshGroup, - createRefreshGroup, - autoRefresh, -} from "./operations/refresh"; -import { processWithdrawGroup } from "./operations/withdraw"; -import { getPendingOperations } from "./operations/pending"; -import { getBalances } from "./operations/balance"; -import { acceptTip, prepareTip, processTip } from "./operations/tip"; -import { TimerGroup } from "./util/timer"; -import { AsyncCondition } from "./util/promiseUtils"; import { AsyncOpMemoSingle } from "./util/asyncMemo"; -import { - PendingOperationInfo, - PendingOperationsResponse, - PendingOperationType, -} from "./types/pendingTypes"; -import { WalletNotification, NotificationType } from "./types/notifications"; -import { - processPurchaseQueryRefund, - applyRefund, - abortFailedPayWithRefund, -} from "./operations/refund"; -import { durationMin, Duration } from "./util/time"; -import { processRecoupGroup } from "./operations/recoup"; -import { - OperationFailedAndReportedError, - OperationFailedError, - makeErrorDetails, -} from "./operations/errors"; -import { - TransactionsRequest, - TransactionsResponse, - codecForTransactionsRequest, -} from "./types/transactionsTypes"; -import { getTransactions } from "./operations/transactions"; -import { - withdrawTestBalance, - runIntegrationTest, - testPay, -} from "./operations/testing"; -import { TalerErrorCode } from "."; -import { - addBackupProvider, - codecForAddBackupProviderRequest, - runBackupCycle, - exportBackup, - importBackupPlain, - exportBackupEncrypted, - importBackupEncrypted, - BackupRecovery, - getBackupRecovery, - AddBackupProviderRequest, - getBackupInfo, - BackupInfo, - loadBackupRecovery, -} from "./operations/backup"; -import { - createDepositGroup, - processDepositGroup, - trackDepositGroup, -} from "./operations/deposits"; +import { HttpRequestLibrary } from "./util/http"; +import { Logger } from "./util/logging"; +import { AsyncCondition } from "./util/promiseUtils"; +import { Database } from "./util/query"; +import { Duration, durationMin } from "./util/time"; +import { TimerGroup } from "./util/timer"; const builtinCurrencies: CurrencyRecord[] = [ { @@ -651,9 +642,9 @@ export class Wallet { return await this.db.get(Stores.exchanges, exchangeBaseUrl); } - async getPendingOperations({ onlyDue = false } = {}): Promise< - PendingOperationsResponse - > { + async getPendingOperations({ + onlyDue = false, + } = {}): Promise { return this.ws.memoGetPending.memo(() => getPendingOperations(this.ws, { onlyDue }), ); -- cgit v1.2.3