Skip to content

Commit d8c5dfe

Browse files
committed
tweak
1 parent e595902 commit d8c5dfe

2 files changed

Lines changed: 16 additions & 17 deletions

File tree

packages/client-utils/src/mappers/helpers/caip.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { toChecksumHexAddress } from '@metamask/controller-utils';
22
// @ts-expect-error: No type definitions for '@metamask/slip44'
3-
import slip44 from '@metamask/slip44';
3+
import slip44data from '@metamask/slip44';
44
import type { CaipAssetType, CaipChainId, Hex } from '@metamask/utils';
55
import {
66
isCaipAssetType,
@@ -13,11 +13,11 @@ import { getChainById } from 'eth-chainlist';
1313

1414
import { nativeTokenAddress } from '../constants.js';
1515

16-
const slip44CoinTypeBySymbol = ((): Map<string, string> => {
16+
const slip44BySymbol = ((): Map<string, string> => {
1717
const coinTypeBySymbol = new Map<string, string>();
1818

1919
for (const [coinType, entry] of Object.entries(
20-
slip44 as Record<string, { symbol: string }>,
20+
slip44data as Record<string, { symbol: string }>,
2121
)) {
2222
const normalizedSymbol = entry.symbol.toUpperCase();
2323

@@ -26,14 +26,13 @@ const slip44CoinTypeBySymbol = ((): Map<string, string> => {
2626
}
2727
}
2828

29-
// Polygon rebrand: POL shares MATIC's slip44 coin type.
3029
coinTypeBySymbol.set('POL', coinTypeBySymbol.get('MATIC') as string);
3130

3231
return coinTypeBySymbol;
3332
})();
3433

35-
function slip44CoinTypeForSymbol(symbol: string): string | undefined {
36-
return slip44CoinTypeBySymbol.get(symbol.toUpperCase());
34+
function getCoinType(symbol: string): string | undefined {
35+
return slip44BySymbol.get(symbol.toUpperCase());
3736
}
3837

3938
/**
@@ -81,7 +80,7 @@ export function resolveNativeAssetId(
8180
return undefined;
8281
}
8382

84-
const coinType = slip44CoinTypeForSymbol(symbol);
83+
const coinType = getCoinType(symbol);
8584

8685
if (!coinType) {
8786
return undefined;
@@ -109,15 +108,15 @@ export function getNativeAsset(chainId: CaipChainId):
109108
return undefined;
110109
}
111110

112-
const { nativeCurrency, slip44: slip44AssetReference } = chain;
111+
const { nativeCurrency, slip44 } = chain;
113112
if (!nativeCurrency?.symbol) {
114113
return undefined;
115114
}
116115

117116
const assetReference =
118-
typeof slip44AssetReference === 'number'
119-
? `${slip44AssetReference}`
120-
: slip44CoinTypeForSymbol(nativeCurrency.symbol);
117+
typeof slip44 === 'number'
118+
? String(slip44)
119+
: getCoinType(nativeCurrency.symbol);
121120

122121
if (!assetReference) {
123122
return undefined;

packages/client-utils/src/mappers/helpers/transactions.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export type TransactionGroup = {
3838

3939
const nativeTokenDecimals = 18;
4040

41-
function toNetworkFeeAmount(
41+
function calculateNetworkFee(
4242
gasUsed: string | number | undefined,
4343
gasPrice: string | number | undefined,
4444
): string | undefined {
@@ -53,7 +53,7 @@ function toNetworkFeeAmount(
5353
}
5454
}
5555

56-
function buildBaseNetworkFee(
56+
function toNetworkFee(
5757
amount: string,
5858
chainId: CaipChainId,
5959
symbol?: string,
@@ -104,7 +104,7 @@ function getNetworkFee(
104104
return undefined;
105105
}
106106

107-
const amount = toNetworkFeeAmount(
107+
const amount = calculateNetworkFee(
108108
transaction.gasUsed,
109109
transaction.effectiveGasPrice,
110110
);
@@ -113,7 +113,7 @@ function getNetworkFee(
113113
return undefined;
114114
}
115115

116-
return buildBaseNetworkFee(amount, chainId);
116+
return toNetworkFee(amount, chainId);
117117
}
118118

119119
export function getFees(
@@ -136,7 +136,7 @@ export function getLocalTransactionFees(
136136
return undefined;
137137
}
138138

139-
const amount = toNetworkFeeAmount(
139+
const amount = calculateNetworkFee(
140140
primaryTransaction.txReceipt?.gasUsed,
141141
primaryTransaction.txReceipt?.effectiveGasPrice ??
142142
primaryTransaction.txParams?.gasPrice,
@@ -146,7 +146,7 @@ export function getLocalTransactionFees(
146146
return undefined;
147147
}
148148

149-
return [buildBaseNetworkFee(amount, chainId, nativeAssetSymbol)];
149+
return [toNetworkFee(amount, chainId, nativeAssetSymbol)];
150150
}
151151

152152
const inProgressTransactionStatuses = [

0 commit comments

Comments
 (0)