@exodus/ethereum-api 2.23.0 → 2.24.0

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.0",
4
4
  "description": "Ethereum Api",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -36,5 +36,5 @@
36
36
  "@exodus/assets-base": "^8.0.136",
37
37
  "@exodus/models": "^8.7.2"
38
38
  },
39
- "gitHead": "5a1621d8fb3c1ecf4c47dc37f284e9a40d7fd018"
39
+ "gitHead": "43d1c84ed5ecc17a3970113097ec9ad6d58e4312"
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,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,35 @@ 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 = (await getAssetSymbolFromContract(transaction.to)).toUpperCase() || 'Token'
83
+
84
+ return [{ grantedTo, balance, symbol, decimals: undefined }] // ToDo: Return 'decimals' in the future once we support changing the approval amount.
85
+ } catch (e) {
86
+ console.error(e.message)
87
+
88
+ return null
89
+ }
90
+ }
91
+
70
92
  export async function simulateAndRetrieveSideEffects(transaction) {
71
93
  const willSend = []
72
94
  const willReceive = []
73
95
 
96
+ const approveTransactionData = await tryToDecodeApprovalTransaction(transaction)
97
+ if (approveTransactionData) {
98
+ return { willApprove: approveTransactionData }
99
+ }
100
+
74
101
  if (!transaction.to) throw new Error(`'to' field is missing in the TX object`)
75
102
 
76
103
  const blocknativeTxObject = {
@@ -4,10 +4,7 @@
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