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 primary account #329

Merged
merged 4 commits into from
Sep 22, 2024
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { AvatarBadge, Icon } from '@chakra-ui/react';
import React, { FC } from 'react';
import { IoEyeOutline, IoLockClosedOutline } from 'react-icons/io5';
import React, { type FC } from 'react';
import {
IoEyeOutline,
IoLockClosedOutline,
IoStarOutline,
} from 'react-icons/io5';

// components
import AccountAvatar from '../AccountAvatar';
Expand All @@ -19,6 +23,7 @@ const AccountAvatarWithBadges: FC<IProps> = ({
account,
accounts,
network,
systemInfo,
}) => {
// misc
const accountInformation = network
Expand All @@ -35,7 +40,7 @@ const AccountAvatarWithBadges: FC<IProps> = ({
p={1}
placement="top-end"
>
<Icon as={IoEyeOutline} color="white" h={iconSize} w={iconSize} />
<Icon as={IoEyeOutline} boxSize={iconSize} color="white" />
</AvatarBadge>
);

Expand All @@ -61,24 +66,32 @@ const AccountAvatarWithBadges: FC<IProps> = ({

return (
<AccountAvatar>
{/*polis account badge*/}
{systemInfo && systemInfo.polisAccountID === account.id && (
<AvatarBadge
bg="orange.500"
borderWidth={0}
boxSize="1.25em"
p={1}
placement="top-start"
>
<Icon as={IoStarOutline} boxSize={iconSize} color="white" />
</AvatarBadge>
)}

{/*watch badge*/}
{renderWatchAccountBadge()}

{/*re-key badge*/}
{accountInformation && accountInformation.authAddress && (
<AvatarBadge
bg="orange.500"
bg="green.500"
borderWidth={0}
boxSize="1.25em"
p={1}
placement="bottom-end"
>
<Icon
as={IoLockClosedOutline}
color="white"
h={iconSize}
w={iconSize}
/>
<Icon as={IoLockClosedOutline} boxSize={2.5} color="white" />
</AvatarBadge>
)}
</AccountAvatar>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// types
import type { IAccountWithExtendedProps, INetwork } from '@extension/types';
import type {
IAccountWithExtendedProps,
INetwork,
ISystemInfo,
} from '@extension/types';

interface IProps {
account: IAccountWithExtendedProps;
accounts: IAccountWithExtendedProps[];
network: INetwork;
systemInfo: ISystemInfo | null;
}

export default IProps;
17 changes: 15 additions & 2 deletions src/extension/components/AccountSelect/AccountSelectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ import usePrimaryColorScheme from '@extension/hooks/usePrimaryColorScheme';
import useSubTextColor from '@extension/hooks/useSubTextColor';

// selectors
import { useSelectSettingsSelectedNetwork } from '@extension/selectors';
import {
useSelectSettingsSelectedNetwork,
useSelectSystemInfo,
} from '@extension/selectors';

// theme
import { theme } from '@extension/theme';
Expand All @@ -52,6 +55,7 @@ import type { TAccountSelectModalProps } from './types';
import calculateIconSize from '@extension/utils/calculateIconSize';
import convertPublicKeyToAVMAddress from '@extension/utils/convertPublicKeyToAVMAddress';
import ellipseAddress from '@extension/utils/ellipseAddress';
import sortAccountsByPolisAccount from '@extension/utils/sortAccountsByPolisAccount';
import upsertItemsById from '@extension/utils/upsertItemsById';

const AccountSelectModal: FC<TAccountSelectModalProps> = ({
Expand All @@ -67,6 +71,7 @@ const AccountSelectModal: FC<TAccountSelectModalProps> = ({
const { t } = useTranslation();
// selectors
const network = useSelectSettingsSelectedNetwork();
const systemInfo = useSelectSystemInfo();
// hooks
const buttonHoverBackgroundColor = useButtonHoverBackgroundColor();
const defaultTextColor = useDefaultTextColor();
Expand Down Expand Up @@ -134,7 +139,14 @@ const AccountSelectModal: FC<TAccountSelectModalProps> = ({
);
}

return accounts.map((account, index) => {
return (
systemInfo?.polisAccountID
? sortAccountsByPolisAccount({
accounts,
polisAccountID: systemInfo.polisAccountID,
})
: accounts
).map((account, index) => {
const address = convertPublicKeyToAVMAddress(account.publicKey);

return (
Expand Down Expand Up @@ -188,6 +200,7 @@ const AccountSelectModal: FC<TAccountSelectModalProps> = ({
account={account}
accounts={accounts}
network={network}
systemInfo={systemInfo}
/>

{/*name/address*/}
Expand Down
26 changes: 26 additions & 0 deletions src/extension/components/PolisAccountBadge/PolisAccountBadge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Tag, TagLabel, TagLeftIcon, Tooltip } from '@chakra-ui/react';
import React, { type FC } from 'react';
import { useTranslation } from 'react-i18next';
import { IoStarOutline } from 'react-icons/io5';

// types
import type { IProps } from './types';

const PolisAccountBadge: FC<IProps> = ({ size = 'sm', tooltipLabel }) => {
const { t } = useTranslation();
// misc
const tag = (
<Tag borderRadius="full" colorScheme="orange" size={size} variant="solid">
<TagLeftIcon as={IoStarOutline} />
<TagLabel>{t('labels.primary')}</TagLabel>
</Tag>
);

if (tooltipLabel) {
return <Tooltip label={tooltipLabel}>{tag}</Tooltip>;
}

return tag;
};

export default PolisAccountBadge;
1 change: 1 addition & 0 deletions src/extension/components/PolisAccountBadge/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './PolisAccountBadge';
8 changes: 8 additions & 0 deletions src/extension/components/PolisAccountBadge/types/IProps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { ResponsiveValue } from '@chakra-ui/react';

interface IProps {
size?: ResponsiveValue<'size'>;
tooltipLabel?: string;
}

export default IProps;
1 change: 1 addition & 0 deletions src/extension/components/PolisAccountBadge/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { default as IProps } from './IProps';
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { IoAlertCircleOutline, IoLockClosedOutline } from 'react-icons/io5';
// types
import type { IProps } from './types';

// utils
import ellipseAddress from '@extension/utils/ellipseAddress';

const ReKeyedAccountBadge: FC<IProps> = ({
authAddress,
isAuthAccountAvailable = false,
Expand All @@ -21,13 +24,15 @@ const ReKeyedAccountBadge: FC<IProps> = ({
const { t } = useTranslation();
// misc
const tag = (
<Tag borderRadius="full" colorScheme="orange" size={size} variant="solid">
<Tag borderRadius="full" colorScheme="green" size={size} variant="solid">
<TagLeftIcon as={IoLockClosedOutline} />

<TagLabel>{t('labels.reKeyed')}</TagLabel>
<TagLabel>{`${t('labels.reKeyed')}: ${ellipseAddress(
authAddress
)}`}</TagLabel>

{!isAuthAccountAvailable && (
<TagRightIcon as={IoAlertCircleOutline} color="red.300" />
<TagRightIcon as={IoAlertCircleOutline} color="red.600" />
)}
</Tag>
);
Expand Down
3 changes: 3 additions & 0 deletions src/extension/components/SideBar/SideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import {
useSelectActiveAccountDetails,
useSelectAvailableAccountsForSelectedNetwork,
useSelectSettingsSelectedNetwork,
useSelectSystemInfo,
} from '@extension/selectors';

// types
Expand All @@ -84,6 +85,7 @@ const SideBar: FC = () => {
const availableAccounts = useSelectAvailableAccountsForSelectedNetwork();
const fetchingAccounts = useSelectAccountsFetching();
const network = useSelectSettingsSelectedNetwork();
const systemInfo = useSelectSystemInfo();
// hooks
const borderColor = useBorderColor();
const defaultTextColor = useDefaultTextColor();
Expand Down Expand Up @@ -245,6 +247,7 @@ const SideBar: FC = () => {
network={network}
onClick={handleOnAccountClick}
onSort={handleOnAccountSort}
systemInfo={systemInfo}
/>
</ScrollableContainer>

Expand Down
2 changes: 2 additions & 0 deletions src/extension/components/SideBarAccountList/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const Item: FC<IItemProps> = ({
isShortForm,
network,
onClick,
systemInfo,
}) => {
const {
attributes,
Expand Down Expand Up @@ -120,6 +121,7 @@ const Item: FC<IItemProps> = ({
account={account}
accounts={accounts}
network={network}
systemInfo={systemInfo}
/>
</Center>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const SideBarAccountList: FC<IProps> = ({
network,
onClick,
onSort,
systemInfo,
}) => {
const sensors = useSensors(
useSensor(PointerSensor),
Expand Down Expand Up @@ -92,6 +93,7 @@ const SideBarAccountList: FC<IProps> = ({
key={value.id}
network={network}
onClick={handleOnClick}
systemInfo={systemInfo}
/>
))}
</SortableContext>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type {
IAccountWithExtendedProps,
INetworkWithTransactionParams,
ISystemInfo,
} from '@extension/types';

/**
Expand All @@ -14,6 +15,7 @@ interface IItemProps {
isShortForm: boolean;
network: INetworkWithTransactionParams;
onClick: (id: string) => void;
systemInfo: ISystemInfo | null;
}

export default IItemProps;
2 changes: 2 additions & 0 deletions src/extension/components/SideBarAccountList/types/IProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type {
IAccountWithExtendedProps,
INetworkWithTransactionParams,
ISystemInfo,
} from '@extension/types';

/**
Expand All @@ -15,6 +16,7 @@ interface IProps {
network: INetworkWithTransactionParams | null;
onClick: (id: string) => void;
onSort: (accounts: IAccountWithExtendedProps[]) => void;
systemInfo: ISystemInfo | null;
}

export default IProps;
1 change: 1 addition & 0 deletions src/extension/features/system/enums/ThunkEnum.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
enum ThunkEnum {
FetchFromStorage = 'system/fetchFromStorage',
SaveDisableWhatsNewOnUpdate = 'system/saveDisableWhatsNewOnUpdate',
SavePolisAccountID = 'system/savePolisAccountID',
SaveWhatsNewVersion = 'system/saveWhatsNewVersion',
StartPollingForNetworkConnectivity = 'networks/startPollingForNetworkConnectivity',
StopPollingForNetworkConnectivity = 'networks/stopPollingForNetworkConnectivity',
Expand Down
29 changes: 21 additions & 8 deletions src/extension/features/system/slice.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createSlice, PayloadAction, Reducer } from '@reduxjs/toolkit';
import { createSlice, type PayloadAction } from '@reduxjs/toolkit';
import type { i18n } from 'i18next';

// enums
Expand All @@ -8,6 +8,7 @@ import { StoreNameEnum } from '@extension/enums';
import {
fetchFromStorageThunk,
saveDisableWhatsNewOnUpdateThunk,
savePolisAccountIDThunk,
saveWhatsNewVersionThunk,
startPollingForNetworkConnectivityThunk,
stopPollingForTransactionsParamsThunk,
Expand All @@ -23,14 +24,14 @@ import { getInitialState } from './utils';

const slice = createSlice({
extraReducers: (builder) => {
/** fetch from storage **/
/**fetch from storage**/
builder.addCase(
fetchFromStorageThunk.fulfilled,
(state: IState, action) => {
state.info = action.payload;
}
);
/** save disable what's on update **/
/**save disable what's on update**/
builder.addCase(
saveDisableWhatsNewOnUpdateThunk.fulfilled,
(state: IState, action) => {
Expand All @@ -45,7 +46,19 @@ const slice = createSlice({
}
}
);
/** save what's new version **/
/**save polis account id**/
builder.addCase(
savePolisAccountIDThunk.fulfilled,
(state: IState, action) => {
if (state.info) {
state.info = {
...state.info,
polisAccountID: action.payload,
};
}
}
);
/**save what's new version**/
builder.addCase(
saveWhatsNewVersionThunk.fulfilled,
(state: IState, action) => {
Expand All @@ -60,21 +73,21 @@ const slice = createSlice({
}
}
);
/** start polling for network connectivity **/
/**start polling for network connectivity**/
builder.addCase(
startPollingForNetworkConnectivityThunk.fulfilled,
(state: IState, action) => {
state.networkConnectivity.pollingID = action.payload;
}
);
/** stop polling for network connectivity **/
/**stop polling for network connectivity**/
builder.addCase(
stopPollingForTransactionsParamsThunk.fulfilled,
(state: IState) => {
state.networkConnectivity.pollingID = null;
}
);
/** update network connectivity **/
/**update network connectivity**/
builder.addCase(
updateNetworkConnectivityThunk.fulfilled,
(state: IState, action) => {
Expand Down Expand Up @@ -107,5 +120,5 @@ const slice = createSlice({
},
});

export const reducer: Reducer = slice.reducer;
export const reducer = slice.reducer;
export const { setI18nAction, setLogger } = slice.actions;
1 change: 1 addition & 0 deletions src/extension/features/system/thunks/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { default as fetchFromStorageThunk } from './fetchFromStorageThunk';
export { default as saveDisableWhatsNewOnUpdateThunk } from './saveDisableWhatsNewOnUpdateThunk';
export { default as savePolisAccountIDThunk } from './savePolisAccountIDThunk';
export { default as saveWhatsNewVersionThunk } from './saveWhatsNewVersionThunk';
export { default as startPollingForNetworkConnectivityThunk } from './startPollingForNetworkConnectivityThunk';
export { default as stopPollingForTransactionsParamsThunk } from './stopPollingForTransactionsParamsThunk';
Expand Down
Loading
Loading