@exodus/bitcoin-plugin 1.6.15 → 1.6.17

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/bitcoin-plugin",
3
- "version": "1.6.15",
3
+ "version": "1.6.17",
4
4
  "description": "Exodus bitcoin-plugin",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -20,7 +20,7 @@
20
20
  "dependencies": {
21
21
  "@exodus/asset-lib": "^4.0.0",
22
22
  "@exodus/basic-utils": "^2.1.0",
23
- "@exodus/bitcoin-api": "^2.7.4",
23
+ "@exodus/bitcoin-api": "^2.7.5",
24
24
  "@exodus/bitcoin-lib": "^2.2.11",
25
25
  "@exodus/models": "^11.0.0",
26
26
  "@exodus/text-encoding-utf8": "^1.0.2",
@@ -29,5 +29,5 @@
29
29
  "devDependencies": {
30
30
  "@exodus/nfts-proxy": "^2.10.1"
31
31
  },
32
- "gitHead": "5b42d1ffc18052f588f3602e8737767a6f12449b"
32
+ "gitHead": "7596b820ccf23528fae15ccee13c269fa930434b"
33
33
  }
@@ -2,6 +2,7 @@ import assert from 'minimalistic-assert'
2
2
  import { getInscriptionAddresses } from './get-inscription-addresses'
3
3
  import { isNftBrc20 } from './nft-utils'
4
4
  import { getOrdinalsUtxos } from '@exodus/bitcoin-api'
5
+ import { uniq } from 'lodash'
5
6
 
6
7
  export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
7
8
  assert(asset, 'asset is required')
@@ -47,31 +48,37 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
47
48
  const unconfirmedUtxosArray = storedOrdinalsUtxos
48
49
  .toArray()
49
50
  .filter((utxo) => !utxo.confirmations)
51
+
52
+ const inscriptionIds = unconfirmedUtxosArray.flatMap(({ inscriptions }) =>
53
+ inscriptions.map(({ inscriptionId }) => inscriptionId)
54
+ )
55
+ const uniqueInscriptionIds = uniq(inscriptionIds)
56
+
50
57
  try {
51
58
  const retrievedNfts = await Promise.all(
52
- unconfirmedUtxosArray.map(async (utxo) => {
53
- const inscriptions = utxo.inscriptions || []
54
- return Promise.all(
55
- inscriptions.map(async ({ inscriptionId }) => {
56
- if (nfts.find((nft) => nft.tokenId === inscriptionId)) {
57
- return undefined
58
- }
59
- try {
60
- const json = await nftsProxy.getNft(inscriptionId)
61
- return {
62
- ...json,
63
- receiving: true,
64
- output: `${utxo.txId}:${utxo.vout}`,
65
- pendingTxId: utxo.txId,
66
- }
67
- } catch (e) {
68
- console.warn(
69
- `Cannot load ${asset.name} nft ${inscriptionId} from proxy server. Error: ${e.message}`
70
- )
71
- return undefined
72
- }
73
- })
74
- )
59
+ uniqueInscriptionIds.map(async (inscriptionId) => {
60
+ if (nfts.find((nft) => nft.tokenId === inscriptionId)) {
61
+ return undefined
62
+ }
63
+ try {
64
+ const json = await nftsProxy.getNft(inscriptionId)
65
+ const utxo = unconfirmedUtxosArray.find((utxo) =>
66
+ utxo.inscriptions
67
+ .map(({ inscriptionId }) => inscriptionId)
68
+ .includes(inscriptionId)
69
+ )
70
+ return {
71
+ ...json,
72
+ receiving: true,
73
+ output: `${utxo.txId}:${utxo.vout}`,
74
+ pendingTxId: utxo.txId,
75
+ }
76
+ } catch (e) {
77
+ console.warn(
78
+ `Cannot load ${asset.name} nft ${inscriptionId} from proxy server. Error: ${e.message}`
79
+ )
80
+ return undefined
81
+ }
75
82
  })
76
83
  )
77
84
  const unconfirmedNfts = retrievedNfts.flat().filter((i) => i)
@@ -99,17 +106,17 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
99
106
 
100
107
  const expandedNfts = nfts.map((nft) => {
101
108
  const sending = !utxosOutputs.includes(nft.output.toLowerCase())
102
- if (sending) {
103
- const sendingTx = unconfirmedTxs.find((tx) =>
109
+
110
+ const sendingTx =
111
+ sending &&
112
+ unconfirmedTxs.find((tx) =>
104
113
  tx.data.sentInscriptions?.find((i) => i.inscriptionId === nft.tokenId)
105
114
  )
106
- return {
107
- ...nft,
108
- sending,
109
- pendingTxId: sendingTx?.txId,
110
- }
111
- } else {
112
- return nft
115
+ return {
116
+ pendingTxId: sendingTx?.txId,
117
+ sending, // always set the field, if not, nft atoms deep merge could pick the old value
118
+ ...nft,
119
+ receiving: Boolean(nft.receiving),
113
120
  }
114
121
  })
115
122