@exodus/ethereum-api 2.23.0 → 2.24.1

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/ethereum-api",
3
- "version": "2.23.0",
3
+ "version": "2.24.1",
4
4
  "description": "Ethereum Api",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -29,12 +29,12 @@
29
29
  "ms": "^2.1.1",
30
30
  "url": "0.10.3",
31
31
  "url-join": "4.0.0",
32
- "ws": "6.1.0"
32
+ "ws": "^6.1.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@exodus/assets": "^8.0.67",
36
36
  "@exodus/assets-base": "^8.0.136",
37
37
  "@exodus/models": "^8.7.2"
38
38
  },
39
- "gitHead": "5a1621d8fb3c1ecf4c47dc37f284e9a40d7fd018"
39
+ "gitHead": "3ebe0a3ec7c9090ebbd451c0845b64090852cead"
40
40
  }
@@ -4,8 +4,6 @@ import { memoizeLruCache } from '@exodus/asset-lib'
4
4
  import assets from '@exodus/assets'
5
5
  import SolidityContract from '@exodus/solidity-contract'
6
6
 
7
- // Mobile only.
8
- // We should refactor mobile to pass 'asset' instead of 'assetName' so that we can use 'isContractAddress'. But that would touch many assets.
9
7
  export async function isContract(baseAssetName, address) {
10
8
  return getServerByName(baseAssetName).isContract(address)
11
9
  }
@@ -1,4 +1,4 @@
1
- import assert from 'assert'
1
+ import assert from 'minimalistic-assert'
2
2
  import request from './request'
3
3
 
4
4
  const isValidResponseCheck = (x) =>
@@ -1,4 +1,4 @@
1
- import assert from 'assert'
1
+ import assert from 'minimalistic-assert'
2
2
  import request from './request'
3
3
 
4
4
  const isValidResponseCheck = (x) =>
@@ -1,4 +1,6 @@
1
1
  import assets from '@exodus/assets'
2
+ import { APPROVE_METHOD_ID } from '@exodus/ethereum-lib'
3
+ import SolidityContract from '@exodus/solidity-contract'
2
4
 
3
5
  import { fetchTxPreview } from './fetch-tx-preview'
4
6
  import { getERC20Params } from '../eth-like-util'
@@ -67,10 +69,36 @@ async function prepareBalanceChanges(internalTransactions, balanceChanges) {
67
69
  return preparedBalanceChanges
68
70
  }
69
71
 
72
+ async function tryToDecodeApprovalTransaction(transaction) {
73
+ if (!transaction?.data.startsWith(APPROVE_METHOD_ID)) return null
74
+
75
+ const contract = SolidityContract.erc20(transaction.to)
76
+ try {
77
+ const decodedInput = contract.decodeInput(transaction.data)
78
+ if (!decodedInput.values) return null
79
+
80
+ const [grantedTo, balance] = decodedInput.values
81
+
82
+ const symbol =
83
+ (await getAssetSymbolFromContract(transaction.to)).toUpperCase() || 'Unknown Token'
84
+
85
+ return [{ grantedTo, balance, symbol, decimals: undefined }] // ToDo: Return 'decimals' in the future once we support changing the approval amount.
86
+ } catch (e) {
87
+ console.error(e.message)
88
+
89
+ return null
90
+ }
91
+ }
92
+
70
93
  export async function simulateAndRetrieveSideEffects(transaction) {
71
94
  const willSend = []
72
95
  const willReceive = []
73
96
 
97
+ const approveTransactionData = await tryToDecodeApprovalTransaction(transaction)
98
+ if (approveTransactionData) {
99
+ return { willApprove: approveTransactionData }
100
+ }
101
+
74
102
  if (!transaction.to) throw new Error(`'to' field is missing in the TX object`)
75
103
 
76
104
  const blocknativeTxObject = {
@@ -4,23 +4,17 @@
4
4
  *
5
5
  * Based on https://github.com/ExodusMovement/fetch/blob/master/core.js , note that chooses native on Desktop
6
6
  */
7
- if (
8
- typeof process !== 'undefined' &&
9
- (process.type === 'renderer' || process.type === 'worker')
10
- ) {
7
+ if (typeof process !== 'undefined' && (process.type === 'renderer' || process.type === 'worker')) {
11
8
  // THIS IS FOR DESKTOP
12
9
  if (process.env.EXODUS_DISABLE_WS) {
13
10
  module.exports = globalThis.WebSocket
14
11
  } else {
15
12
  module.exports = require('ws')
16
13
  }
14
+ } else if (typeof WebSocket !== 'undefined') {
15
+ // THIS IS FOR BE
16
+ module.exports = globalThis.WebSocket
17
17
  } else {
18
- // eslint-disable-next-line no-undef
19
- if (global.window?.WebSocket) {
20
- // THIS IS FOR BE
21
- module.exports = global.window?.WebSocket
22
- } else {
23
- // THIS IS FOR UNIT TESTING.
24
- module.exports = require('ws')
25
- }
18
+ // THIS IS FOR UNIT TESTING.
19
+ module.exports = require('ws')
26
20
  }