From 5c7ee4d6528104709a7d45dfdbdbe8362ad8179d Mon Sep 17 00:00:00 2001 From: Samuel Holmes Date: Wed, 6 Sep 2023 17:15:40 -0700 Subject: [PATCH] fixup! Add back `stakeMetadataCache` processing on new transactions --- .../services/AccountCallbackManager.tsx | 15 ++---- src/plugins/stake-plugins/metadataCache.ts | 5 +- .../uniswapV2/policies/cemeteryPolicy.ts | 30 ++++-------- .../uniswapV2/policies/masonryPolicy.ts | 46 +++++-------------- 4 files changed, 28 insertions(+), 68 deletions(-) diff --git a/src/components/services/AccountCallbackManager.tsx b/src/components/services/AccountCallbackManager.tsx index 0072cb452c1..1270abcaa2e 100644 --- a/src/components/services/AccountCallbackManager.tsx +++ b/src/components/services/AccountCallbackManager.tsx @@ -1,4 +1,4 @@ -import { EdgeAccount, EdgeCurrencyWallet, EdgeTransaction } from 'edge-core-js' +import { EdgeAccount, EdgeCurrencyWallet } from 'edge-core-js' import { watchSecurityAlerts } from 'edge-login-ui-rn' import * as React from 'react' @@ -93,16 +93,9 @@ export function AccountCallbackManager(props: Props) { // Assign cached stake metadata if (cacheEntries != null) { cacheEntries.forEach(cacheEntry => { - const { currencyCode, metadata, nativeAmount } = cacheEntry - - const newTx: EdgeTransaction = { - ...tx, - currencyCode, - nativeAmount: nativeAmount ?? tx.nativeAmount, - metadata - } - - wallet.saveTx(newTx).catch(err => console.warn(err)) + const { currencyCode, metadata } = cacheEntry + if (tx.currencyCode !== currencyCode) return + wallet.saveTx({ ...tx, metadata }).catch(err => console.warn(err)) }) delete stakeMetadataCache[txid] diff --git a/src/plugins/stake-plugins/metadataCache.ts b/src/plugins/stake-plugins/metadataCache.ts index d985ea61945..230a1b4877c 100644 --- a/src/plugins/stake-plugins/metadataCache.ts +++ b/src/plugins/stake-plugins/metadataCache.ts @@ -5,7 +5,6 @@ import { EdgeMetadata } from 'edge-core-js/types' export interface MetadataCacheEntry { currencyCode: string metadata: EdgeMetadata - nativeAmount?: string // multiple tokens and amounts can be in each tx } export interface MetadataCache { @@ -14,9 +13,9 @@ export interface MetadataCache { export const stakeMetadataCache: MetadataCache = {} -export const cacheTxMetadata = (txid: string, currencyCode: string, metadata: EdgeMetadata, nativeAmount?: string) => { +export const cacheTxMetadata = (txid: string, currencyCode: string, metadata: EdgeMetadata) => { // Add metadata cache entry: const key = txid.toLowerCase() stakeMetadataCache[key] = stakeMetadataCache[key] ?? [] - stakeMetadataCache[key].push({ currencyCode, metadata, nativeAmount }) + stakeMetadataCache[key].push({ currencyCode, metadata }) } diff --git a/src/plugins/stake-plugins/uniswapV2/policies/cemeteryPolicy.ts b/src/plugins/stake-plugins/uniswapV2/policies/cemeteryPolicy.ts index da6450179e4..e273003a2af 100644 --- a/src/plugins/stake-plugins/uniswapV2/policies/cemeteryPolicy.ts +++ b/src/plugins/stake-plugins/uniswapV2/policies/cemeteryPolicy.ts @@ -328,26 +328,16 @@ export const makeCemeteryPolicy = (options: CemeteryPolicyOptions): StakePluginP } // Cache metadata - cacheTxMetadata( - result.hash, - tokenACurrencyCode, - { - name: metadataName, - category: 'Transfer:Staking', - notes: `Provide liquidity for ${metadataLpName} - LP` - }, - amountTokenADesired - ) - cacheTxMetadata( - result.hash, - tokenBCurrencyCode, - { - name: metadataName, - category: 'Transfer:Staking', - notes: `Provide liquidity for ${metadataLpName} - LP` - }, - amountTokenBDesired - ) + cacheTxMetadata(result.hash, tokenACurrencyCode, { + name: metadataName, + category: 'Transfer:Staking', + notes: `Provide liquidity for ${metadataLpName} - LP` + }) + cacheTxMetadata(result.hash, tokenBCurrencyCode, { + name: metadataName, + category: 'Transfer:Staking', + notes: `Provide liquidity for ${metadataLpName} - LP` + }) // // Decode the log data in the receipt to get the liquidity token transfer amount diff --git a/src/plugins/stake-plugins/uniswapV2/policies/masonryPolicy.ts b/src/plugins/stake-plugins/uniswapV2/policies/masonryPolicy.ts index 53318cc9c17..85b8a662351 100644 --- a/src/plugins/stake-plugins/uniswapV2/policies/masonryPolicy.ts +++ b/src/plugins/stake-plugins/uniswapV2/policies/masonryPolicy.ts @@ -251,18 +251,11 @@ export const makeMasonryPolicy = (options?: MasonryPolicyOptions): StakePluginPo category: 'Expense:Fees', notes: 'Stake funds' }) - cacheTxMetadata( - result.hash, - metadataStakeCurrencyCode, - { name: metadataName, category: 'Transfer:Staking', notes: 'Stake funds' }, - request.nativeAmount - ) + cacheTxMetadata(result.hash, metadataStakeCurrencyCode, { name: metadataName, category: 'Transfer:Staking', notes: 'Stake funds' }) })(gasLimitAcc('240000')) ) } - // @ts-expect-error - const earnedAmount = allocations.find(allocation => allocation.allocationType === 'earned')?.nativeAmount if (action === 'unstake') { txs.build( (gasLimit => @@ -277,22 +270,12 @@ export const makeMasonryPolicy = (options?: MasonryPolicyOptions): StakePluginPo category: 'Expense:Fees', notes: 'Unstake funds' }) - cacheTxMetadata( - result.hash, - metadataStakeCurrencyCode, - { name: metadataName, category: 'Transfer:Staking', notes: 'Unstake funds' }, - request.nativeAmount - ) - cacheTxMetadata( - result.hash, - metadataRewardCurrencyCode, - { - name: metadataName, - category: 'Income:Staking', - notes: 'Reward for staked funds' - }, - earnedAmount - ) + cacheTxMetadata(result.hash, metadataStakeCurrencyCode, { name: metadataName, category: 'Transfer:Staking', notes: 'Unstake funds' }) + cacheTxMetadata(result.hash, metadataRewardCurrencyCode, { + name: metadataName, + category: 'Income:Staking', + notes: 'Reward for staked funds' + }) })(gasLimitAcc('240000')) ) } @@ -312,16 +295,11 @@ export const makeMasonryPolicy = (options?: MasonryPolicyOptions): StakePluginPo category: 'Expense:Fees', notes: 'Claiming reward' }) - cacheTxMetadata( - result.hash, - metadataRewardCurrencyCode, - { - name: metadataName, - category: 'Income:Staking', - notes: 'Reward for staked funds' - }, - earnedAmount - ) + cacheTxMetadata(result.hash, metadataRewardCurrencyCode, { + name: metadataName, + category: 'Income:Staking', + notes: 'Reward for staked funds' + }) })(gasLimitAcc('240000')) ) }