diff options
| author | David Lönnhager <david.l@mullvad.net> | 2021-06-16 10:22:47 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2021-06-18 11:53:28 +0200 |
| commit | 5453eece3a53c4cc45c8987a88789e43fb214912 (patch) | |
| tree | c36308988a46a5125949f47611e7f76cba21c27a /gui/src | |
| parent | 335cc80d9347f43264765a3dd359eda83c782bc8 (diff) | |
| download | mullvadvpn-5453eece3a53c4cc45c8987a88789e43fb214912.tar.xz mullvadvpn-5453eece3a53c4cc45c8987a88789e43fb214912.zip | |
Update account history RPCs
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/main/daemon-rpc.ts | 8 | ||||
| -rw-r--r-- | gui/src/main/index.ts | 12 | ||||
| -rw-r--r-- | gui/src/renderer/app.tsx | 10 | ||||
| -rw-r--r-- | gui/src/renderer/components/Login.tsx | 48 | ||||
| -rw-r--r-- | gui/src/renderer/components/Support.tsx | 4 | ||||
| -rw-r--r-- | gui/src/renderer/containers/LoginPage.tsx | 2 | ||||
| -rw-r--r-- | gui/src/renderer/redux/account/actions.ts | 4 | ||||
| -rw-r--r-- | gui/src/renderer/redux/account/reducers.ts | 4 | ||||
| -rw-r--r-- | gui/src/shared/ipc-schema.ts | 8 |
9 files changed, 49 insertions, 51 deletions
diff --git a/gui/src/main/daemon-rpc.ts b/gui/src/main/daemon-rpc.ts index 04332a4447..8ed75b8885 100644 --- a/gui/src/main/daemon-rpc.ts +++ b/gui/src/main/daemon-rpc.ts @@ -418,13 +418,13 @@ export class DaemonRpc { } } - public async getAccountHistory(): Promise<AccountToken[]> { + public async getAccountHistory(): Promise<AccountToken | undefined> { const response = await this.callEmpty<grpcTypes.AccountHistory>(this.client.getAccountHistory); - return response.toObject().tokenList; + return response.getToken()?.getValue(); } - public async removeAccountFromHistory(accountToken: AccountToken): Promise<void> { - await this.callString(this.client.removeAccountFromHistory, accountToken); + public async clearAccountHistory(): Promise<void> { + await this.callEmpty(this.client.clearAccountHistory); } public async getCurrentVersion(): Promise<string> { diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 2b9bc74a0a..d86a6cba53 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -115,7 +115,7 @@ class ApplicationMain { private quitStage = AppQuitStage.unready; private accountData?: IAccountData = undefined; - private accountHistory: AccountToken[] = []; + private accountHistory?: AccountToken = undefined; private tunnelState: TunnelState = { state: 'disconnected' }; private settings: ISettings = { accountToken: undefined, @@ -665,7 +665,7 @@ class ApplicationMain { return daemonEventListener; } - private setAccountHistory(accountHistory: AccountToken[]) { + private setAccountHistory(accountHistory?: AccountToken) { this.accountHistory = accountHistory; if (this.windowController) { @@ -1128,8 +1128,8 @@ class ApplicationMain { this.daemonRpc.submitVoucher(voucherCode), ); - IpcMainEventChannel.accountHistory.handleRemoveItem(async (token: AccountToken) => { - await this.daemonRpc.removeAccountFromHistory(token); + IpcMainEventChannel.accountHistory.handleClear(async () => { + await this.daemonRpc.clearAccountHistory(); consumePromise(this.updateAccountHistory()); }); @@ -1162,8 +1162,8 @@ class ApplicationMain { const reportPath = this.getProblemReportPath(id); const executable = resolveBin('mullvad-problem-report'); const args = ['collect', '--output', reportPath]; - if (toRedact.length > 0) { - args.push('--redact', ...toRedact); + if (toRedact) { + args.push('--redact', toRedact); } return new Promise((resolve, reject) => { diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index 7627428059..9fa0e4a456 100644 --- a/gui/src/renderer/app.tsx +++ b/gui/src/renderer/app.tsx @@ -148,7 +148,7 @@ export default class AppRenderer { this.setAccountExpiry(newAccountData && newAccountData.expiry); }); - IpcRendererEventChannel.accountHistory.listen((newAccountHistory: AccountToken[]) => { + IpcRendererEventChannel.accountHistory.listen((newAccountHistory?: AccountToken) => { this.setAccountHistory(newAccountHistory); }); @@ -337,8 +337,8 @@ export default class AppRenderer { return IpcRendererEventChannel.settings.setDnsOptions(dns); } - public removeAccountFromHistory(accountToken: AccountToken): Promise<void> { - return IpcRendererEventChannel.accountHistory.removeItem(accountToken); + public clearAccountHistory(): Promise<void> { + return IpcRendererEventChannel.accountHistory.clear(); } public async openLinkWithAuth(link: string): Promise<void> { @@ -455,7 +455,7 @@ export default class AppRenderer { return IpcRendererEventChannel.splitTunneling.launchApplication(application); } - public collectProblemReport(toRedact: string[]): Promise<string> { + public collectProblemReport(toRedact?: string): Promise<string> { return IpcRendererEventChannel.problemReport.collectLogs(toRedact); } @@ -653,7 +653,7 @@ export default class AppRenderer { } } - private setAccountHistory(accountHistory: AccountToken[]) { + private setAccountHistory(accountHistory?: AccountToken) { this.reduxActions.account.updateAccountHistory(accountHistory); } diff --git a/gui/src/renderer/components/Login.tsx b/gui/src/renderer/components/Login.tsx index 6118f7ac8e..e672094f99 100644 --- a/gui/src/renderer/components/Login.tsx +++ b/gui/src/renderer/components/Login.tsx @@ -36,13 +36,13 @@ import { AriaControlGroup, AriaControlled, AriaControls } from './AriaGroup'; interface IProps { accountToken?: AccountToken; - accountHistory: AccountToken[]; + accountHistory?: AccountToken; loginState: LoginState; openExternalLink: (type: string) => void; login: (accountToken: AccountToken) => void; resetLoginError: () => void; updateAccountToken: (accountToken: AccountToken) => void; - removeAccountTokenFromHistory: (accountToken: AccountToken) => Promise<void>; + clearAccountHistory: () => Promise<void>; createNewAccount: () => void; } @@ -208,7 +208,9 @@ export default class Login extends React.Component<IProps, IState> { } private shouldShowAccountHistory() { - return this.allowInteraction() && this.state.isActive && this.props.accountHistory.length > 0; + return ( + this.allowInteraction() && this.state.isActive && this.props.accountHistory !== undefined + ); } private shouldShowFooter() { @@ -223,13 +225,13 @@ export default class Login extends React.Component<IProps, IState> { this.props.login(accountToken); }; - private onRemoveAccountFromHistory = (accountToken: string) => { - consumePromise(this.removeAccountFromHistory(accountToken)); + private onClearAccountHistory = () => { + consumePromise(this.clearAccountHistory()); }; - private async removeAccountFromHistory(accountToken: AccountToken) { + private async clearAccountHistory() { try { - await this.props.removeAccountTokenFromHistory(accountToken); + await this.props.clearAccountHistory(); // TODO: Remove account from memory } catch (error) { @@ -288,9 +290,9 @@ export default class Login extends React.Component<IProps, IState> { <Accordion expanded={this.shouldShowAccountHistory()}> <StyledAccountDropdownContainer> <AccountDropdown - items={this.props.accountHistory.slice().reverse()} + item={this.props.accountHistory} onSelect={this.onSelectAccountFromHistory} - onRemove={this.onRemoveAccountFromHistory} + onRemove={this.onClearAccountHistory} /> </StyledAccountDropdownContainer> </Accordion> @@ -316,28 +318,24 @@ export default class Login extends React.Component<IProps, IState> { } interface IAccountDropdownProps { - items: AccountToken[]; + item?: AccountToken; onSelect: (value: AccountToken) => void; onRemove: (value: AccountToken) => void; } function AccountDropdown(props: IAccountDropdownProps) { - const uniqueItems = [...new Set(props.items)]; + const token = props.item; + if (!token) { + return null; + } + const label = formatAccountToken(token); return ( - <> - {uniqueItems.map((token) => { - const label = formatAccountToken(token); - return ( - <AccountDropdownItem - key={token} - value={token} - label={label} - onSelect={props.onSelect} - onRemove={props.onRemove} - /> - ); - })} - </> + <AccountDropdownItem + value={token} + label={label} + onSelect={props.onSelect} + onRemove={props.onRemove} + /> ); } diff --git a/gui/src/renderer/components/Support.tsx b/gui/src/renderer/components/Support.tsx index e7960a30c7..d34e6b6b08 100644 --- a/gui/src/renderer/components/Support.tsx +++ b/gui/src/renderer/components/Support.tsx @@ -49,13 +49,13 @@ interface ISupportState { interface ISupportProps { defaultEmail: string; defaultMessage: string; - accountHistory: AccountToken[]; + accountHistory?: AccountToken; isOffline: boolean; onClose: () => void; viewLog: (path: string) => void; saveReportForm: (form: ISupportReportForm) => void; clearReportForm: () => void; - collectProblemReport: (accountsToRedact: string[]) => Promise<string>; + collectProblemReport: (accountToRedact?: string) => Promise<string>; sendProblemReport: (email: string, message: string, savedReportId: string) => Promise<void>; outdatedVersion: boolean; suggestedIsBeta: boolean; diff --git a/gui/src/renderer/containers/LoginPage.tsx b/gui/src/renderer/containers/LoginPage.tsx index f937beb590..a56e6ec04a 100644 --- a/gui/src/renderer/containers/LoginPage.tsx +++ b/gui/src/renderer/containers/LoginPage.tsx @@ -25,7 +25,7 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: IAppContext) => { }, openExternalLink: (url: string) => props.app.openUrl(url), updateAccountToken, - removeAccountTokenFromHistory: (token: string) => props.app.removeAccountFromHistory(token), + clearAccountHistory: () => props.app.clearAccountHistory(), createNewAccount: () => consumePromise(props.app.createNewAccount()), }; }; diff --git a/gui/src/renderer/redux/account/actions.ts b/gui/src/renderer/redux/account/actions.ts index 3c0bad3c7b..b8fbe94d39 100644 --- a/gui/src/renderer/redux/account/actions.ts +++ b/gui/src/renderer/redux/account/actions.ts @@ -44,7 +44,7 @@ interface IUpdateAccountTokenAction { interface IUpdateAccountHistoryAction { type: 'UPDATE_ACCOUNT_HISTORY'; - accountHistory: AccountToken[]; + accountHistory?: AccountToken; } interface IUpdateAccountExpiryAction { @@ -125,7 +125,7 @@ function updateAccountToken(token: AccountToken): IUpdateAccountTokenAction { }; } -function updateAccountHistory(accountHistory: AccountToken[]): IUpdateAccountHistoryAction { +function updateAccountHistory(accountHistory?: AccountToken): IUpdateAccountHistoryAction { return { type: 'UPDATE_ACCOUNT_HISTORY', accountHistory, diff --git a/gui/src/renderer/redux/account/reducers.ts b/gui/src/renderer/redux/account/reducers.ts index 8de7b2d07e..53bc55db1b 100644 --- a/gui/src/renderer/redux/account/reducers.ts +++ b/gui/src/renderer/redux/account/reducers.ts @@ -8,14 +8,14 @@ export type LoginState = | { type: 'failed'; method: LoginMethod; error: Error }; export interface IAccountReduxState { accountToken?: AccountToken; - accountHistory: AccountToken[]; + accountHistory?: AccountToken; expiry?: string; // ISO8601 status: LoginState; } const initialState: IAccountReduxState = { accountToken: undefined, - accountHistory: [], + accountHistory: undefined, expiry: undefined, status: { type: 'none' }, }; diff --git a/gui/src/shared/ipc-schema.ts b/gui/src/shared/ipc-schema.ts index 5cc347e51e..01c5c53a95 100644 --- a/gui/src/shared/ipc-schema.ts +++ b/gui/src/shared/ipc-schema.ts @@ -44,7 +44,7 @@ export interface IAppStateSnapshot { isConnected: boolean; autoStart: boolean; accountData?: IAccountData; - accountHistory: AccountToken[]; + accountHistory?: AccountToken; tunnelState: TunnelState; settings: ISettings; location?: ILocation; @@ -165,8 +165,8 @@ export const ipcSchema = { submitVoucher: invoke<string, VoucherResponse>(), }, accountHistory: { - '': notifyRenderer<AccountToken[]>(), - removeItem: invoke<AccountToken, void>(), + '': notifyRenderer<AccountToken | undefined>(), + clear: invoke<void, void>(), }, autoStart: { '': notifyRenderer<boolean>(), @@ -183,7 +183,7 @@ export const ipcSchema = { launchApplication: invoke<ILinuxSplitTunnelingApplication | string, LaunchApplicationResult>(), }, problemReport: { - collectLogs: invoke<string[], string>(), + collectLogs: invoke<string | undefined, string>(), sendReport: invoke<{ email: string; message: string; savedReportId: string }, void>(), viewLog: invoke<string, string>(), }, |
