Skip to content

Commit

Permalink
Merge pull request #4691 from EdgeApp/paul/fixTagging
Browse files Browse the repository at this point in the history
Paul/fix tagging
  • Loading branch information
paullinator authored Jan 10, 2024
2 parents 48e757e + e8ead3d commit 4439318
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 31 deletions.
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ PODS:
- disklet (0.5.2):
- React
- DoubleConversion (1.1.6)
- edge-core-js (2.0.0):
- edge-core-js (2.0.1):
- React-Core
- edge-currency-accountbased (3.0.0):
- React-Core
Expand Down Expand Up @@ -1266,7 +1266,7 @@ SPEC CHECKSUMS:
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
disklet: e7ed3e673ccad9d175a1675f9f3589ffbf69a5fd
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
edge-core-js: 9c9b75bf90e628968a9ae34cf8ee93a066b6be51
edge-core-js: 1c873ea7016c3b0a4c1b2dcb6b3f80c385191ef9
edge-currency-accountbased: 1111b3eef85a4986135d6f03e522eb740ed713d4
edge-exchange-plugins: a7340c395f9b99f762858ff568e7889269f5b8da
edge-login-ui-rn: 57eda824fa72e5e2cf9771065819555d5d9f97ea
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
"deepmerge": "^4.3.1",
"detect-bundler": "^1.1.0",
"disklet": "^0.5.2",
"edge-core-js": "^2.0.0",
"edge-core-js": "^2.0.1",
"edge-currency-accountbased": "^3.0.0",
"edge-currency-monero": "^1.1.1",
"edge-currency-plugins": "^2.5.1",
Expand Down
55 changes: 55 additions & 0 deletions src/actions/CategoriesActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { EdgeAccount, EdgeAssetAmount, EdgeCurrencyWallet, EdgeMetadata, EdgeTra
import { sprintf } from 'sprintf-js'

import { showError } from '../components/services/AirshipInstance'
import { EDGE_CONTENT_SERVER_URI } from '../constants/CdnConstants'
import { TX_ACTION_LABEL_MAP } from '../constants/txActionConstants'
import { lstrings } from '../locales/strings'
import { ThunkAction } from '../types/reduxTypes'
Expand Down Expand Up @@ -268,6 +269,7 @@ export const defaultCategories = [

export interface ActionDisplayInfo {
direction: 'send' | 'receive'
iconPluginId?: string
userData: EdgeMetadata
savedData: EdgeMetadata
mergedData: EdgeMetadata
Expand All @@ -290,6 +292,7 @@ export const getTxActionDisplayInfo = (tx: EdgeTransaction, account: EdgeAccount
let edgeCategory: EdgeCategory
let direction: 'send' | 'receive'
let notes: string | undefined
let iconPluginId: string | undefined

// Default text for send or receive
if (isSentTransaction) {
Expand Down Expand Up @@ -321,7 +324,26 @@ export const getTxActionDisplayInfo = (tx: EdgeTransaction, account: EdgeAccount

switch (actionType) {
case 'swap': {
iconPluginId = action.swapInfo.pluginId
switch (assetActionType) {
case 'transfer': {
const txSrc = action.payoutWalletId !== wallet.id
const toFromStr = txSrc ? lstrings.transaction_details_swap_to_subcat_1s : lstrings.transaction_details_swap_from_subcat_1s
const walletName = account.currencyWallets[action.payoutWalletId]?.name ?? currencyName
edgeCategory = {
category: 'transfer',
subcategory: sprintf(toFromStr, walletName)
}
break
}
case 'transferNetworkFee':
case 'swapNetworkFee': {
edgeCategory = {
category: 'expense',
subcategory: lstrings.wc_smartcontract_network_fee
}
break
}
case 'swap':
case 'swapOrderFill': {
// Determine if the swap destination was to a different asset or if the
Expand Down Expand Up @@ -360,6 +382,7 @@ export const getTxActionDisplayInfo = (tx: EdgeTransaction, account: EdgeAccount
break
}
case 'stake': {
iconPluginId = action.pluginId
switch (assetActionType) {
case 'stake': {
let subcategory
Expand Down Expand Up @@ -387,6 +410,7 @@ export const getTxActionDisplayInfo = (tx: EdgeTransaction, account: EdgeAccount
direction = 'send'
break
}
case 'claim':
case 'unstake': {
let subcategory
if (action.stakeAssets.length === 1) subcategory = sprintf(lstrings.transaction_details_unstake_subcat_1s, ...getCurrencyCodes(action.stakeAssets))
Expand All @@ -400,6 +424,7 @@ export const getTxActionDisplayInfo = (tx: EdgeTransaction, account: EdgeAccount
direction = 'receive'
break
}
case 'claimOrder':
case 'unstakeOrder': {
if (action.stakeAssets.length === 1) notes = sprintf(lstrings.transaction_details_unstake_order_notes_1s, ...getCurrencyCodes(action.stakeAssets))
else if (action.stakeAssets.length === 2)
Expand All @@ -413,12 +438,22 @@ export const getTxActionDisplayInfo = (tx: EdgeTransaction, account: EdgeAccount
direction = 'send'
break
}
case 'unstakeNetworkFee':
case 'stakeNetworkFee': {
edgeCategory = {
category: 'expense',
subcategory: lstrings.wc_smartcontract_network_fee
}
break
}

default:
console.error(`Unsupported EdgeTxAction assetAction:assetActionType: '${assetAction}:${assetActionType}'`)
}
break
}
case 'fiat': {
iconPluginId = action.fiatPlugin.providerId
switch (assetActionType) {
case 'buy': {
payeeText = sprintf(payeeText, currencyName)
Expand Down Expand Up @@ -464,8 +499,28 @@ export const getTxActionDisplayInfo = (tx: EdgeTransaction, account: EdgeAccount

return {
direction,
iconPluginId,
savedData,
userData: metadata ?? {},
mergedData
}
}

export const pluginIdIcons: Record<string, string> = {
bitrefill: EDGE_CONTENT_SERVER_URI + '/bitrefill.png',
bitsofgold: EDGE_CONTENT_SERVER_URI + '/bits-of-gold-logo.png',
changenow: EDGE_CONTENT_SERVER_URI + '/changenow.png',
changehero: EDGE_CONTENT_SERVER_URI + '/changehero.png',
exolix: EDGE_CONTENT_SERVER_URI + '/exolix-logo.png',
godex: EDGE_CONTENT_SERVER_URI + '/godex.png',
letsexchange: EDGE_CONTENT_SERVER_URI + '/letsexchange-logo.png',
lifi: EDGE_CONTENT_SERVER_URI + '/lifi.png',
sideshift: EDGE_CONTENT_SERVER_URI + '/sideshift-logo.png',
simplex: EDGE_CONTENT_SERVER_URI + '/simplex.png',
swapuz: EDGE_CONTENT_SERVER_URI + '/swapuz.png',
thorchain: EDGE_CONTENT_SERVER_URI + '/thorchain.png',
thorchainda: EDGE_CONTENT_SERVER_URI + '/thorchain.png',
tronResources: EDGE_CONTENT_SERVER_URI + '/TRON/TRON.png',
velodrome: EDGE_CONTENT_SERVER_URI + '/velodrome.png',
xrpdex: EDGE_CONTENT_SERVER_URI + '/xrpdex.png'
}
6 changes: 3 additions & 3 deletions src/components/scenes/TransactionDetailsScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import FastImage from 'react-native-fast-image'
import IonIcon from 'react-native-vector-icons/Ionicons'
import { sprintf } from 'sprintf-js'

import { formatCategory, getTxActionDisplayInfo, splitCategory } from '../../actions/CategoriesActions'
import { formatCategory, getTxActionDisplayInfo, pluginIdIcons, splitCategory } from '../../actions/CategoriesActions'
import { playSendSound } from '../../actions/SoundActions'
import { getSymbolFromCurrency } from '../../constants/WalletAndCurrencyConstants'
import { useContactThumbnail } from '../../hooks/redux/useContactThumbnail'
Expand Down Expand Up @@ -60,11 +60,11 @@ const TransactionDetailsComponent = (props: Props) => {
const account = useSelector(state => state.core.account)
const styles = getStyles(theme)
// Choose a default category based on metadata or the txAction
const { direction, mergedData, savedData } = getTxActionDisplayInfo(transaction, account, wallet)
const { direction, iconPluginId, mergedData, savedData } = getTxActionDisplayInfo(transaction, account, wallet)

const swapData = convertActionToSwapData(account, transaction) ?? transaction.swapData

const thumbnailPath = useContactThumbnail(mergedData.name)
const thumbnailPath = useContactThumbnail(mergedData.name) ?? pluginIdIcons[iconPluginId ?? '']

const [localMetadata, setLocalMetadata] = React.useState<EdgeMetadata>({
exchangeAmount: metadata?.exchangeAmount,
Expand Down
15 changes: 12 additions & 3 deletions src/components/scenes/TransactionsExportScene.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { asBoolean, asObject, asString } from 'cleaners'
import { EdgeCurrencyWallet, EdgeTokenId, EdgeTransaction } from 'edge-core-js'
import { EdgeAccount, EdgeCurrencyWallet, EdgeTokenId, EdgeTransaction } from 'edge-core-js'
import * as React from 'react'
import { Platform } from 'react-native'
import RNFS from 'react-native-fs'
import Share from 'react-native-share'
import EntypoIcon from 'react-native-vector-icons/Entypo'

import { getTxActionDisplayInfo } from '../../actions/CategoriesActions'
import { exportTransactionsToBitwave, exportTransactionsToCSV, exportTransactionsToQBO, updateTxsFiat } from '../../actions/TransactionExportActions'
import { formatDate } from '../../locales/intl'
import { lstrings } from '../../locales/strings'
Expand Down Expand Up @@ -35,6 +36,7 @@ interface File {
interface OwnProps extends EdgeSceneProps<'transactionsExport'> {}

interface StateProps {
account: EdgeAccount
multiplier: string
exchangeMultiplier: string
parentMultiplier: string
Expand Down Expand Up @@ -206,7 +208,7 @@ class TransactionsExportSceneComponent extends React.PureComponent<Props, State>
}

handleSubmit = async (): Promise<void> => {
const { exchangeMultiplier, multiplier, parentMultiplier, route } = this.props
const { account, exchangeMultiplier, multiplier, parentMultiplier, route } = this.props
const { sourceWallet, currencyCode } = route.params
const { isExportBitwave, isExportQbo, isExportCsv, startDate, endDate } = this.state
const { tokenId } = this.props
Expand Down Expand Up @@ -285,12 +287,18 @@ class TransactionsExportSceneComponent extends React.PureComponent<Props, State>
.trim()
.replace(/[-\s]+/g, '-') // Collapse spaces & dashes

const txs = await sourceWallet.getTransactions({
const rawTxs = await sourceWallet.getTransactions({
tokenId,
startDate,
endDate
})

const txs = rawTxs.map(tx => {
const { mergedData } = getTxActionDisplayInfo(tx, account, sourceWallet)
const out: EdgeTransaction = { ...tx, metadata: mergedData }
return out
})

const files: File[] = []
const formats: string[] = []

Expand Down Expand Up @@ -380,6 +388,7 @@ class TransactionsExportSceneComponent extends React.PureComponent<Props, State>

export const TransactionsExportScene = connect<StateProps, DispatchProps, OwnProps>(
(state, { route: { params } }) => ({
account: state.core.account,
multiplier: getDisplayDenomination(state, params.sourceWallet.currencyInfo.pluginId, params.currencyCode).multiplier,
exchangeMultiplier: getExchangeDenomination(state, params.sourceWallet.currencyInfo.pluginId, params.currencyCode).multiplier,
parentMultiplier: getExchangeDenomination(state, params.sourceWallet.currencyInfo.pluginId, params.sourceWallet.currencyInfo.currencyCode).multiplier,
Expand Down
6 changes: 3 additions & 3 deletions src/components/themed/TransactionListRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Share from 'react-native-share'
import Ionicons from 'react-native-vector-icons/Ionicons'
import { sprintf } from 'sprintf-js'

import { formatCategory, getTxActionDisplayInfo, splitCategory } from '../../actions/CategoriesActions'
import { formatCategory, getTxActionDisplayInfo, pluginIdIcons, splitCategory } from '../../actions/CategoriesActions'
import { getSymbolFromCurrency } from '../../constants/WalletAndCurrencyConstants'
import { useContactThumbnail } from '../../hooks/redux/useContactThumbnail'
import { displayFiatAmount } from '../../hooks/useFiatText'
Expand Down Expand Up @@ -77,7 +77,7 @@ export function TransactionListRow(props: Props) {
maxConversionDecimals = maxPrimaryCurrencyConversionDecimals(log10(displayDenomination.multiplier), precisionAdjustValue)
}

const { direction, mergedData } = getTxActionDisplayInfo(transaction, account, wallet)
const { direction, iconPluginId, mergedData } = getTxActionDisplayInfo(transaction, account, wallet)
const { category, name } = mergedData
const isSentTransaction = direction === 'send'

Expand Down Expand Up @@ -120,7 +120,7 @@ export function TransactionListRow(props: Props) {
}

// Icon & Thumbnail
const thumbnailPath = useContactThumbnail(name)
const thumbnailPath = useContactThumbnail(name) ?? pluginIdIcons[iconPluginId ?? '']
if (thumbnailPath != null) {
arrowIconSize = theme.rem(1)
arrowContainerStyle.push(styles.arrowIconOverlayContainer)
Expand Down
8 changes: 6 additions & 2 deletions src/constants/txActionConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ import { lstrings } from '../locales/strings'

export const TX_ACTION_LABEL_MAP: Record<EdgeAssetActionType, string> = {
buy: lstrings.fiat_plugin_buy_currencycode,
claim: lstrings.transaction_details_claim,
claimOrder: lstrings.transaction_details_claim_order,
sell: lstrings.fiat_plugin_sell_currencycode_s,
sellNetworkFee: lstrings.fiat_plugin_sell_network_fee,
swap: lstrings.transaction_details_swap,
swapNetworkFee: lstrings.transaction_details_swap_network_fee,
swapOrderPost: lstrings.transaction_details_swap_order_post,
swapOrderFill: lstrings.transaction_details_swap_order_fill,
swapOrderCancel: lstrings.transaction_details_swap_order_cancel,
stake: lstrings.transaction_details_stake,
stakeNetworkFee: '',
stakeNetworkFee: lstrings.transaction_details_stake_network_fee,
stakeOrder: lstrings.transaction_details_stake_order,
tokenApproval: lstrings.transaction_details_token_approval,
transfer: lstrings.transaction_details_transfer_funds,
transferNetworkFee: lstrings.transaction_details_transfer_network_fee,
unstake: lstrings.transaction_details_unstake,
unstakeNetworkFee: '',
unstakeNetworkFee: lstrings.transaction_details_unstake_network_fee,
unstakeOrder: lstrings.transaction_details_unstake_order
}
6 changes: 6 additions & 0 deletions src/locales/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,12 +692,18 @@ const strings = {
transaction_details_exchange_support_request: '%s Support Request',
transaction_details_fee_warning: 'High Network Fees',
transaction_details_swap: 'Swap Funds',
transaction_details_swap_network_fee: 'Swap Network Fee',
transaction_details_swap_order_cancel: 'Swap Order Canceled',
transaction_details_swap_order_post: 'Swap Order Opened',
transaction_details_swap_order_fill: 'Swap Order Filled',
transaction_details_claim: 'Claim Staked Funds',
transaction_details_claim_order: 'Claim Order',
transaction_details_stake: 'Stake Funds',
transaction_details_stake_order: 'Stake Order',
transaction_details_stake_network_fee: 'Stake Network Fee',
transaction_details_transfer_network_fee: 'Transfer Network Fee',
transaction_details_unstake: 'Unstake Funds',
transaction_details_unstake_network_fee: 'Unstake Network Fee',
transaction_details_unstake_order: 'Unstake Order',

transaction_details_swap_to_subcat_1s: 'To %1$s',
Expand Down
6 changes: 6 additions & 0 deletions src/locales/strings/enUS.json
Original file line number Diff line number Diff line change
Expand Up @@ -623,12 +623,18 @@
"transaction_details_exchange_support_request": "%s Support Request",
"transaction_details_fee_warning": "High Network Fees",
"transaction_details_swap": "Swap Funds",
"transaction_details_swap_network_fee": "Swap Network Fee",
"transaction_details_swap_order_cancel": "Swap Order Canceled",
"transaction_details_swap_order_post": "Swap Order Opened",
"transaction_details_swap_order_fill": "Swap Order Filled",
"transaction_details_claim": "Claim Staked Funds",
"transaction_details_claim_order": "Claim Order",
"transaction_details_stake": "Stake Funds",
"transaction_details_stake_order": "Stake Order",
"transaction_details_stake_network_fee": "Stake Network Fee",
"transaction_details_transfer_network_fee": "Transfer Network Fee",
"transaction_details_unstake": "Unstake Funds",
"transaction_details_unstake_network_fee": "Unstake Network Fee",
"transaction_details_unstake_order": "Unstake Order",
"transaction_details_swap_to_subcat_1s": "To %1$s",
"transaction_details_swap_from_subcat_1s": "From %1$s",
Expand Down
36 changes: 36 additions & 0 deletions src/plugins/stake-plugins/currency/tronStakePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,18 @@ export const makeTronStakePlugin = async (): Promise<StakePlugin> => {
otherParams: {
type: 'addV2',
params: { nativeAmount, resource }
},
assetAction: { assetActionType: 'stake' },
savedAction: {
actionType: 'stake',
pluginId: stakeProviderInfo.pluginId,
stakeAssets: [
{
pluginId,
tokenId: null,
nativeAmount
}
]
}
}
edgeTransaction = await wallet.makeSpend(spendInfo)
Expand All @@ -191,6 +203,18 @@ export const makeTronStakePlugin = async (): Promise<StakePlugin> => {
otherParams: {
type: 'removeV2',
params: { nativeAmount, resource }
},
assetAction: { assetActionType: 'unstake' },
savedAction: {
actionType: 'stake',
pluginId: stakeProviderInfo.pluginId,
stakeAssets: [
{
pluginId,
tokenId: null,
nativeAmount
}
]
}
}
edgeTransaction = await wallet.makeSpend(spendInfo)
Expand All @@ -202,6 +226,18 @@ export const makeTronStakePlugin = async (): Promise<StakePlugin> => {
spendTargets,
otherParams: {
type: 'withdrawExpireUnfreeze'
},
assetAction: { assetActionType: 'claim' },
savedAction: {
actionType: 'stake',
pluginId: stakeProviderInfo.pluginId,
stakeAssets: [
{
pluginId,
tokenId: null,
nativeAmount
}
]
}
}
edgeTransaction = await wallet.makeSpend(spendInfo)
Expand Down
Loading

0 comments on commit 4439318

Please sign in to comment.