Skip to content

Commit 7e1a561

Browse files
committed
feat: add toast after edit
1 parent 5196425 commit 7e1a561

File tree

10 files changed

+98
-0
lines changed

10 files changed

+98
-0
lines changed

app/_locales/en/messages.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/ducks/app/app.ts

+9
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ type AppState = {
8080
newNftAddedMessage: string;
8181
removeNftMessage: string;
8282
newNetworkAddedName: string;
83+
editedNetwork: string;
8384
newNetworkAddedConfigurationId: string;
8485
selectedNetworkConfigurationId: string;
8586
sendInputCurrencySwitched: boolean;
@@ -158,6 +159,7 @@ const initialState: AppState = {
158159
newNftAddedMessage: '',
159160
removeNftMessage: '',
160161
newNetworkAddedName: '',
162+
editedNetwork: '',
161163
newNetworkAddedConfigurationId: '',
162164
selectedNetworkConfigurationId: '',
163165
sendInputCurrencySwitched: false,
@@ -467,6 +469,13 @@ export default function reduceApp(
467469
newNetworkAddedConfigurationId: networkConfigurationId,
468470
};
469471
}
472+
case actionConstants.SET_EDIT_NETWORK: {
473+
const { nickname } = action.payload;
474+
return {
475+
...appState,
476+
editedNetwork: nickname,
477+
};
478+
}
470479
case actionConstants.SET_NEW_TOKENS_IMPORTED:
471480
return {
472481
...appState,

ui/pages/home/home.component.js

+26
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ export default class Home extends PureComponent {
164164
showOutdatedBrowserWarning: PropTypes.bool.isRequired,
165165
setOutdatedBrowserWarningLastShown: PropTypes.func.isRequired,
166166
newNetworkAddedName: PropTypes.string,
167+
editedNetwork: PropTypes.string,
167168
// This prop is used in the `shouldCloseNotificationPopup` function
168169
// eslint-disable-next-line react/no-unused-prop-types
169170
isSigningQRHardwareTransaction: PropTypes.bool.isRequired,
@@ -177,6 +178,7 @@ export default class Home extends PureComponent {
177178
setNewTokensImported: PropTypes.func.isRequired,
178179
setNewTokensImportedError: PropTypes.func.isRequired,
179180
clearNewNetworkAdded: PropTypes.func,
181+
clearEditedNetwork: PropTypes.func,
180182
setActiveNetwork: PropTypes.func,
181183
// eslint-disable-next-line react/no-unused-prop-types
182184
setTokenAutodetectModal: PropTypes.func,
@@ -450,6 +452,7 @@ export default class Home extends PureComponent {
450452
newNftAddedMessage,
451453
setNewNftAddedMessage,
452454
newNetworkAddedName,
455+
editedNetwork,
453456
removeNftMessage,
454457
setRemoveNftMessage,
455458
newTokensImported,
@@ -458,6 +461,7 @@ export default class Home extends PureComponent {
458461
setNewTokensImportedError,
459462
newNetworkAddedConfigurationId,
460463
clearNewNetworkAdded,
464+
clearEditedNetwork,
461465
setActiveNetwork,
462466
} = this.props;
463467

@@ -572,6 +576,28 @@ export default class Home extends PureComponent {
572576
}
573577
/>
574578
) : null}
579+
{console.log('IM HERE ***********', editedNetwork)}
580+
{editedNetwork ? (
581+
<ActionableMessage
582+
type="success"
583+
className="home__new-network-notification"
584+
message={
585+
<Box display={Display.InlineFlex}>
586+
<i className="fa fa-check-circle home__new-network-notification-icon" />
587+
<Text variant={TextVariant.bodySm} as="h6">
588+
{t('newNetworkEdited', [editedNetwork])}
589+
</Text>
590+
<ButtonIcon
591+
iconName={IconName.Close}
592+
size={ButtonIconSize.Sm}
593+
ariaLabel={t('close')}
594+
onClick={() => clearEditedNetwork()}
595+
className="home__new-network-notification-close"
596+
/>
597+
</Box>
598+
}
599+
/>
600+
) : null}
575601
{newTokensImported ? (
576602
<ActionableMessage
577603
type="success"

ui/pages/home/home.container.js

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
getNewTokensImportedError,
4747
hasPendingApprovals,
4848
getSelectedInternalAccount,
49+
getEditedNetwork,
4950
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
5051
getAccountType,
5152
///: END:ONLY_INCLUDE_IF
@@ -73,6 +74,7 @@ import {
7374
setNewTokensImportedError,
7475
setShowTokenAutodetectModal,
7576
setShowTokenAutodetectModalOnUpgrade,
77+
setEditedNetwork,
7678
} from '../../store/actions';
7779
import {
7880
hideWhatsNewPopup,
@@ -190,6 +192,7 @@ const mapStateToProps = (state) => {
190192
getIsBrowserDeprecated() && getShowOutdatedBrowserWarning(state),
191193
seedPhraseBackedUp,
192194
newNetworkAddedName: getNewNetworkAdded(state),
195+
editedNetwork: getEditedNetwork(state),
193196
isSigningQRHardwareTransaction: getIsSigningQRHardwareTransaction(state),
194197
newNftAddedMessage: getNewNftAddedMessage(state),
195198
removeNftMessage: getRemoveNftMessage(state),
@@ -256,6 +259,9 @@ const mapDispatchToProps = (dispatch) => {
256259
clearNewNetworkAdded: () => {
257260
dispatch(setNewNetworkAdded({}));
258261
},
262+
clearEditedNetwork: () => {
263+
dispatch(setEditedNetwork({}));
264+
},
259265
setActiveNetwork: (networkConfigurationId) => {
260266
dispatch(setActiveNetwork(networkConfigurationId));
261267
},

ui/pages/settings/networks-tab/networks-form/networks-form.js

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
import {
4848
editAndSetNetworkConfiguration,
4949
requestUserApproval,
50+
setEditedNetwork,
5051
setNewNetworkAdded,
5152
setSelectedNetworkConfigurationId,
5253
showDeprecatedNetworkModal,
@@ -855,6 +856,9 @@ const NetworksForm = ({
855856
token_symbol: ticker,
856857
},
857858
});
859+
if (networkMenuRedesign) {
860+
dispatch(setEditedNetwork({ nickname: networkName }));
861+
}
858862
}
859863

860864
if (

ui/selectors/selectors.js

+4
Original file line numberDiff line numberDiff line change
@@ -2009,6 +2009,10 @@ export function getNewNetworkAdded(state) {
20092009
return state.appState.newNetworkAddedName;
20102010
}
20112011

2012+
export function getEditedNetwork(state) {
2013+
return state.appState.editedNetwork;
2014+
}
2015+
20122016
export function getNetworksTabSelectedNetworkConfigurationId(state) {
20132017
return state.appState.selectedNetworkConfigurationId;
20142018
}

ui/selectors/selectors.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,20 @@ describe('Selectors', () => {
510510
});
511511
});
512512

513+
describe('#getEditedNetwork', () => {
514+
it('returns undefined if getEditedNetwork is undefined', () => {
515+
expect(selectors.getNewNetworkAdded({ appState: {} })).toBeUndefined();
516+
});
517+
518+
it('returns getEditedNetwork', () => {
519+
expect(
520+
selectors.getEditedNetwork({
521+
appState: { editedNetwork: 'test-chain' },
522+
}),
523+
).toStrictEqual('test-chain');
524+
});
525+
});
526+
513527
describe('#getRpcPrefsForCurrentProvider', () => {
514528
it('returns an empty object if state.metamask.providerConfig is empty', () => {
515529
expect(

ui/store/actionConstants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export const SET_SHOW_TOKEN_AUTO_DETECT_MODAL_UPGRADE =
107107
export const SET_SELECTED_NETWORK_CONFIGURATION_ID =
108108
'SET_SELECTED_NETWORK_CONFIGURATION_ID';
109109
export const SET_NEW_NETWORK_ADDED = 'SET_NEW_NETWORK_ADDED';
110+
export const SET_EDIT_NETWORK = 'SET_EDIT_NETWORK';
110111

111112
export const SET_NEW_NFT_ADDED_MESSAGE = 'SET_NEW_NFT_ADDED_MESSAGE';
112113
export const SET_REMOVE_NFT_MESSAGE = 'SET_REMOVE_NFT_MESSAGE';

ui/store/actions.test.js

+19
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,25 @@ describe('Actions', () => {
13891389
});
13901390
});
13911391

1392+
describe('#setEditedNetwork', () => {
1393+
it('sets appState.setEditedNetwork to provided value', async () => {
1394+
const store = mockStore();
1395+
1396+
const newNetworkAddedDetails = {
1397+
nickname: 'test-chain',
1398+
};
1399+
1400+
store.dispatch(actions.setEditedNetwork(newNetworkAddedDetails));
1401+
1402+
const resultantActions = store.getActions();
1403+
1404+
expect(resultantActions[0]).toStrictEqual({
1405+
type: 'SET_EDIT_NETWORK',
1406+
payload: newNetworkAddedDetails,
1407+
});
1408+
});
1409+
});
1410+
13921411
describe('#addToAddressBook', () => {
13931412
it('calls setAddressBook', async () => {
13941413
const store = mockStore();

ui/store/actions.ts

+12
Original file line numberDiff line numberDiff line change
@@ -4103,6 +4103,18 @@ export function setNewNetworkAdded({
41034103
};
41044104
}
41054105

4106+
export function setEditedNetwork({
4107+
nickname,
4108+
}: {
4109+
networkConfigurationId: string;
4110+
nickname: string;
4111+
}): PayloadAction<object> {
4112+
return {
4113+
type: actionConstants.SET_EDIT_NETWORK,
4114+
payload: { nickname },
4115+
};
4116+
}
4117+
41064118
export function setNewNftAddedMessage(
41074119
newNftAddedMessage: string,
41084120
): PayloadAction<string> {

0 commit comments

Comments
 (0)