@exodus/activity-txs 4.1.0 → 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,19 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [4.1.2](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/activity-txs@4.1.1...@exodus/activity-txs@4.1.2) (2024-05-15)
7
+
8
+ ### Bug Fixes
9
+
10
+ - address security feedback ([#6963](https://github.com/ExodusMovement/exodus-hydra/issues/6963)) ([155bdfe](https://github.com/ExodusMovement/exodus-hydra/commit/155bdfed531685108d828be60c9d1a8be9e785ee))
11
+ - indexless order should be ignored in first loop ([#6965](https://github.com/ExodusMovement/exodus-hydra/issues/6965)) ([83766cd](https://github.com/ExodusMovement/exodus-hydra/commit/83766cd69533d81317ea52ab770541a7ccfde274))
12
+
13
+ ## [4.1.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/activity-txs@4.1.0...@exodus/activity-txs@4.1.1) (2024-05-15)
14
+
15
+ ### Bug Fixes
16
+
17
+ - duplicated activity items for transfers ([#6931](https://github.com/ExodusMovement/exodus-hydra/issues/6931)) ([7d2acb6](https://github.com/ExodusMovement/exodus-hydra/commit/7d2acb63b3151b9703243349e256b1db52613b43))
18
+
6
19
  ## [4.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/activity-txs@4.0.1...@exodus/activity-txs@4.1.0) (2024-05-13)
7
20
 
8
21
  ### Features
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/activity-txs",
3
- "version": "4.1.0",
3
+ "version": "4.1.2",
4
4
  "description": "The activity-txs feature",
5
5
  "author": "Exodus Movement, Inc.",
6
6
  "repository": {
@@ -46,19 +46,19 @@
46
46
  "@exodus/assets-feature": "^5.3.1",
47
47
  "@exodus/available-assets": "^8.2.0",
48
48
  "@exodus/bitcoin-plugin": "^1.4.2",
49
- "@exodus/blockchain-metadata": "^15.3.0",
49
+ "@exodus/blockchain-metadata": "^15.3.1",
50
50
  "@exodus/connected-origins": "^3.3.1",
51
51
  "@exodus/dependency-injection": "^2.2.0",
52
52
  "@exodus/dependency-preprocessors": "^5.2.0",
53
- "@exodus/fiat-ramp": "^10.5.0",
53
+ "@exodus/fiat-ramp": "^10.5.1",
54
54
  "@exodus/nfts": "^9.2.1",
55
55
  "@exodus/orders": "^4.8.1",
56
56
  "@exodus/personal-notes": "^3.6.0",
57
57
  "@exodus/redux-dependency-injection": "^3.1.0",
58
58
  "@exodus/storage-memory": "^2.1.1",
59
- "@exodus/wallet-accounts": "^16.4.0",
59
+ "@exodus/wallet-accounts": "^16.5.0",
60
60
  "@types/minimalistic-assert": "^1.0.1",
61
61
  "redux": "^4.2.1"
62
62
  },
63
- "gitHead": "345159fcb1012fc873ba5ecc24880d5c54700d0b"
63
+ "gitHead": "a0c1b2cb7cdd31f455f566879612777c8d46b654"
64
64
  }
@@ -12,24 +12,36 @@ const generateActivityId = ({ activityItem }) => {
12
12
  : `${activityItem.assetName}.${activityItem.txId}`
13
13
  }
14
14
 
15
- const groupTxsWithSameOrder = ({ txs, orderSet }) => {
15
+ const groupTxsWithSameOrder = ({ txs, orderSet, isIndexless }) => {
16
16
  const getOrder = (tx) => orderSet.getByTxId(tx.txId)
17
- const exchangeByOrderId = {}
17
+ const exchangeByOrderId = new Map()
18
18
  const result = []
19
+
19
20
  for (const tx of txs) {
20
21
  const order = getOrder(tx)
22
+ if (isIndexless && order) {
23
+ // Orders are the source of truth for indexless swaps.
24
+ // Skip this tx and add it later as exchanged.
25
+ continue
26
+ }
27
+
21
28
  if (order) {
22
- ;(exchangeByOrderId[order.orderId] ?? (exchangeByOrderId[order.orderId] = [])).push(tx)
29
+ if (!exchangeByOrderId.has(order.orderId)) {
30
+ exchangeByOrderId.set(order.orderId, [])
31
+ }
32
+
33
+ exchangeByOrderId.get(order.orderId).push(tx)
23
34
  } else {
24
35
  result.push({ tx, type: 'tx' })
25
36
  }
26
37
  }
27
38
 
28
- Object.values(exchangeByOrderId).forEach((txsGroup) => {
39
+ exchangeByOrderId.forEach((txsGroup) => {
29
40
  const tx = txsGroup.sort((a, b) => b.date.getTime() - a.date.getTime())[0]
30
41
  const order = getOrder(tx)
31
42
  result.push({ tx, type: 'exchange', order })
32
43
  })
44
+
33
45
  return result
34
46
  }
35
47
 
@@ -50,13 +62,13 @@ const createAssetSourceBaseActivitySelectorDefinition = {
50
62
  getPersonalNoteByTxIdSelector,
51
63
  (assets, txs = EMPTY, orderSet, getPersonalNoteByTxId) => {
52
64
  const activityResult = []
53
-
54
- const groupedTxs = groupTxsWithSameOrder({ txs, orderSet })
65
+ const isIndexless = assets[assetName]?.baseAsset?.api?.features?.noHistory
66
+ const groupedTxs = groupTxsWithSameOrder({ txs, orderSet, isIndexless })
55
67
 
56
68
  for (const group of groupedTxs) {
57
69
  const { tx, order, type: formatterType } = group
58
70
  const personalNote = getPersonalNoteByTxId(tx.txId)
59
- const formattedTx = formattersByType[formatterType]({
71
+ const formattedTx = formattersByType.get(formatterType)({
60
72
  assets,
61
73
  order,
62
74
  tx,
@@ -67,7 +79,6 @@ const createAssetSourceBaseActivitySelectorDefinition = {
67
79
  activityResult.push(formattedTx)
68
80
  }
69
81
 
70
- const isIndexless = assets[assetName]?.baseAsset?.api?.features?.noHistory
71
82
  if (isIndexless) {
72
83
  const orderIdsFromActivity = new Set(activityResult.map((tx) => tx.orderId))
73
84
  const ordersForIndexlessAssets = [...orderSet].filter(
@@ -91,7 +102,7 @@ const createAssetSourceBaseActivitySelectorDefinition = {
91
102
  data: { swapTx: true },
92
103
  selfSend: false,
93
104
  token: null, // TBD
94
- bumpType: {},
105
+ bumpType: Object.create(null),
95
106
  coinName: isFromIndexlessAsset ? order.fromAsset : order.toAsset,
96
107
  value: isFromIndexlessAsset ? order.fromAmount : order.toAmount,
97
108
  coinAmount: isFromIndexlessAsset ? order.fromAmount : order.toAmount,
@@ -6,11 +6,14 @@ const selectorFactory =
6
6
  createWithConnectionsActivity
7
7
  ) =>
8
8
  // call this once on client-side
9
- (options = {}) => {
9
+ (options = Object.create(null)) => {
10
10
  let createFullSelector = createAssetSourceBaseActivity
11
11
  createFullSelector = createWithNftsActivity({
12
12
  createActivitySelector: createFullSelector,
13
- nftsNetworkNameToAssetName: options.nftsNetworkNameToAssetName || {},
13
+ nftsNetworkNameToAssetName:
14
+ (Object.hasOwn(options, 'nftsNetworkNameToAssetName') &&
15
+ options.nftsNetworkNameToAssetName) ||
16
+ Object.create(null),
14
17
  })
15
18
  createFullSelector = createWithFiatActivity({ createActivitySelector: createFullSelector })
16
19
  createFullSelector = createWithConnectionsActivity({
@@ -1,6 +1,7 @@
1
1
  import { memoize } from '@exodus/basic-utils'
2
2
  import { createSelector } from 'reselect'
3
3
  import assert from 'minimalistic-assert'
4
+ import { uniqBy } from 'lodash'
4
5
 
5
6
  const selectorFactory =
6
7
  () =>
@@ -30,15 +31,21 @@ const selectorFactory =
30
31
  let result = activities.flat()
31
32
  if (dedupExchange) {
32
33
  result = result.filter((activityItem) => {
33
- if (activityItem.orderId && !ordersIncluded.has(activityItem.orderId)) {
34
- ordersIncluded.add(activityItem.orderId)
35
- return true
34
+ const { orderId } = activityItem
35
+ if (orderId) {
36
+ if (!ordersIncluded.has(orderId)) {
37
+ ordersIncluded.add(orderId)
38
+ return true
39
+ }
40
+
41
+ return false
36
42
  }
37
43
 
38
- return !ordersIncluded.has(activityItem.orderId)
44
+ return true
39
45
  })
40
46
  }
41
47
 
48
+ result = uniqBy(result, 'id')
42
49
  return result.sort((a, b) => (b.date === a.date ? 0 : b.date > a.date ? 1 : -1))
43
50
  })
44
51
  },
@@ -47,6 +47,7 @@ const selectorFactory =
47
47
  ;[...nftsByTxId.values()]
48
48
  .filter(
49
49
  (nftTx) =>
50
+ Object.hasOwn(nftsNetworkNameToAssetName, nftTx.network) &&
50
51
  assetName === nftsNetworkNameToAssetName[nftTx.network] &&
51
52
  !indexedNftTxIds.has(nftTx.txId)
52
53
  )
@@ -13,17 +13,17 @@ const EXODEX_TX_TYPES = {
13
13
  CLEANUP: 'cleanupTransaction',
14
14
  }
15
15
 
16
- const UI_TX_TYPE_FROM_EXODEX = {
17
- [EXODEX_TX_TYPES.PRE_SETUP]: TX_TYPES.APPROVAL,
18
- [EXODEX_TX_TYPES.SETUP]: TX_TYPES.APPROVAL,
19
- [EXODEX_TX_TYPES.SWAP]: TX_TYPES.EXCHANGE,
20
- [EXODEX_TX_TYPES.CLEANUP]: TX_TYPES.CLEANUP,
21
- }
16
+ const UI_TX_TYPE_FROM_EXODEX = new Map([
17
+ [EXODEX_TX_TYPES.PRE_SETUP, TX_TYPES.APPROVAL],
18
+ [EXODEX_TX_TYPES.SETUP, TX_TYPES.APPROVAL],
19
+ [EXODEX_TX_TYPES.SWAP, TX_TYPES.EXCHANGE],
20
+ [EXODEX_TX_TYPES.CLEANUP, TX_TYPES.CLEANUP],
21
+ ])
22
22
 
23
23
  function getTxType({ tx, order }) {
24
24
  if (order) {
25
25
  const txInfoFromOrder = order.txIds?.find((txFromOrder) => txFromOrder.txId === tx.txId)
26
- return UI_TX_TYPE_FROM_EXODEX[txInfoFromOrder?.txType] || TX_TYPES.EXCHANGE
26
+ return UI_TX_TYPE_FROM_EXODEX.get(txInfoFromOrder?.txType) || TX_TYPES.EXCHANGE
27
27
  }
28
28
 
29
29
  return tx.sent ? TX_TYPES.SENT : TX_TYPES.RECEIVED
@@ -82,10 +82,10 @@ const formatGroupedTx = ({ tx, assets, personalNote }) =>
82
82
  personalNote,
83
83
  })
84
84
 
85
- export const formattersByType = {
86
- exchange: formatGroupedExchangeTxs,
87
- tx: formatGroupedTx,
88
- }
85
+ export const formattersByType = new Map([
86
+ ['exchange', formatGroupedExchangeTxs],
87
+ ['tx', formatGroupedTx],
88
+ ])
89
89
 
90
90
  export const formatUnindexedNftTx = ({ asset, nftTx }) => {
91
91
  return {