@exodus/bitcoin-plugin 1.6.10 → 1.6.11

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.10",
3
+ "version": "1.6.11",
4
4
  "description": "Exodus bitcoin-plugin",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -20,11 +20,14 @@
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.0",
23
+ "@exodus/bitcoin-api": "^2.7.1",
24
24
  "@exodus/bitcoin-lib": "^2.2.11",
25
25
  "@exodus/models": "^11.0.0",
26
26
  "@exodus/text-encoding-utf8": "^1.0.2",
27
27
  "minimalistic-assert": "^1.0.1"
28
28
  },
29
- "gitHead": "5c306496cb4086ff823640e8eadb0d9750ac3683"
29
+ "devDependencies": {
30
+ "@exodus/nfts-proxy": "^2.10.1"
31
+ },
32
+ "gitHead": "9c993eed3a3bcfc1c49d86377fdc5c7cb731d632"
30
33
  }
@@ -44,6 +44,7 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl: defaultApiUrl, coinIn
44
44
  gapLimit = 10,
45
45
  refreshGapLimit = 25,
46
46
  overrideCallback = ({ asset }) => asset,
47
+ nftsProxy,
47
48
  feeDataCustomValues,
48
49
  } = {}) => {
49
50
  const apiUrl = customApiUrl || defaultApiUrl
@@ -172,7 +173,7 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl: defaultApiUrl, coinIn
172
173
 
173
174
  const accountStateClass = createAccountState({ asset: asset, ordinalsEnabled, brc20Enabled })
174
175
 
175
- const nfts = ordinalsEnabled ? nftsApiFactory({ ordinalChainIndex, asset }) : undefined
176
+ const nfts = ordinalsEnabled ? nftsApiFactory({ ordinalChainIndex, asset, nftsProxy }) : undefined
176
177
 
177
178
  const { createToken, getTokens, validateAssetId } = brc20Enabled
178
179
  ? createTokenFactory({ address, bip44, keys, getBalances }, [])
@@ -250,13 +251,8 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl: defaultApiUrl, coinIn
250
251
  if (tx.sent && Array.isArray(tx.data.sent) && tx.data.sent.length > 0) {
251
252
  const feeAmount = tx.feeAmount.div(tx.data.sent.length)
252
253
  return tx.data.sent
253
- .map((to, i) => {
254
- if (!to.amount) {
255
- console.warn(
256
- `${asset.name} tx ${tx.txId} sent index ${i} does not have an amount!!!`
257
- )
258
- }
259
- return tx.update({
254
+ .map((to, i) =>
255
+ tx.update({
260
256
  to: to.address,
261
257
  data: { sentIndex: i },
262
258
  coinAmount: to.amount
@@ -264,7 +260,7 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl: defaultApiUrl, coinIn
264
260
  : asset.currency.ZERO,
265
261
  feeAmount,
266
262
  })
267
- })
263
+ )
268
264
  .reverse()
269
265
  }
270
266
  return tx
@@ -3,10 +3,11 @@ import { getInscriptionAddresses } from './get-inscription-addresses'
3
3
  import { isNftBrc20 } from './nft-utils'
4
4
  import { getOrdinalsUtxos } from '@exodus/bitcoin-api'
5
5
 
6
- export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
6
+ export const nftsApiFactory = ({ ordinalChainIndex, asset, nftsProxy }) => {
7
7
  assert(asset, 'asset is required')
8
8
  assert(typeof ordinalChainIndex === 'number', 'ordinalChainIndex must be a number')
9
9
  let aci // convert to constructor argument when wallet send aci at createAsset time
10
+
10
11
  return {
11
12
  initialize: ({ assetClientInterface }) => {
12
13
  aci = assetClientInterface
@@ -42,6 +43,53 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
42
43
  })
43
44
  const storedOrdinalsUtxos = getOrdinalsUtxos({ accountState, asset })
44
45
 
46
+ const unconfirmedUtxosArray = storedOrdinalsUtxos
47
+ .toArray()
48
+ .filter((utxo) => !utxo.confirmations)
49
+
50
+ if (nftsProxy) {
51
+ try {
52
+ const retrievedNfts = await Promise.all(
53
+ unconfirmedUtxosArray.map(async (utxo) => {
54
+ const inscriptions = utxo.inscriptions || []
55
+ return Promise.all(
56
+ inscriptions.map(async ({ inscriptionId }) => {
57
+ if (nfts.find((nft) => nft.tokenId === inscriptionId)) {
58
+ return undefined
59
+ }
60
+ const id = `${asset.name}:${inscriptionId}`
61
+ try {
62
+ const json = await nftsProxy.getNft(id)
63
+ return {
64
+ ...json,
65
+ receiving: true,
66
+ output: `${utxo.txId}:${utxo.vout}`,
67
+ pendingTxId: utxo.txId,
68
+ }
69
+ } catch (e) {
70
+ console.warn(`Cannot load nft ${id} from proxy server. Error: ${e.message}`)
71
+ return undefined
72
+ }
73
+ })
74
+ )
75
+ })
76
+ )
77
+ const unconfirmedNfts = retrievedNfts.flat().filter((i) => i)
78
+ nfts.push(...unconfirmedNfts)
79
+ } catch (e) {
80
+ console.warn(
81
+ `There has been an error adding mempool bitcoin ordinals into nfts list. Error: ${e.message}`
82
+ )
83
+ }
84
+ }
85
+
86
+ const unconfirmedTxs = Array.from(
87
+ await aci.getTxLog({
88
+ walletAccount: walletAccountInstance.toString(),
89
+ assetName: asset.name,
90
+ })
91
+ ).filter((tx) => !tx.confirmations)
92
+
45
93
  const utxosOutputs = storedOrdinalsUtxos
46
94
  .toArray()
47
95
  .map((utxo) => {
@@ -49,13 +97,25 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
49
97
  })
50
98
  .filter(Boolean)
51
99
 
52
- const expandedNfts = nfts.map((nft) => ({
53
- ...nft,
54
- collectionName: nft.collectionName || 'No Collection',
55
- inTransit: !utxosOutputs.includes(nft.output.toLowerCase()),
56
- }))
100
+ const expandedNfts = nfts.map((nft) => {
101
+ const sending = !utxosOutputs.includes(nft.output.toLowerCase())
102
+ if (sending) {
103
+ const sendingTx = unconfirmedTxs.find((tx) =>
104
+ tx.data.sentInscriptions?.find((i) => i.inscriptionId === nft.tokenId)
105
+ )
106
+ return {
107
+ ...nft,
108
+ sending,
109
+ pendingTxId: sendingTx?.txId,
110
+ }
111
+ } else {
112
+ return nft
113
+ }
114
+ })
57
115
 
58
- return expandedNfts.filter((nft) => !isNftBrc20(nft))
116
+ return expandedNfts
117
+ .filter((nft) => !isNftBrc20(nft))
118
+ .map((nft) => ({ ...nft, collectionName: nft.collectionName || 'No Collection' }))
59
119
  },
60
120
  }
61
121
  }