Skip to content

Commit 311f683

Browse files
committed
chore: unnecessary if
1 parent f85570e commit 311f683

File tree

7 files changed

+78
-84
lines changed

7 files changed

+78
-84
lines changed

app/scripts/background.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,12 @@ function maybeDetectPhishing(theController) {
339339
}
340340

341341
const { hostname, href, searchParams } = new URL(details.url);
342-
if (inTest) {
343-
if (searchParams.has('IN_TEST_BYPASS_EARLY_PHISHING_DETECTION')) {
344-
// this is a test page that needs to bypass early phishing detection
345-
return {};
346-
}
342+
if (
343+
inTest &&
344+
searchParams.has('IN_TEST_BYPASS_EARLY_PHISHING_DETECTION')
345+
) {
346+
// this is a test page that needs to bypass early phishing detection
347+
return {};
347348
}
348349

349350
theController.phishingController.maybeUpdateState();

app/scripts/controllers/app-state-controller.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,11 +1033,10 @@ export class AppStateController extends BaseController<
10331033
): void {
10341034
if (
10351035
pollingTokenType.toString() !==
1036-
POLLING_TOKEN_ENVIRONMENT_TYPES[ENVIRONMENT_TYPE_BACKGROUND]
1036+
POLLING_TOKEN_ENVIRONMENT_TYPES[ENVIRONMENT_TYPE_BACKGROUND] &&
1037+
this.#isValidPollingTokenType(pollingTokenType)
10371038
) {
1038-
if (this.#isValidPollingTokenType(pollingTokenType)) {
1039-
this.#updatePollingTokens(pollingToken, pollingTokenType);
1040-
}
1039+
this.#updatePollingTokens(pollingToken, pollingTokenType);
10411040
}
10421041
}
10431042

app/scripts/services/subscription/subscription-service.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,17 @@ export class SubscriptionService {
137137
changeInfo: { url: string },
138138
) => {
139139
// We only care about updates to our specific checkout tab
140-
if (tabId === openedTab.id && changeInfo.url) {
141-
if (changeInfo.url.startsWith(params.successUrl)) {
142-
// Payment was successful!
143-
succeeded = true;
144-
145-
// Clean up: close the tab
146-
this.#platform.closeTab(tabId);
147-
}
148-
// TODO: handle cancel url ?
140+
if (
141+
tabId === openedTab.id &&
142+
changeInfo.url?.startsWith(params.successUrl)
143+
) {
144+
// Payment was successful!
145+
succeeded = true;
146+
147+
// Clean up: close the tab
148+
this.#platform.closeTab(tabId);
149149
}
150+
// TODO: handle cancel url ?
150151
};
151152
this.#platform.addTabUpdatedListener(onTabUpdatedListener);
152153

app/scripts/streams/provider-stream.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,13 @@ function getNotificationTransformStream() {
314314
highWaterMark: 16,
315315
objectMode: true,
316316
transform: (chunk, _, cb) => {
317-
if (chunk?.name === METAMASK_EIP_1193_PROVIDER) {
318-
if (chunk.data?.method === 'metamask_accountsChanged') {
319-
chunk.data.method = 'wallet_accountsChanged';
320-
chunk.data.result = chunk.data.params;
321-
delete chunk.data.params;
322-
}
317+
if (
318+
chunk?.name === METAMASK_EIP_1193_PROVIDER &&
319+
chunk.data?.method === 'metamask_accountsChanged'
320+
) {
321+
chunk.data.method = 'wallet_accountsChanged';
322+
chunk.data.result = chunk.data.params;
323+
delete chunk.data.params;
323324
}
324325
cb(null, chunk);
325326
},

test/e2e/api-specs/MultichainAuthorizationConfirmationErrors.ts

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -77,55 +77,53 @@ export class MultichainAuthorizationConfirmationErrors implements Rule {
7777
getCalls(__: unknown, method: MethodObject) {
7878
const calls: Call[] = [];
7979
const isMethodAllowed = this.only ? this.only.includes(method.name) : true;
80-
if (isMethodAllowed) {
81-
if (method.errors) {
82-
method.errors.forEach((err) => {
83-
const unsupportedErrorCodes = [5000, 5100, 5101, 5102, 5300, 5301];
84-
const error = err as ErrorObject;
85-
if (unsupportedErrorCodes.includes(error.code)) {
86-
return;
87-
}
88-
let params: Record<string, unknown> = {};
89-
switch (error.code) {
90-
case 5100:
91-
params = {
92-
requiredScopes: {
93-
'eip155:10124': {
94-
methods: ['eth_signTypedData_v4'],
95-
notifications: [],
96-
},
80+
if (isMethodAllowed && method.errors) {
81+
method.errors.forEach((err) => {
82+
const unsupportedErrorCodes = [5000, 5100, 5101, 5102, 5300, 5301];
83+
const error = err as ErrorObject;
84+
if (unsupportedErrorCodes.includes(error.code)) {
85+
return;
86+
}
87+
let params: Record<string, unknown> = {};
88+
switch (error.code) {
89+
case 5100:
90+
params = {
91+
requiredScopes: {
92+
'eip155:10124': {
93+
methods: ['eth_signTypedData_v4'],
94+
notifications: [],
9795
},
98-
};
99-
break;
100-
case 5302:
101-
params = {
102-
requiredScopes: {
103-
'eip155:1': {
104-
methods: ['eth_signTypedData_v4'],
105-
notifications: [],
106-
},
96+
},
97+
};
98+
break;
99+
case 5302:
100+
params = {
101+
requiredScopes: {
102+
'eip155:1': {
103+
methods: ['eth_signTypedData_v4'],
104+
notifications: [],
107105
},
108-
sessionProperties: {},
109-
};
110-
break;
111-
default:
112-
break;
113-
}
106+
},
107+
sessionProperties: {},
108+
};
109+
break;
110+
default:
111+
break;
112+
}
114113

115-
// params should make error happen (or lifecycle hooks will make it happen)
116-
calls.push({
117-
title: `${this.getTitle()} - with error ${error.code} ${
118-
error.message
119-
} `,
120-
methodName: method.name,
121-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
122-
params: params as any,
123-
url: '',
124-
resultSchema: (method.result as ContentDescriptorObject).schema,
125-
expectedResult: error,
126-
});
114+
// params should make error happen (or lifecycle hooks will make it happen)
115+
calls.push({
116+
title: `${this.getTitle()} - with error ${error.code} ${
117+
error.message
118+
} `,
119+
methodName: method.name,
120+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
121+
params: params as any,
122+
url: '',
123+
resultSchema: (method.result as ContentDescriptorObject).schema,
124+
expectedResult: error,
127125
});
128-
}
126+
});
129127
}
130128
return calls;
131129
}

ui/components/multichain/asset-picker-amount/asset-picker/asset-picker.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,12 @@ export function AssetPicker({
196196
// If there is only 1 selected network switch to that network to populate tokens
197197
if (
198198
chainIds.length === 1 &&
199-
chainIds[0] !== currentNetworkProviderConfig?.chainId
199+
chainIds[0] !== currentNetworkProviderConfig?.chainId &&
200+
networkProps?.onNetworkChange
200201
) {
201-
if (networkProps?.onNetworkChange) {
202-
networkProps.onNetworkChange(
203-
allNetworks[chainIds[0] as keyof typeof allNetworks],
204-
);
205-
}
202+
networkProps.onNetworkChange(
203+
allNetworks[chainIds[0] as keyof typeof allNetworks],
204+
);
206205
}
207206
}}
208207
selectedChainIds={selectedChainIds}

ui/selectors/selectors.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3913,16 +3913,11 @@ export function getAccountToConnectToActiveTab(state) {
39133913
const numberOfAccounts = Object.keys(accounts).length;
39143914

39153915
if (
3916-
connectedAccounts.length &&
3917-
connectedAccounts.length !== numberOfAccounts
3916+
connectedAccounts.length > 0 &&
3917+
connectedAccounts.length !== numberOfAccounts &&
3918+
connectedAccounts.includes(selectedInternalAccount.address)
39183919
) {
3919-
if (
3920-
connectedAccounts.findIndex(
3921-
(address) => address === selectedInternalAccount.address,
3922-
) === -1
3923-
) {
3924-
return getInternalAccount(state, selectedInternalAccount.id);
3925-
}
3920+
return getInternalAccount(state, selectedInternalAccount.id);
39263921
}
39273922

39283923
return undefined;

0 commit comments

Comments
 (0)