Skip to content

Commit

Permalink
feat: update arc200 asset information when updating the accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
kieranroneill committed Dec 22, 2023
1 parent e8e96d6 commit dfd3d2c
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/extension/apps/main/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import SignTxnsModal from '@extension/components/SignTxnsModal';
import WalletConnectModal from '@extension/components/WalletConnectModal';

// features
import { setAccountId } from '@extension/features/add-asset';
import { reset as resetAddAsset } from '@extension/features/add-asset';
import {
fetchAccountsFromStorageThunk,
startPollingForAccountsThunk,
Expand Down Expand Up @@ -61,7 +61,7 @@ const Root: FC = () => {
const accounts: IAccount[] = useSelectAccounts();
const selectedNetwork: INetwork | null = useSelectSelectedNetwork();
// handlers
const handleAddAssetClose = () => dispatch(setAccountId(null));
const handleAddAssetClose = () => dispatch(resetAddAsset());
const handleConfirmClose = () => dispatch(setConfirm(null));
const handleEnableModalClose = () => dispatch(setEnableRequest(null));
const handleErrorModalClose = () => dispatch(setError(null));
Expand Down
10 changes: 7 additions & 3 deletions src/extension/components/AddAssetModal/AddAssetModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ const AddAssetModal: FC<IProps> = ({ onClose }: IProps) => {
);
}

// reset the modal to close it
dispatch(reset());
handleClose();
} catch (error) {
dispatch(
createNotification({
Expand All @@ -147,11 +146,16 @@ const AddAssetModal: FC<IProps> = ({ onClose }: IProps) => {
);
}
};
const handleCancelClick = () => onClose();
const handleCancelClick = () => handleClose();
const handleClearQuery = () => {
setQuery('');
dispatch(clearAssets());
};
const handleClose = () => {
setQuery('');
setQueryByIdDispatch(null);
onClose();
};
const handleKeyUp = () => {
// if we have only numbers, we have an asset/app id
if (new RegExp(/^\d+$/).test(query)) {
Expand Down
42 changes: 37 additions & 5 deletions src/extension/components/AssetsTab/AssetsTab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { HStack, Spacer, TabPanel, VStack } from '@chakra-ui/react';
import {
HStack,
Spacer,
Spinner,
TabPanel,
Tooltip,
VStack,
} from '@chakra-ui/react';
import React, { FC, ReactNode } from 'react';
import { useTranslation } from 'react-i18next';
import { IoAdd } from 'react-icons/io5';
Expand All @@ -19,13 +26,16 @@ import { setAccountId as setAddAssetAccountId } from '@extension/features/add-as

// hooks
import useAccountInformation from '@extension/hooks/useAccountInformation';
import useDefaultTextColor from '@extension/hooks/useDefaultTextColor';

// selectors
import {
useSelectArc200AssetsBySelectedNetwork,
useSelectFetchingArc200Assets,
useSelectFetchingStandardAssets,
useSelectStandardAssetsBySelectedNetwork,
useSelectSelectedNetwork,
useSelectUpdatingArc200Assets,
useSelectUpdatingStandardAssets,
} from '@extension/selectors';

Expand Down Expand Up @@ -53,12 +63,15 @@ const AssetsTab: FC<IProps> = ({ account }: IProps) => {
const dispatch: IAppThunkDispatch = useDispatch<IAppThunkDispatch>();
// selectors
const arc200Assets: IArc200Asset[] = useSelectArc200AssetsBySelectedNetwork();
const fetching: boolean = useSelectFetchingStandardAssets();
const fetchingArc200Assets: boolean = useSelectFetchingArc200Assets();
const fetchingStandardAssets: boolean = useSelectFetchingStandardAssets();
const selectedNetwork: INetwork | null = useSelectSelectedNetwork();
const standardAssets: IStandardAsset[] =
useSelectStandardAssetsBySelectedNetwork();
const updating: boolean = useSelectUpdatingStandardAssets();
const updatingArc200Assets: boolean = useSelectUpdatingArc200Assets();
const updatingStandardAssets: boolean = useSelectUpdatingStandardAssets();
// hooks
const defaultTextColor: string = useDefaultTextColor();
const accountInformation: IAccountInformation | null = useAccountInformation(
account.id
);
Expand All @@ -83,7 +96,7 @@ const AssetsTab: FC<IProps> = ({ account }: IProps) => {
const renderContent = () => {
let assetNodes: ReactNode[] = [];

if (fetching || updating) {
if (fetchingArc200Assets || fetchingStandardAssets) {
return Array.from({ length: 3 }, (_, index) => (
<AssetTabLoadingItem key={`asset-tab-loading-item-${index}`} />
));
Expand Down Expand Up @@ -143,12 +156,31 @@ const AssetsTab: FC<IProps> = ({ account }: IProps) => {
{/*controls*/}
<HStack
alignItems="center"
justifyContent="flex-end"
justifyContent="flex-start"
px={DEFAULT_GAP / 2}
py={DEFAULT_GAP / 3}
spacing={1}
w="full"
>
{/*updating asset spinner*/}
{updatingArc200Assets ||
(updatingStandardAssets && (
<Tooltip
aria-label="Updating asset information spinner"
label={t<string>('captions.updatingAssetInformation')}
>
<Spinner
thickness="1px"
speed="0.65s"
color={defaultTextColor}
size="sm"
/>
</Tooltip>
))}

<Spacer />

{/*add asset*/}
<Button
leftIcon={<IoAdd />}
onClick={handleAddAssetClick}
Expand Down
2 changes: 2 additions & 0 deletions src/extension/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export { default as useSelectConfirm } from './useSelectConfirm';
export { default as useSelectEnableRequest } from './useSelectEnableRequest';
export { default as useSelectError } from './useSelectError';
export { default as useSelectFetchingAccounts } from './useSelectFetchingAccounts';
export { default as useSelectFetchingArc200Assets } from './useSelectFetchingArc200Assets';
export { default as useSelectFetchingSessions } from './useSelectFetchingSessions';
export { default as useSelectFetchingSettings } from './useSelectFetchingSettings';
export { default as useSelectFetchingStandardAssets } from './useSelectFetchingStandardAssets';
Expand Down Expand Up @@ -44,6 +45,7 @@ export { default as useSelectSignBytesRequest } from './useSelectSignBytesReques
export { default as useSelectSignTxnsRequest } from './useSelectSignTxnsRequest';
export { default as useSelectStandardAssetsByGenesisHash } from './useSelectStandardAssetsByGenesisHash';
export { default as useSelectStandardAssetsBySelectedNetwork } from './useSelectStandardAssetsBySelectedNetwork';
export { default as useSelectUpdatingArc200Assets } from './useSelectUpdatingArc200Assets';
export { default as useSelectUpdatingStandardAssets } from './useSelectUpdatingStandardAssets';
export { default as useSelectWalletConnectModalOpen } from './useSelectWalletConnectModalOpen';
export { default as useSelectWeb3Wallet } from './useSelectWeb3Wallet';
9 changes: 9 additions & 0 deletions src/extension/selectors/useSelectFetchingArc200Assets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useSelector } from 'react-redux';

// types
import { IMainRootState } from '@extension/types';
export default function useSelectFetchingArc200Assets(): boolean {
return useSelector<IMainRootState, boolean>(
(state) => state.arc200Assets.fetching
);
}
10 changes: 10 additions & 0 deletions src/extension/selectors/useSelectUpdatingArc200Assets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { useSelector } from 'react-redux';

// types
import { IMainRootState } from '@extension/types';

export default function useSelectUpdatingArc200Assets(): boolean {
return useSelector<IMainRootState, boolean>(
(state) => state.arc200Assets.updating
);
}
1 change: 1 addition & 0 deletions src/extension/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ const translation: IResourceLanguage = {
transactionIdCopied: 'Transaction ID copied!',
transactionSendSuccessful:
'Transaction "{{transactionId}}" was successfully sent.',
updatingAssetInformation: 'Updating asset information',
},
errors: {
descriptions: {
Expand Down

0 comments on commit dfd3d2c

Please sign in to comment.