Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into cryptodev2s/migrat…
Browse files Browse the repository at this point in the history
…e-app-state-controller-to-base-controller-v2
  • Loading branch information
cryptodev-2s committed Nov 29, 2024
2 parents 14ef9e0 + 7143c96 commit da09c89
Show file tree
Hide file tree
Showing 39 changed files with 392 additions and 287 deletions.
1 change: 0 additions & 1 deletion app/scripts/constants/sentry-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export const SENTRY_BACKGROUND_STATE = {
termsOfUseLastAgreed: true,
timeoutMinutes: true,
trezorModel: true,
usedNetworks: true,
},
MultichainBalancesController: {
balances: false,
Expand Down
12 changes: 0 additions & 12 deletions app/scripts/controllers/app-state-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,18 +352,6 @@ describe('AppStateController', () => {
});
});

describe('setFirstTimeUsedNetwork', () => {
it('updates the array of the first time used networks', async () => {
await withController(({ controller }) => {
const chainId = '0x1';

controller.setFirstTimeUsedNetwork(chainId);

expect(controller.state.usedNetworks[chainId]).toBe(true);
});
});
});

describe('setLastInteractedConfirmationInfo', () => {
it('sets information about last confirmation user has interacted with', async () => {
await withController(({ controller }) => {
Expand Down
30 changes: 3 additions & 27 deletions app/scripts/controllers/app-state-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export type AppStateControllerState = {
hadAdvancedGasFeesSetPriorToMigration92_3: boolean;
qrHardware: Json;
nftsDropdownState: Json;
usedNetworks: Record<string, boolean>;
surveyLinkLastClickedOrClosed: number | null;
signatureSecurityAlertResponses: Record<string, SecurityAlertResponse>;
// States used for displaying the changed network toast
Expand Down Expand Up @@ -147,11 +146,8 @@ type AppStateControllerInitState = Partial<
AppStateControllerState,
| 'qrHardware'
| 'nftsDropdownState'
| 'usedNetworks'
| 'surveyLinkLastClickedOrClosed'
| 'signatureSecurityAlertResponses'
| 'switchedNetworkDetails'
| 'switchedNetworkNeverShowMessage'
| 'currentExtensionPopupId'
>
>;
Expand Down Expand Up @@ -188,17 +184,12 @@ const getDefaultAppStateControllerState = (): AppStateControllerState => ({
newPrivacyPolicyToastClickedOrClosed: null,
newPrivacyPolicyToastShownDate: null,
hadAdvancedGasFeesSetPriorToMigration92_3: false,
usedNetworks: {
'0x1': true,
'0x5': true,
'0x539': true,
},
surveyLinkLastClickedOrClosed: null,
switchedNetworkNeverShowMessage: false,
...getDefaultOverrides(),
...getDefaultAppStateOverrides(),
});

function getDefaultOverrides() {
function getDefaultAppStateOverrides() {
return {
qrHardware: {},
nftsDropdownState: {},
Expand Down Expand Up @@ -309,10 +300,6 @@ const controllerMetadata = {
persist: false,
anonymous: true,
},
usedNetworks: {
persist: true,
anonymous: true,
},
surveyLinkLastClickedOrClosed: {
persist: true,
anonymous: true,
Expand Down Expand Up @@ -390,7 +377,7 @@ export class AppStateController extends BaseController<
state: {
...getDefaultAppStateControllerState(),
...state,
...getDefaultOverrides(),
...getDefaultAppStateOverrides(),
},
messenger,
});
Expand Down Expand Up @@ -884,17 +871,6 @@ export class AppStateController extends BaseController<
});
}

/**
* Updates the array of the first time used networks
*
* @param chainId
*/
setFirstTimeUsedNetwork(chainId: string): void {
this.update((state) => {
state.usedNetworks[chainId] = true;
});
}

///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
/**
* Set the interactive replacement token with a url and the old refresh token
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/controllers/mmi-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export class MMIController {
}
}

const txList = this.txStateManager.getTransactions({}, [], false); // Includes all transactions, but we are looping through keyrings. Currently filtering is done in updateCustodianTransactions :-/
const txList = this.txStateManager.getTransactions(); // Includes all transactions, but we are looping through keyrings. Currently filtering is done in updateCustodianTransactions :-/

try {
updateCustodianTransactions({
Expand Down
1 change: 1 addition & 0 deletions app/scripts/lib/transaction/metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ describe('Transaction metrics', () => {
type: TransactionType.simpleSend,
origin: ORIGIN_METAMASK,
chainId: mockChainId,
networkClientId: 'testNetworkClientId',
time: 1624408066355,
defaultGasEstimates: {
gas: '0x7b0d',
Expand Down
1 change: 1 addition & 0 deletions app/scripts/lib/transaction/smart-transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ function withRequest<ReturnValue>(
},
type: TransactionType.simpleSend,
chainId: CHAIN_IDS.MAINNET,
networkClientId: 'testNetworkClientId',
time: 1624408066355,
defaultGasEstimates: {
gas: '0x7b0d',
Expand Down
39 changes: 1 addition & 38 deletions app/scripts/lib/transaction/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const TRANSACTION_PARAMS_MOCK: TransactionParams = {

const TRANSACTION_OPTIONS_MOCK: AddTransactionOptions = {
actionId: 'mockActionId',
networkClientId: 'mockNetworkClientId',
origin: 'mockOrigin',
requireApproval: false,
type: TransactionType.simpleSend,
Expand Down Expand Up @@ -151,23 +152,6 @@ describe('Transaction Utils', () => {
});
});

it('adds transaction with networkClientId if process.env.TRANSACTION_MULTICHAIN is set', async () => {
process.env.TRANSACTION_MULTICHAIN = '1';

await addTransaction(request);

expect(
request.transactionController.addTransaction,
).toHaveBeenCalledTimes(1);
expect(
request.transactionController.addTransaction,
).toHaveBeenCalledWith(TRANSACTION_PARAMS_MOCK, {
...TRANSACTION_OPTIONS_MOCK,
networkClientId: 'mockNetworkClientId',
});
process.env.TRANSACTION_MULTICHAIN = '';
});

it('returns transaction meta', async () => {
const transactionMeta = await addTransaction(request);
expect(transactionMeta).toStrictEqual(TRANSACTION_META_MOCK);
Expand Down Expand Up @@ -541,27 +525,6 @@ describe('Transaction Utils', () => {
});
});

it('adds transaction with networkClientId if process.env.TRANSACTION_MULTICHAIN is set', async () => {
process.env.TRANSACTION_MULTICHAIN = '1';

await addDappTransaction(dappRequest);

expect(
request.transactionController.addTransaction,
).toHaveBeenCalledTimes(1);
expect(
request.transactionController.addTransaction,
).toHaveBeenCalledWith(TRANSACTION_PARAMS_MOCK, {
...TRANSACTION_OPTIONS_MOCK,
networkClientId: 'mockNetworkClientId',
method: DAPP_REQUEST_MOCK.method,
requireApproval: true,
securityAlertResponse: DAPP_REQUEST_MOCK.securityAlertResponse,
type: undefined,
});
process.env.TRANSACTION_MULTICHAIN = '';
});

it('returns transaction hash', async () => {
const transactionHash = await addDappTransaction(dappRequest);
expect(transactionHash).toStrictEqual(TRANSACTION_META_MOCK.hash);
Expand Down
7 changes: 4 additions & 3 deletions app/scripts/lib/transaction/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type BaseAddTransactionRequest = {
};

type FinalAddTransactionRequest = BaseAddTransactionRequest & {
transactionOptions: AddTransactionOptions;
transactionOptions: Partial<AddTransactionOptions>;
};

export type AddTransactionRequest = FinalAddTransactionRequest & {
Expand All @@ -66,7 +66,7 @@ export async function addDappTransaction(
const { id: actionId, method, origin } = dappRequest;
const { securityAlertResponse, traceContext } = dappRequest;

const transactionOptions: AddTransactionOptions = {
const transactionOptions: Partial<AddTransactionOptions> = {
actionId,
method,
origin,
Expand Down Expand Up @@ -143,10 +143,11 @@ async function addTransactionWithController(
transactionParams,
networkClientId,
} = request;

const { result, transactionMeta } =
await transactionController.addTransaction(transactionParams, {
...transactionOptions,
...(process.env.TRANSACTION_MULTICHAIN ? { networkClientId } : {}),
networkClientId,
});

return {
Expand Down
Loading

0 comments on commit da09c89

Please sign in to comment.