Skip to content

Commit

Permalink
fixup! Add back stakeMetadataCache processing on new transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
samholmes committed Sep 7, 2023
1 parent 732d9b9 commit 5c7ee4d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 68 deletions.
15 changes: 4 additions & 11 deletions src/components/services/AccountCallbackManager.tsx
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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]
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/stake-plugins/metadataCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 })
}
30 changes: 10 additions & 20 deletions src/plugins/stake-plugins/uniswapV2/policies/cemeteryPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 12 additions & 34 deletions src/plugins/stake-plugins/uniswapV2/policies/masonryPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand All @@ -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'))
)
}
Expand All @@ -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'))
)
}
Expand Down

0 comments on commit 5c7ee4d

Please sign in to comment.