Skip to content

Commit 55fc96e

Browse files
committed
Linter fixes
1 parent c44c94b commit 55fc96e

File tree

4 files changed

+39
-28
lines changed

4 files changed

+39
-28
lines changed

shared/types/store.ts

Whitespace-only changes.

ui/helpers/utils/token-util.ts

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import log from 'loglevel';
2+
import { TransactionDescription } from '@ethersproject/abi';
3+
import { Nft, NftContract, Token } from '@metamask/assets-controllers';
24
import { getTokenStandardAndDetails } from '../../store/actions';
35
import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils';
46
import { parseStandardTokenTransactionData } from '../../../shared/modules/transaction.utils';
@@ -8,8 +10,6 @@ import { calcTokenAmount } from '../../../shared/lib/transactions-controller-uti
810
import { Numeric } from '../../../shared/modules/Numeric';
911
import * as util from './util';
1012
import { formatCurrency } from './confirm-tx.util';
11-
import { Nft, NftContract, Token } from '@metamask/assets-controllers';
12-
import { TransactionDescription } from '@ethersproject/abi';
1313

1414
const DEFAULT_SYMBOL = '';
1515

@@ -160,34 +160,41 @@ export function tokenInfoGetter() {
160160
* Attempts to get the address parameter of the given token transaction data
161161
* (i.e. function call) per the Human Standard Token ABI, in the following
162162
* order:
163-
* - The '_to' parameter, if present
164-
* - The first parameter, if present
163+
* - The '_to' parameter, if present
164+
* - The first parameter, if present
165165
*
166-
* @param {object} tokenData - ethers Interface token data.
167-
* @returns {string | undefined} A lowercase address string.
166+
* @param tokenData - ethers Interface token data.
167+
* @returns A lowercase address string or undefined.
168168
*/
169169
export function getTokenAddressParam(
170170
tokenData: Partial<TransactionDescription> = {},
171171
) {
172-
const value =
173-
tokenData?.args?._to || tokenData?.args?.to || tokenData?.args?.[0];
172+
const { args = [] } = tokenData;
173+
let value: unknown;
174+
if ('_to' in args) {
175+
value = args._to;
176+
} else if ('to' in args) {
177+
value = args.to;
178+
} else if (Array.isArray(args)) {
179+
value = args[0];
180+
}
174181
return value?.toString().toLowerCase();
175182
}
176183

177184
/**
178185
* Gets the '_value' parameter of the given token transaction data
179186
* (i.e function call) per the Human Standard Token ABI, if present.
180187
*
181-
* @param {object} tokenData - ethers Interface token data.
182-
* @returns {string | undefined} A decimal string value.
188+
* @param tokenData - ethers Interface token data.
189+
* @returns A decimal string value or undefined.
183190
*/
184191
/**
185192
* Gets either the '_tokenId' parameter or the 'id' param of the passed token transaction data.,
186193
* These are the parsed tokenId values returned by `parseStandardTokenTransactionData` as defined
187194
* in the ERC721 and ERC1155 ABIs from metamask-eth-abis (https://github.com/MetaMask/metamask-eth-abis/tree/main/src/abis)
188195
*
189-
* @param {object} tokenData - ethers Interface token data.
190-
* @returns {string | undefined} A decimal string value.
196+
* @param tokenData - ethers Interface token data.
197+
* @returns A decimal string value or undefined.
191198
*/
192199
export function getTokenIdParam(
193200
tokenData: Partial<TransactionDescription> = {},
@@ -201,26 +208,30 @@ export function getTokenIdParam(
201208
* Gets the '_approved' parameter of the given token transaction data
202209
* (i.e function call) per the Human Standard Token ABI, if present.
203210
*
204-
* @param {object} tokenData - ethers Interface token data.
205-
* @returns {boolean | undefined} A boolean indicating whether the function is being called to approve or revoke access.
211+
* @param tokenData - ethers Interface token data.
212+
* @returns A boolean indicating whether the function is being called to approve or revoke access, or undefined if the '_approved` parameter is not present.
206213
*/
207214
export function getTokenApprovedParam(
208215
tokenData: Partial<TransactionDescription> = {},
209216
) {
210-
return tokenData?.args?._approved;
217+
const { args = {} } = tokenData;
218+
if (!('_approved' in args)) {
219+
return undefined;
220+
}
221+
return Boolean(args._approved);
211222
}
212223

213224
/**
214225
* Get the token balance converted to fiat and optionally formatted for display
215226
*
216-
* @param {number | string} [contractExchangeRate] - The exchange rate between the current token and the native currency
217-
* @param {number} conversionRate - The exchange rate between the current fiat currency and the native currency
218-
* @param {string} currentCurrency - The currency code for the user's chosen fiat currency
219-
* @param {string} [tokenAmount] - The current token balance
220-
* @param {string} [tokenSymbol] - The token symbol
221-
* @param {boolean} [formatted] - Whether the return value should be formatted or not
222-
* @param {boolean} [hideCurrencySymbol] - excludes the currency symbol in the result if true
223-
* @returns {string|undefined} The token amount in the user's chosen fiat currency, optionally formatted and localize
227+
* @param [contractExchangeRate] - The exchange rate between the current token and the native currency
228+
* @param conversionRate - The exchange rate between the current fiat currency and the native currency
229+
* @param currentCurrency - The currency code for the user's chosen fiat currency
230+
* @param [tokenAmount] - The current token balance
231+
* @param [tokenSymbol] - The token symbol
232+
* @param [formatted] - Whether the return value should be formatted or not
233+
* @param [hideCurrencySymbol] - excludes the currency symbol in the result if true
234+
* @returns The token amount in the user's chosen fiat currency, optionally formatted and localize, or undefined
224235
*/
225236
export function getTokenFiatAmount(
226237
contractExchangeRate: number | string,

ui/selectors/first-time-flow.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export type OnboardingState =
1515
* When the user unlocks the wallet but onboarding has not fully completed we
1616
* must direct the user to the appropriate step in the onboarding process.
1717
*
18-
* @param {object} state - MetaMask state tree
19-
* @returns {string} Route to redirect the user to
18+
* @param state - MetaMask state tree
19+
* @returns Route to redirect the user to
2020
*/
2121
export function getFirstTimeFlowTypeRouteAfterUnlock(state: OnboardingState) {
2222
const { firstTimeFlowType } = state.metamask.OnboardingController;
@@ -40,8 +40,8 @@ export function getFirstTimeFlowTypeRouteAfterUnlock(state: OnboardingState) {
4040
* restore option because the restore option is atypical from the other two
4141
* options and removes an entire screen from the onboarding flow.
4242
*
43-
* @param {object} state - MetaMask state tree
44-
* @returns {string} Route to redirect the user to
43+
* @param state - MetaMask state tree
44+
* @returns Route to redirect the user to
4545
*/
4646
export function getFirstTimeFlowTypeRouteAfterMetaMetricsOptIn(
4747
state: OnboardingState,

ui/selectors/institutional/selectors.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Hex } from '@metamask/utils';
55
import { toHex } from '@metamask/controller-utils';
66
import { InternalAccountWithBalance } from '../selectors.types';
77
import { MetaMaskReduxState } from '../../store/store';
8+
import { BackgroundStateProxy } from '../../../shared/types/metamask';
89
import { ETH_EOA_METHODS } from '../../../shared/constants/eth-methods';
910
import { mockNetworkState } from '../../../test/stub/networks';
1011
import {
@@ -33,7 +34,6 @@ import {
3334
getNoteToTraderMessage,
3435
getIsNoteToTraderSupported,
3536
} from './selectors';
36-
import { BackgroundStateProxy } from '../../../shared/types/metamask';
3737

3838
const custodianMock = {
3939
type: 'saturn',

0 commit comments

Comments
 (0)