@exodus/web3-ethereum-utils 3.37.0 → 3.38.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.
@@ -24,10 +24,19 @@ export const createSimulateTransactions = ({ apiEndpoint, headers }) => async ({
24
24
  simulationResult,
25
25
  headers,
26
26
  });
27
- if (simulationTransactionInternalResult.kind === 'error' &&
28
- simulationTransactionInternalResult.error ===
29
- 0 /* SimulationErrorMessages.SimulationNotSupported */) {
30
- tryEstimatingChangesLocally({ asset, simulationResult, transaction });
27
+ if (simulationTransactionInternalResult.kind === 'error') {
28
+ const simulatedLocally = tryEstimatingChangesLocally({
29
+ asset,
30
+ simulationResult,
31
+ transaction,
32
+ });
33
+ if (!simulatedLocally) {
34
+ simulationResult.warnings.push({
35
+ kind: 'INTERNAL_ERROR',
36
+ severity: 'HIGH',
37
+ message: 'Balance changes cannot be estimated.',
38
+ });
39
+ }
31
40
  return simulationResult;
32
41
  }
33
42
  simulationResult.displayDetails = getDisplayDetails(simulationResult.balanceChanges.willApprove);
@@ -5,7 +5,8 @@ declare type SimulateTransactionParams = Required<Pick<CreateSimulateTransaction
5
5
  headers?: Record<string, string>;
6
6
  };
7
7
  export declare const enum SimulationErrorMessages {
8
- 'SimulationNotSupported' = 0
8
+ 'SimulationNotSupported' = 0,
9
+ 'APICallFailed' = 1
9
10
  }
10
11
  export declare const simulateTransactions: ({ transactions, apiEndpoint, origin, simulationResult, headers, asset, }: SimulateTransactionParams) => SimulateTransactionsInternalResult<undefined, SimulationErrorMessages>;
11
12
  export {};
@@ -53,7 +53,11 @@ const handleExpectedBalanceChange = (expectedBalanceChange, simulationResult, {
53
53
  ]);
54
54
  // According to the Blowfish docs, `symbol` and `name` can be null as they are not required by the standard.
55
55
  // Using `NFT` as a fallback ensures a user sees a meaningful UI in that case.
56
- const symbol = asset.symbol || asset.name || 'NFT';
56
+ let symbol = asset.symbol || asset.name || 'NFT';
57
+ // TODO: remove this once Blowfish completes their migration from Matic to POL.
58
+ if (network === 'polygon' && asset.symbol === 'MATIC') {
59
+ symbol = 'POL';
60
+ }
57
61
  if (isNftTransfer || isNftTransferApproval) {
58
62
  asset_.imageUrl = data?.metadata?.rawImageUrl;
59
63
  }
@@ -141,7 +145,10 @@ export const simulateTransactions = async ({ transactions, apiEndpoint, origin,
141
145
  headers,
142
146
  });
143
147
  if (!response) {
144
- return successDefaultResult;
148
+ return {
149
+ kind: 'error',
150
+ error: 1 /* SimulationErrorMessages.APICallFailed */,
151
+ };
145
152
  }
146
153
  simulationResult.metadata.simulatedLocally = false;
147
154
  const { expectedStateChanges = {}, error } = response.simulationResults.aggregated;
@@ -4,4 +4,4 @@ export declare const tryEstimatingChangesLocally: ({ asset, simulationResult, tr
4
4
  asset: Asset;
5
5
  simulationResult: EthAggregatedTransactionSimulationResult;
6
6
  transaction: EthTransaction;
7
- }) => void;
7
+ }) => boolean;
@@ -3,6 +3,7 @@ import { getCreateCurrencyParams } from './common.js';
3
3
  import { estimateSimpleTransfer, NotSimpleTransferError, } from './estimateSimpleTransfer.js';
4
4
  /*
5
5
  Mutates the provided 'simulationResult' adding a 'willSend' entry if the transaction is a simple transfer.
6
+ The function also returns a boolean indicating whether the local simulation was possible (e.g., if any balance changes were made).
6
7
  */
7
8
  export const tryEstimatingChangesLocally = ({ asset, simulationResult, transaction, }) => {
8
9
  try {
@@ -13,11 +14,13 @@ export const tryEstimatingChangesLocally = ({ asset, simulationResult, transacti
13
14
  simulationResult.balanceChanges.willSend.push({
14
15
  balance: actualTransferValue,
15
16
  });
17
+ return true;
16
18
  }
17
19
  catch (err) {
18
20
  const expectedError = err instanceof NotSimpleTransferError;
19
21
  if (!expectedError) {
20
22
  // ToDo: accept a logger dep and log an error here
21
23
  }
24
+ return false;
22
25
  }
23
26
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@exodus/web3-ethereum-utils",
3
3
  "description": "Web3 Ethereum utils.",
4
- "version": "3.37.0",
4
+ "version": "3.38.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "module": "lib/index.js",
@@ -36,5 +36,5 @@
36
36
  "@exodus/web3-utils": "^1.48.2",
37
37
  "@metamask/eth-sig-util": "^4.0.1"
38
38
  },
39
- "gitHead": "7f05caccbeec6ffb7785e6c404fe5a1141764706"
39
+ "gitHead": "212dd8249e074525316708335355fda305aa691f"
40
40
  }