Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paul/fiat data #573

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/core/currency/wallet/currency-wallet-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
EdgeStakingStatus,
EdgeStreamTransactionOptions,
EdgeTransaction,
EdgeTxFiat,
EdgeWalletInfo
} from '../../../types/types'
import { mergeDeeply } from '../../../util/util'
Expand All @@ -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,
Expand Down Expand Up @@ -468,6 +470,7 @@ export function makeCurrencyWalletApi(
memos,
skipChecks,
spendTargets = [],
fiatData,
swapData
} = spendInfo

Expand Down Expand Up @@ -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

Expand All @@ -549,14 +553,16 @@ export function makeCurrencyWalletApi(
async saveTxMetadata(
txid: string,
currencyCode: string,
metadata: EdgeMetadata
metadata?: EdgeMetadata,
fiatData?: EdgeTxFiat
): Promise<void> {
await setCurrencyWalletTxMetadata(
input,
txid,
currencyCode,
packMetadata(metadata, input.props.walletState.fiat),
fakeCallbacks
fakeCallbacks,
packMetadata(metadata ?? {}, input.props.walletState.fiat),
fiatData
)
},
async signMessage(
Expand Down Expand Up @@ -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]
)
Expand All @@ -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
Expand Down
30 changes: 29 additions & 1 deletion src/core/currency/wallet/currency-wallet-cleaners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
asArray,
asBoolean,
asEither,
asMaybe,
asNull,
asNumber,
asObject,
Expand All @@ -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'

/**
Expand All @@ -35,6 +41,7 @@ export interface TransactionFile {
creationDate: number
currencies: {
[currencyCode: string]: {
fiatData?: EdgeTxFiat
metadata: DiskMetadata
nativeAmount?: string
providerFeeSent?: string
Expand Down Expand Up @@ -153,6 +160,26 @@ const asFeeRate: Cleaner<'high' | 'standard' | 'low'> = asValue(
'low'
)

export const asEdgeTxFiat = asObject<EdgeTxFiat>({
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<EdgeTxSwap>({
orderId: asOptional(asString),
orderUri: asOptional(asString),
Expand Down Expand Up @@ -207,6 +234,7 @@ export const asTransactionFile = asObject<TransactionFile>({
creationDate: asNumber,
currencies: asObject(
asObject({
fiatData: asOptional(asEdgeTxFiat),
metadata: asDiskMetadata,
nativeAmount: asOptional(asString),
providerFeeSent: asOptional(asString)
Expand Down
9 changes: 9 additions & 0 deletions src/core/currency/wallet/currency-wallet-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions src/core/currency/wallet/currency-wallet-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -384,8 +385,9 @@ export async function setCurrencyWalletTxMetadata(
input: CurrencyWalletInput,
txid: string,
currencyCode: string,
fakeCallbacks: EdgeCurrencyEngineCallbacks,
metadata: DiskMetadata,
fakeCallbacks: EdgeCurrencyEngineCallbacks
fiatData?: EdgeTxFiat
): Promise<void> {
const { dispatch, state, walletId } = input.props
const disklet = getStorageWalletDisklet(state, walletId)
Expand Down Expand Up @@ -427,7 +429,7 @@ export async function setCurrencyWalletTxMetadata(
currencies: {}
}
newFile.currencies[currencyCode] = {
metadata
metadata: { ...metadata, ...fiatData }
}
const json = mergeDeeply(oldFile, newFile)

Expand All @@ -450,7 +452,7 @@ export async function setupNewTxMetadata(
): Promise<void> {
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
Expand All @@ -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) {
Expand Down
14 changes: 13 additions & 1 deletion src/core/currency/wallet/currency-wallet-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
EdgeStakingStatus,
EdgeTransaction,
EdgeTxAction,
EdgeTxFiat,
EdgeTxSwap,
EdgeWalletInfo,
EdgeWalletInfoFull,
JsonObject
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -424,7 +428,7 @@ export function mergeTx(
memos
} = tx

const out = {
const out: MergedTransaction = {
action,
blockHeight: tx.blockHeight,
confirmations: tx.confirmations ?? 'unconfirmed',
Expand All @@ -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
}
26 changes: 25 additions & 1 deletion src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -520,6 +541,7 @@ export interface EdgeTransaction {
readonly uniqueIdentifier: string | undefined
}>
swapData?: EdgeTxSwap
fiatData?: EdgeTxFiat
txSecret?: string // Monero decryption key

/**
Expand Down Expand Up @@ -574,6 +596,7 @@ export interface EdgeSpendInfo {
// Core:
metadata?: EdgeMetadata
swapData?: EdgeTxSwap
fiatData?: EdgeTxFiat
otherParams?: JsonObject

/** @deprecated Use tokenId instead */
Expand Down Expand Up @@ -1103,7 +1126,8 @@ export interface EdgeCurrencyWallet {
readonly saveTxMetadata: (
txid: string,
currencyCode: string,
metadata: EdgeMetadata
metadata?: EdgeMetadata,
fiatData?: EdgeTxFiat
) => Promise<void>
readonly signTx: (tx: EdgeTransaction) => Promise<EdgeTransaction>
readonly sweepPrivateKeys: (
Expand Down