Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/preferences controller smart tx opt in #3815

Merged
merged 8 commits into from
May 22, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('PreferencesController', () => {
acc[curr] = true;
return acc;
}, {} as { [chainId in EtherscanSupportedHexChainId]: boolean }),
smartTransactionsOptInStatus: false,
infiniteflower marked this conversation as resolved.
Show resolved Hide resolved
});
});

Expand Down Expand Up @@ -415,6 +416,12 @@ describe('PreferencesController', () => {
controller.setEnableNetworkIncomingTransactions('0x1', false);
expect(controller.state.showIncomingTransactions['0x1']).toBe(false);
});

it('should set smartTransactionsOptInStatus', () => {
const controller = setupPreferencesController();
controller.setSmartTransactionsOptInStatus(true);
expect(controller.state.smartTransactionsOptInStatus).toBe(true);
});
});

/**
Expand Down
17 changes: 17 additions & 0 deletions packages/preferences-controller/src/PreferencesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ export type PreferencesState = {
* Controls whether token detection is enabled
*/
useTokenDetection: boolean;
/**
* Controls whether smart transactions are opted into
*/
smartTransactionsOptInStatus: boolean;
};

const metadata = {
Expand All @@ -125,6 +129,7 @@ const metadata = {
showIncomingTransactions: { persist: true, anonymous: true },
useNftDetection: { persist: true, anonymous: true },
useTokenDetection: { persist: true, anonymous: true },
smartTransactionsOptInStatus: { persist: true, anonymous: true },
infiniteflower marked this conversation as resolved.
Show resolved Hide resolved
};

const name = 'PreferencesController';
Expand Down Expand Up @@ -197,6 +202,7 @@ export function getDefaultPreferencesState() {
showTestNetworks: false,
useNftDetection: false,
useTokenDetection: true,
smartTransactionsOptInStatus: false,
};
}

Expand Down Expand Up @@ -497,6 +503,17 @@ export class PreferencesController extends BaseController<
});
}
}

/**
* A setter for the user to opt into smart transactions
*
* @param smartTransactionsOptInStatus - true to opt into smart transactions
*/
setSmartTransactionsOptInStatus(smartTransactionsOptInStatus: boolean) {
infiniteflower marked this conversation as resolved.
Show resolved Hide resolved
this.update((state) => {
state.smartTransactionsOptInStatus = smartTransactionsOptInStatus;
});
}
}

export default PreferencesController;
Loading