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

feature: add account watch mode #1045

Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/apps/popup/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useUserActivityTracker } from '@src/hooks/use-user-activity-tracker';

import { AccountSettingsPage } from '@popup/pages/account-settings';
import { AddContactPage } from '@popup/pages/add-contact';
import { AddWatchAccount } from '@popup/pages/add-watch-account';
import { AllAccountsPage } from '@popup/pages/all-accounts';
import { BackupSecretPhrasePage } from '@popup/pages/backup-secret-phrase';
import { BuyCSPRPage } from '@popup/pages/buy-cspr';
Expand Down Expand Up @@ -249,6 +250,7 @@ function AppRoutes() {
element={<SignWithLedgerInNewWindowPage />}
/>
<Route path={RouterPath.DeployDetails} element={<DeployDetailsPage />} />
<Route path={RouterPath.AddWatchAccount} element={<AddWatchAccount />} />
</Routes>
);
}
100 changes: 100 additions & 0 deletions src/apps/popup/pages/add-watch-account/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import React from 'react';
import { FieldValues, useForm } from 'react-hook-form';

import { RouterPath, useTypedNavigate } from '@popup/router';

import { dispatchToMainStore } from '@background/redux/utils';
import { addWatchingAccount } from '@background/redux/vault/actions';

import {
ContentContainer,
FooterButtonsContainer,
HeaderPopup,
HeaderSubmenuBarNavLink,
InputsContainer,
ParagraphContainer,
PopupLayout,
SpacingSize
} from '@libs/layout';
import {
Button,
FormField,
Input,
TextArea,
Typography
} from '@libs/ui/components';
import { calculateSubmitButtonDisabled } from '@libs/ui/forms/get-submit-button-state-from-validation';

export const AddWatchAccount = () => {
const navigate = useTypedNavigate();

const {
register,
handleSubmit,
formState: { isValid }
} = useForm();

const isButtonDisabled = calculateSubmitButtonDisabled({ isValid });

const onSubmit = (data: FieldValues) => {
dispatchToMainStore(
addWatchingAccount({
publicKey: data.publicKey.trim(),
name: data.name.trim(),
secretKey: '',
hidden: false,
imported: true
})
).then(() => navigate(RouterPath.Home));
};

return (
<PopupLayout
variant="form"
onSubmit={handleSubmit(onSubmit)}
renderHeader={() => (
<HeaderPopup
withNetworkSwitcher
withMenu
withConnectionStatus
renderSubmenuBarItems={() => (
<HeaderSubmenuBarNavLink linkType="back" />
)}
/>
)}
renderContent={() => (
<ContentContainer>
<ParagraphContainer top={SpacingSize.XL}>
<Typography type="header">Add watch account</Typography>
</ParagraphContainer>
<InputsContainer>
<Input
type="text"
label="Name"
placeholder="Name"
{...register('name', {
required: true
})}
/>
<FormField label={'Public key'}>
<TextArea
placeholder={'Public key'}
type="captionHash"
{...register('publicKey', {
required: true
})}
/>
</FormField>
</InputsContainer>
</ContentContainer>
)}
renderFooter={() => (
<FooterButtonsContainer>
<Button type="submit" disabled={isButtonDisabled}>
Add account
</Button>
</FooterButtonsContainer>
)}
/>
);
};
12 changes: 11 additions & 1 deletion src/apps/popup/pages/navigation-menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,17 @@ export function NavigationMenuPageContent() {
}
}
]
: [])
: []),
{
id: 6,
title: t('Add watch account'),
iconPath: 'assets/icons/plus.svg',
disabled: false,
handleOnClick: () => {
closeNavigationMenu();
navigate(RouterPath.AddWatchAccount);
}
}
]
},
{
Expand Down
3 changes: 2 additions & 1 deletion src/apps/popup/router/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ export enum RouterPath {
BuyCSPR = '/buy-cspr',
ImportAccountFromLedger = '/import-account-from-ledger',
SignWithLedgerInNewWindow = '/sign-with-ledger-in-new-window',
DeployDetails = '/deploys-details'
DeployDetails = '/deploys-details',
AddWatchAccount = '/add-watch-account'
}
2 changes: 2 additions & 0 deletions src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import {
accountsAdded,
accountsImported,
activeAccountChanged,
addWatchingAccount,
anotherAccountConnected,
deployPayloadReceived,
deploysReseted,
Expand Down Expand Up @@ -645,6 +646,7 @@ runtime.onMessage.addListener(
case getType(ledgerStateCleared):
case getType(ledgerDeployChanged):
case getType(ledgerRecipientToSaveOnSuccessChanged):
case getType(addWatchingAccount):
store.dispatch(action);
return sendResponse(undefined);

Expand Down
4 changes: 4 additions & 0 deletions src/background/redux/vault/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ export const hideAccountFromListChanged = createAction(
)<{
accountName: string;
}>();

export const addWatchingAccount = createAction(
'ADD_WATCHING_ACCOUNT'
)<Account>();
13 changes: 13 additions & 0 deletions src/background/redux/vault/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
accountsAdded,
accountsImported,
activeAccountChanged,
addWatchingAccount,
anotherAccountConnected,
deployPayloadReceived,
deploysReseted,
Expand Down Expand Up @@ -318,4 +319,16 @@ export const reducer = createReducer(initialState)
})
};
}
)
.handleAction(
addWatchingAccount,
(state, action: ReturnType<typeof addWatchingAccount>): State => {
const account = action.payload;

return {
...state,
accounts: [...state.accounts, account],
activeAccountName: account.name
};
}
);
Loading