diff --git a/src/core/currency/wallet/currency-wallet-api.ts b/src/core/currency/wallet/currency-wallet-api.ts index 9fe764e8c..a9caf8651 100644 --- a/src/core/currency/wallet/currency-wallet-api.ts +++ b/src/core/currency/wallet/currency-wallet-api.ts @@ -31,6 +31,7 @@ import { EdgeStakingStatus, EdgeStreamTransactionOptions, EdgeTransaction, + EdgeTxFiat, EdgeWalletInfo } from '../../../types/types' import { mergeDeeply } from '../../../util/util' @@ -40,6 +41,7 @@ import { makeStorageWalletApi } from '../../storage/storage-api' import { getCurrencyMultiplier } from '../currency-selectors' import { makeCurrencyWalletCallbacks } from './currency-wallet-callbacks' import { + asEdgeTxFiat, asEdgeTxSwap, packMetadata, TransactionFile, @@ -468,6 +470,7 @@ export function makeCurrencyWalletApi( memos, skipChecks, spendTargets = [], + fiatData, swapData } = spendInfo @@ -536,6 +539,7 @@ export function makeCurrencyWalletApi( tx.spendTargets = savedTargets if (metadata != null) tx.metadata = metadata if (swapData != null) tx.swapData = asEdgeTxSwap(swapData) + if (fiatData != null) tx.fiatData = asEdgeTxFiat(fiatData) if (input.props.state.login.deviceDescription != null) tx.deviceDescription = input.props.state.login.deviceDescription @@ -549,14 +553,16 @@ export function makeCurrencyWalletApi( async saveTxMetadata( txid: string, currencyCode: string, - metadata: EdgeMetadata + metadata?: EdgeMetadata, + fiatData?: EdgeTxFiat ): Promise { await setCurrencyWalletTxMetadata( input, txid, currencyCode, - packMetadata(metadata, input.props.walletState.fiat), - fakeCallbacks + fakeCallbacks, + packMetadata(metadata ?? {}, input.props.walletState.fiat), + fiatData ) }, async signMessage( @@ -665,7 +671,7 @@ export function combineTxWithFile( if (file != null) { if (file.creationDate < out.date) out.date = file.creationDate - const merged = mergeDeeply( + const merged: TransactionFile['currencies']['currencyCode'] = mergeDeeply( file.currencies[walletCurrency], file.currencies[currencyCode] ) @@ -676,6 +682,10 @@ export function combineTxWithFile( } } + if (merged.fiatData != null) { + out.fiatData = merged.fiatData + } + if (file.feeRateRequested != null) { if (typeof file.feeRateRequested === 'string') { out.networkFeeOption = file.feeRateRequested diff --git a/src/core/currency/wallet/currency-wallet-cleaners.ts b/src/core/currency/wallet/currency-wallet-cleaners.ts index b7fb21670..81e4140cd 100644 --- a/src/core/currency/wallet/currency-wallet-cleaners.ts +++ b/src/core/currency/wallet/currency-wallet-cleaners.ts @@ -2,6 +2,7 @@ import { asArray, asBoolean, asEither, + asMaybe, asNull, asNumber, asObject, @@ -11,7 +12,12 @@ import { Cleaner } from 'cleaners' -import { EdgeMetadata, EdgeTxSwap, JsonObject } from '../../../types/types' +import { + EdgeMetadata, + EdgeTxFiat, + EdgeTxSwap, + JsonObject +} from '../../../types/types' import { asJsonObject } from '../../../util/file-helpers' /** @@ -35,6 +41,7 @@ export interface TransactionFile { creationDate: number currencies: { [currencyCode: string]: { + fiatData?: EdgeTxFiat metadata: DiskMetadata nativeAmount?: string providerFeeSent?: string @@ -153,6 +160,26 @@ const asFeeRate: Cleaner<'high' | 'standard' | 'low'> = asValue( 'low' ) +export const asEdgeTxFiat = asObject({ + orderId: asString, + orderUri: asOptional(asString), + isEstimate: asBoolean, + + fiatPlugin: asObject({ + providerId: asString, + providerDisplayName: asString, + supportEmail: asOptional(asString) + }), + txType: asValue('buy', 'sell', 'sellNetworkFee'), + payinAddress: asMaybe(asString), + payoutAddress: asMaybe(asString), + fiatCurrencyCode: asString, + cryptoPluginId: asString, + cryptoTokenId: asMaybe(asString), + cryptoNativeAmount: asString, + walletId: asString +}) + export const asEdgeTxSwap = asObject({ orderId: asOptional(asString), orderUri: asOptional(asString), @@ -207,6 +234,7 @@ export const asTransactionFile = asObject({ creationDate: asNumber, currencies: asObject( asObject({ + fiatData: asOptional(asEdgeTxFiat), metadata: asDiskMetadata, nativeAmount: asOptional(asString), providerFeeSent: asOptional(asString) diff --git a/src/core/currency/wallet/currency-wallet-export.ts b/src/core/currency/wallet/currency-wallet-export.ts index 4aba1b7c6..dc6b67441 100644 --- a/src/core/currency/wallet/currency-wallet-export.ts +++ b/src/core/currency/wallet/currency-wallet-export.ts @@ -73,6 +73,15 @@ export function searchStringFilter( if (checkNullTypeAndIndex(displayName) || checkNullTypeAndIndex(pluginId)) return true } + if (tx.fiatData != null) { + const { providerId = '', providerDisplayName = '' } = tx.fiatData.fiatPlugin + if ( + checkNullTypeAndIndex(providerId) || + checkNullTypeAndIndex(providerDisplayName) + ) + return true + } + if (tx.spendTargets != null) { for (const target of tx.spendTargets) { const { publicAddress = '', memo = '' } = target diff --git a/src/core/currency/wallet/currency-wallet-files.ts b/src/core/currency/wallet/currency-wallet-files.ts index edb72490d..76fc39fca 100644 --- a/src/core/currency/wallet/currency-wallet-files.ts +++ b/src/core/currency/wallet/currency-wallet-files.ts @@ -3,7 +3,8 @@ import { Disklet, justFiles, navigateDisklet } from 'disklet' import { EdgeCurrencyEngineCallbacks, - EdgeTransaction + EdgeTransaction, + EdgeTxFiat } from '../../../types/types' import { makeJsonFile } from '../../../util/file-helpers' import { mergeDeeply } from '../../../util/util' @@ -384,8 +385,9 @@ export async function setCurrencyWalletTxMetadata( input: CurrencyWalletInput, txid: string, currencyCode: string, + fakeCallbacks: EdgeCurrencyEngineCallbacks, metadata: DiskMetadata, - fakeCallbacks: EdgeCurrencyEngineCallbacks + fiatData?: EdgeTxFiat ): Promise { const { dispatch, state, walletId } = input.props const disklet = getStorageWalletDisklet(state, walletId) @@ -427,7 +429,7 @@ export async function setCurrencyWalletTxMetadata( currencies: {} } newFile.currencies[currencyCode] = { - metadata + metadata: { ...metadata, ...fiatData } } const json = mergeDeeply(oldFile, newFile) @@ -450,7 +452,7 @@ export async function setupNewTxMetadata( ): Promise { const { dispatch, walletState, state, walletId } = input.props const { fiat = 'iso:USD' } = walletState - const { currencyCode, spendTargets, swapData, txid } = tx + const { currencyCode, fiatData, spendTargets, swapData, txid } = tx const disklet = getStorageWalletDisklet(state, walletId) const creationDate = Date.now() / 1000 @@ -472,7 +474,7 @@ export async function setupNewTxMetadata( currencies: {}, swap: swapData } - json.currencies[currencyCode] = { metadata, nativeAmount } + json.currencies[currencyCode] = { metadata, nativeAmount, fiatData } // Set up the fee metadata: if (tx.networkFeeOption != null) { diff --git a/src/core/currency/wallet/currency-wallet-reducer.ts b/src/core/currency/wallet/currency-wallet-reducer.ts index 7e5ec2853..0ff758467 100644 --- a/src/core/currency/wallet/currency-wallet-reducer.ts +++ b/src/core/currency/wallet/currency-wallet-reducer.ts @@ -8,6 +8,8 @@ import { EdgeStakingStatus, EdgeTransaction, EdgeTxAction, + EdgeTxFiat, + EdgeTxSwap, EdgeWalletInfo, EdgeWalletInfoFull, JsonObject @@ -52,6 +54,8 @@ export interface MergedTransaction { ourReceiveAddresses: string[] signedTx: string txid: string + swapData?: EdgeTxSwap + fiatData?: EdgeTxFiat nativeAmount: { [currencyCode: string]: string } networkFee: { [currencyCode: string]: string } @@ -424,7 +428,7 @@ export function mergeTx( memos } = tx - const out = { + const out: MergedTransaction = { action, blockHeight: tx.blockHeight, confirmations: tx.confirmations ?? 'unconfirmed', @@ -449,5 +453,13 @@ export function mergeTx( out.networkFee[defaultCurrency] = String(tx.parentNetworkFee) } + if (tx.fiatData != null) { + out.fiatData = tx.fiatData + } + + if (tx.swapData != null) { + out.swapData = tx.swapData + } + return out } diff --git a/src/types/types.ts b/src/types/types.ts index a3cf301b5..5c44941eb 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -468,6 +468,27 @@ export interface EdgeTxSwap { refundAddress?: string } +export interface EdgeTxFiat { + orderId: string + orderUri?: string + isEstimate: boolean + + fiatPlugin: { + providerId: string + providerDisplayName: string + supportEmail?: string + } + + txType: 'buy' | 'sell' | 'sellNetworkFee' + payinAddress?: string + payoutAddress?: string + fiatCurrencyCode: string + cryptoPluginId: string + cryptoTokenId?: string + cryptoNativeAmount: string + walletId: string +} + export type EdgeConfirmationState = // More than `EdgeCurrencyInfo.requiredConfirmations`: | 'confirmed' @@ -520,6 +541,7 @@ export interface EdgeTransaction { readonly uniqueIdentifier: string | undefined }> swapData?: EdgeTxSwap + fiatData?: EdgeTxFiat txSecret?: string // Monero decryption key /** @@ -574,6 +596,7 @@ export interface EdgeSpendInfo { // Core: metadata?: EdgeMetadata swapData?: EdgeTxSwap + fiatData?: EdgeTxFiat otherParams?: JsonObject /** @deprecated Use tokenId instead */ @@ -1103,7 +1126,8 @@ export interface EdgeCurrencyWallet { readonly saveTxMetadata: ( txid: string, currencyCode: string, - metadata: EdgeMetadata + metadata?: EdgeMetadata, + fiatData?: EdgeTxFiat ) => Promise readonly signTx: (tx: EdgeTransaction) => Promise readonly sweepPrivateKeys: (