Skip to content

Commit 108786f

Browse files
committed
Merge branch 'frontend-sync-manage-accounts'
2 parents 189909b + f05d800 commit 108786f

File tree

2 files changed

+15
-25
lines changed

2 files changed

+15
-25
lines changed

frontends/web/src/routes/router.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,13 @@ export const AppRouter = ({ devices, deviceIDs, devicesKey, accounts, activeAcco
202202
<Route path="device-settings/:deviceID" element={Device} />
203203
<Route path="advanced-settings" element={AdvancedSettingsEl} />
204204
<Route path="electrum" element={<ElectrumSettings />} />
205-
<Route path="manage-accounts" element={<ManageAccounts key={'manage-accounts'} deviceIDs={deviceIDs} hasAccounts={hasAccounts}/>} />
205+
<Route path="manage-accounts" element={
206+
<ManageAccounts
207+
accounts={accounts}
208+
key="manage-accounts"
209+
deviceIDs={deviceIDs}
210+
hasAccounts={hasAccounts} />
211+
} />
206212
</Route>
207213
</Route>
208214
</Routes>;

frontends/web/src/routes/settings/manage-accounts.tsx

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { WatchonlySetting } from './components/manage-accounts/watchonlySetting'
3636
import style from './manage-accounts.module.css';
3737

3838
interface ManageAccountsProps {
39+
accounts: accountAPI.IAccount[];
3940
deviceIDs: string[];
4041
hasAccounts: boolean;
4142
}
@@ -48,27 +49,17 @@ type TShowTokens = {
4849

4950
interface State {
5051
editErrorMessage?: string;
51-
accounts: accountAPI.IAccount[];
5252
showTokens: TShowTokens;
5353
currentlyEditedAccount?: accountAPI.IAccount;
5454
}
5555

5656
class ManageAccounts extends Component<Props, State> {
5757
public readonly state: State = {
5858
editErrorMessage: undefined,
59-
accounts: [],
6059
showTokens: {},
6160
currentlyEditedAccount: undefined,
6261
};
6362

64-
private fetchAccounts = () => {
65-
return accountAPI.getAccounts().then(accounts => this.setState({ accounts }));
66-
};
67-
68-
public componentDidMount() {
69-
this.fetchAccounts();
70-
}
71-
7263
private renderAccounts = (accounts: accountAPI.IAccount[]) => {
7364
const { showTokens } = this.state;
7465
const { t } = this.props;
@@ -155,9 +146,7 @@ class ManageAccounts extends Component<Props, State> {
155146

156147
private toggleAccount = (accountCode: string, active: boolean) => {
157148
return backendAPI.setAccountActive(accountCode, active).then(({ success, errorMessage }) => {
158-
if (success) {
159-
return this.fetchAccounts();
160-
} else if (errorMessage) {
149+
if (!success && errorMessage) {
161150
alertUser(errorMessage);
162151
}
163152
});
@@ -166,9 +155,7 @@ class ManageAccounts extends Component<Props, State> {
166155
// disabling for now, we'll either bring this back (if user request it) or remove for good
167156
// private setWatch = async (accountCode: string, watch: boolean) => {
168157
// const result = await backendAPI.accountSetWatch(accountCode, watch);
169-
// if (result.success) {
170-
// await this.fetchAccounts();
171-
// } else if (result.errorMessage) {
158+
// if (!result.success && result.errorMessage) {
172159
// alertUser(result.errorMessage);
173160
// }
174161
// };
@@ -226,17 +213,16 @@ class ManageAccounts extends Component<Props, State> {
226213

227214
private toggleToken = (ethAccountCode: string, tokenCode: string, active: boolean) => {
228215
backendAPI.setTokenActive(ethAccountCode, tokenCode, active).then(({ success, errorMessage }) => {
229-
if (success) {
230-
this.fetchAccounts();
231-
} else if (errorMessage) {
216+
if (!success && errorMessage) {
232217
alertUser(errorMessage);
233218
}
234219
});
235220
};
236221

237222
private updateAccount = (event: React.SyntheticEvent) => {
238223
event.preventDefault();
239-
const { accounts, currentlyEditedAccount } = this.state;
224+
const { accounts } = this.props;
225+
const { currentlyEditedAccount } = this.state;
240226

241227
if (!currentlyEditedAccount) {
242228
return;
@@ -256,7 +242,6 @@ class ManageAccounts extends Component<Props, State> {
256242
if (currentlyEditedAccount.active !== account?.active) {
257243
this.toggleAccount(currentlyEditedAccount.code, currentlyEditedAccount.active);
258244
}
259-
this.fetchAccounts();
260245
this.setState({
261246
editErrorMessage: undefined,
262247
currentlyEditedAccount: undefined,
@@ -265,8 +250,8 @@ class ManageAccounts extends Component<Props, State> {
265250
};
266251

267252
public render() {
268-
const { t, deviceIDs, hasAccounts } = this.props;
269-
const { accounts, editErrorMessage, currentlyEditedAccount } = this.state;
253+
const { t, accounts, deviceIDs, hasAccounts } = this.props;
254+
const { editErrorMessage, currentlyEditedAccount } = this.state;
270255
const accountsByKeystore = getAccountsByKeystore(accounts);
271256
return (
272257
<GuideWrapper>
@@ -358,7 +343,6 @@ class ManageAccounts extends Component<Props, State> {
358343
</GuidedContent>
359344
<AccountGuide />
360345
</GuideWrapper>
361-
362346
);
363347
}
364348
}

0 commit comments

Comments
 (0)