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: add nano contract feature toggle #441

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ export const types = {
NETWORKSETTINGS_UPDATE_INVALID: 'NETWORKSETTINGS_UPDATE_INVALID',
/* It indicates the update request has failed. */
NETWORKSETTINGS_UPDATE_FAILURE: 'NETWORK_SETTINGS_UPDATE_FAILURE',
/* It updates the redux state of network settings status */
/* It updates the redux state of network settings status. */
NETWORKSETTINGS_UPDATE_READY: 'NETWORK_SETTINGS_UPDATE_READY',
/* It sets the availability of Nano Contract's feature toggle. */
NANOCONTRACT_FEATURETOGGLE_SET_AVAILABILITY: 'NANOCONTRACT_FEATURETOGGLE_SET_AVAILABILITY',
};

export const featureToggleInitialized = () => ({
Expand Down Expand Up @@ -975,3 +977,11 @@ export const networkSettingsUpdateInvalid = (errors) => ({
export const networkSettingsUpdateReady = () => ({
type: types.NETWORKSETTINGS_UPDATE_READY,
});

/**
* @param {boolean} payload - true if unleash enables the nano contract feature
*/
export const setNanoContractAvailability = (payload) => ({
type: types.NANOCONTRACT_FEATURETOGGLE_SET_AVAILABILITY,
payload,
});
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export const WALLET_SERVICE_FEATURE_TOGGLE = 'wallet-service-mobile.rollout';
export const PUSH_NOTIFICATION_FEATURE_TOGGLE = 'push-notification.rollout';
export const WALLET_CONNECT_FEATURE_TOGGLE = 'wallet-connect-mobile.rollout';
export const NETWORK_SETTINGS_FEATURE_TOGGLE = 'network-settings.rollout';
export const NANO_CONTRACT_FEATURE_TOGGLE = 'nano-contract.rollout';

/**
* Default feature toggle values.
Expand All @@ -172,6 +173,7 @@ export const FEATURE_TOGGLE_DEFAULTS = {
[PUSH_NOTIFICATION_FEATURE_TOGGLE]: false,
[WALLET_CONNECT_FEATURE_TOGGLE]: false,
[NETWORK_SETTINGS_FEATURE_TOGGLE]: false,
[NANO_CONTRACT_FEATURE_TOGGLE]: false,
};

// Project id configured in https://walletconnect.com
Expand Down
21 changes: 21 additions & 0 deletions src/reducers/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ const initialState = {
networkSettings: PRE_SETTINGS_MAINNET,
networkSettingsInvalid: {},
networkSettingsStatus: NETWORKSETTINGS_STATUS.READY,
nanoContract: {
/**
* @property {boolean}
* @description Reflects Nano Contract's unleash feature toggle value.
*/
available: false,
pedroferreira1 marked this conversation as resolved.
Show resolved Hide resolved
},
};

export const reducer = (state = initialState, action) => {
Expand Down Expand Up @@ -386,6 +393,8 @@ export const reducer = (state = initialState, action) => {
return onNetworkSettingsUpdateFailure(state);
case types.NETWORKSETTINGS_UPDATE_INVALID:
return onNetworkSettingsUpdateInvalid(state, action);
case types.NANOCONTRACT_FEATURETOGGLE_SET_AVAILABILITY:
return onNanoContractFeatureToggleAvailability(state, action);
default:
return state;
}
Expand Down Expand Up @@ -1210,3 +1219,15 @@ export const onNetworkSettingsUpdateInvalid = (state, { payload }) => ({
networkSettingsInvalid: payload,
networkSettingsStatus: NETWORKSETTINGS_STATUS.READY,
});

/**
* @param {Object} state Redux state
* @param {{ payload: boolean }} Nano Contract unleash feature toggle value
*/
export const onNanoContractFeatureToggleAvailability = (state, { payload }) => ({
...state,
nanoContract: {
...state.nanoContract,
available: payload,
},
});
14 changes: 14 additions & 0 deletions src/sagas/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
DEFAULT_TOKEN,
WALLET_SERVICE_FEATURE_TOGGLE,
PUSH_NOTIFICATION_FEATURE_TOGGLE,
NANO_CONTRACT_FEATURE_TOGGLE,
} from '../constants';
import { STORE } from '../store';
import {
Expand Down Expand Up @@ -63,6 +64,7 @@ import {
resetWalletSuccess,
setTokens,
onExceptionCaptured,
setNanoContractAvailability,
} from '../actions';
import { fetchTokenData } from './tokens';
import {
Expand Down Expand Up @@ -96,6 +98,16 @@ export function* isPushNotificationEnabled() {
return pushEnabled;
}

/**
* Returns the value of the NANO_CONTRACT_FEATURE_TOGGLE feature flag
* @returns {Generator<unknown, boolean>}
*/
export function* isNanoContractEnabled() {
const nanoEnabled = yield call(checkForFeatureFlag, NANO_CONTRACT_FEATURE_TOGGLE);

return nanoEnabled;
}

/**
* Returns a boolean indicating if we should use the wallet-service
* @returns {Generator<unknown, boolean>}
Expand Down Expand Up @@ -133,9 +145,11 @@ export function* startWallet(action) {
const uniqueDeviceId = getUniqueId();
const useWalletService = yield call(isWalletServiceEnabled);
const usePushNotification = yield call(isPushNotificationEnabled);
const useNanoContract = yield call(isNanoContractEnabled);

yield put(setUseWalletService(useWalletService));
yield put(setAvailablePushNotification(usePushNotification));
yield put(setNanoContractAvailability(useNanoContract));

// clean storage and metadata before starting the wallet
// this should be cleaned when stopping the wallet,
Expand Down
Loading