Skip to content

Commit

Permalink
improve hot order updates
Browse files Browse the repository at this point in the history
  • Loading branch information
NickJ202 committed Jun 21, 2024
1 parent 48c3da7 commit 5bae325
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 76 deletions.
10 changes: 10 additions & 0 deletions src/components/atoms/Notification/Notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ export default function Notification(props: IProps) {
props.callback();
}

React.useEffect(() => {
if (show) {
const timer = setTimeout(() => {
handleClose();
}, 5000);

return () => clearTimeout(timer);
}
}, []);

return show ? (
<Portal node={DOM.notification}>
<S.Wrapper warning={props.type === 'warning'}>
Expand Down
22 changes: 12 additions & 10 deletions src/components/organisms/AssetsTable/AssetsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,18 @@ export default function AssetsTable(props: IProps) {
if (props.ids && !props.ids.length) {
setAssets([]);
} else {
setAssetIdGroups(
getAssetIdGroups({
ids: props.ids || null,
groupCount: props.pageCount || PAGINATORS.default,
filterListings: assetFilterListings,
sortType: assetSortType.id as AssetSortType,
})
);
if (!props.loadingIds) {
setAssetIdGroups(
getAssetIdGroups({
ids: props.ids || null,
groupCount: props.pageCount || PAGINATORS.default,
filterListings: assetFilterListings,
sortType: assetSortType.id as AssetSortType,
})
);
}
}
}, [assetFilterListings, assetSortType, props.ids]);
}, [assetFilterListings, assetSortType, props.ids, props.loadingIds]);

React.useEffect(() => {
(async function () {
Expand Down Expand Up @@ -166,7 +168,7 @@ export default function AssetsTable(props: IProps) {
}

function getData() {
if (assetsLoading) {
if ((assetsLoading || props.loadingIds) && viewType) {
let Wrapper: any;
let Element: any;

Expand Down
1 change: 1 addition & 0 deletions src/components/organisms/AssetsTable/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface IProps {
ids?: string[];
loadingIds?: boolean;
type: 'list' | 'grid';
pageCount?: number;
}
12 changes: 7 additions & 5 deletions src/components/organisms/OrderCancel/OrderCancel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ export default function OrderCancel(props: IProps) {
});
}

setCancelProcessed(true);

arProvider.setToggleTokenBalanceUpdate(!arProvider.toggleTokenBalanceUpdate);
props.toggleUpdate();

const existingUCM = { ...ucmReducer };
const maxTries = 10;
let tries = 0;
Expand Down Expand Up @@ -98,7 +93,14 @@ export default function OrderCancel(props: IProps) {
};

await fetchUntilChange();

setCancelProcessed(true);

arProvider.setToggleTokenBalanceUpdate(!arProvider.toggleTokenBalanceUpdate);
props.toggleUpdate();

setShowConfirmation(false);
setCancelProcessed(false);
windowUtils.scrollTo(0, 0, 'smooth');
}
} catch (e: any) {
Expand Down
1 change: 1 addition & 0 deletions src/helpers/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const language = {
errorUpdatingProfile: `Error updating profile`,
executing: `Executing`,
fetching: `Fetching`,
fetchingAsset: `Fetching asset`,
floorPrice: `Floor price`,
goTo: `Go to`,
implements: `Implements`,
Expand Down
100 changes: 51 additions & 49 deletions src/views/Asset/AssetAction/AssetAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,53 +160,55 @@ export default function AssetAction(props: IProps) {
return listing.creator === arProvider.profile.id;
}

function getCurrentOwners() {
return (
<>
{!mobile && (
<GS.DrawerHeaderWrapper>
<GS.DrawerContentFlex>
{language.owner.charAt(0).toUpperCase() + language.owner.slice(1)}
</GS.DrawerContentFlex>
<GS.DrawerContentDetail>{language.quantity}</GS.DrawerContentDetail>
<GS.DrawerContentDetail>{language.percentage}</GS.DrawerContentDetail>
</GS.DrawerHeaderWrapper>
)}
{currentOwners.map((owner: OwnerType, index: number) => {
return (
<S.DrawerContentLine key={index}>
{mobile && (
<S.MDrawerHeader>
<GS.DrawerContentHeader>
{language.owner.charAt(0).toUpperCase() + language.owner.slice(1)}
</GS.DrawerContentHeader>
</S.MDrawerHeader>
)}
<S.DrawerContentFlex>
<OwnerLine owner={owner} callback={() => setShowCurrentOwnersModal(false)} />
</S.DrawerContentFlex>
{mobile && (
<S.MDrawerHeader>
<GS.DrawerContentHeader>{language.quantity}</GS.DrawerContentHeader>
</S.MDrawerHeader>
)}
<S.DrawerContentDetailAlt>
{getDenominatedTokenValue(owner.ownerQuantity, props.asset.data.id)}
</S.DrawerContentDetailAlt>
{mobile && (
<S.MDrawerHeader>
<GS.DrawerContentHeader>{language.percentage}</GS.DrawerContentHeader>
</S.MDrawerHeader>
)}
<S.DrawerContentDetailAlt>{formatPercentage(owner.ownerPercentage)}</S.DrawerContentDetailAlt>
</S.DrawerContentLine>
);
})}
</>
);
}
const getCurrentOwners = React.useMemo(() => {
if (currentOwners) {
return (
<>
{!mobile && (
<GS.DrawerHeaderWrapper>
<GS.DrawerContentFlex>
{language.owner.charAt(0).toUpperCase() + language.owner.slice(1)}
</GS.DrawerContentFlex>
<GS.DrawerContentDetail>{language.quantity}</GS.DrawerContentDetail>
<GS.DrawerContentDetail>{language.percentage}</GS.DrawerContentDetail>
</GS.DrawerHeaderWrapper>
)}
{currentOwners.map((owner: OwnerType, index: number) => {
return (
<S.DrawerContentLine key={index}>
{mobile && (
<S.MDrawerHeader>
<GS.DrawerContentHeader>
{language.owner.charAt(0).toUpperCase() + language.owner.slice(1)}
</GS.DrawerContentHeader>
</S.MDrawerHeader>
)}
<S.DrawerContentFlex>
<OwnerLine owner={owner} callback={() => setShowCurrentOwnersModal(false)} />
</S.DrawerContentFlex>
{mobile && (
<S.MDrawerHeader>
<GS.DrawerContentHeader>{language.quantity}</GS.DrawerContentHeader>
</S.MDrawerHeader>
)}
<S.DrawerContentDetailAlt>
{getDenominatedTokenValue(owner.ownerQuantity, props.asset.data.id)}
</S.DrawerContentDetailAlt>
{mobile && (
<S.MDrawerHeader>
<GS.DrawerContentHeader>{language.percentage}</GS.DrawerContentHeader>
</S.MDrawerHeader>
)}
<S.DrawerContentDetailAlt>{formatPercentage(owner.ownerPercentage)}</S.DrawerContentDetailAlt>
</S.DrawerContentLine>
);
})}
</>
);
} else return null;
}, [currentOwners, mobile]);

function getCurrentListings() {
const getCurrentListings = React.useMemo(() => {
if (currentListings) {
return (
<>
Expand Down Expand Up @@ -274,7 +276,7 @@ export default function AssetAction(props: IProps) {
</>
);
} else return null;
}
}, [currentListings, showCurrentListingsModal, mobile]);

function getCurrentTab() {
switch (currentTab) {
Expand Down Expand Up @@ -345,13 +347,13 @@ export default function AssetAction(props: IProps) {
{showCurrentOwnersModal && currentOwners && currentOwners.length > 0 && (
<Modal header={language.currentlyOwnedBy} handleClose={() => setShowCurrentOwnersModal(false)}>
<S.DrawerContent transparent className={'modal-wrapper'}>
{getCurrentOwners()}
{getCurrentOwners}
</S.DrawerContent>
</Modal>
)}
{showCurrentListingsModal && currentListings && currentListings.length > 0 && (
<Modal header={language.currentlyBeingSoldBy} handleClose={() => setShowCurrentListingsModal(false)}>
<S.DrawerContent className={'modal-wrapper'}>{getCurrentListings()}</S.DrawerContent>
<S.DrawerContent className={'modal-wrapper'}>{getCurrentListings}</S.DrawerContent>
</Modal>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default function AssetActionMarket(props: IProps) {
<Drawer
title={language.activeSaleOrders}
icon={ASSETS.orders}
content={<S.DrawerContent>{props.getCurrentListings()}</S.DrawerContent>}
content={<S.DrawerContent>{props.getCurrentListings}</S.DrawerContent>}
/>
</GS.DrawerWrapper>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ export default function AssetActionMarketOrders(props: IProps) {
return false;
}

function getTotals() {
const getTotals = React.useMemo(() => {
let balanceHeader: string | null = null;
let percentageHeader: string | null = null;
let quantity: number | null = null;
Expand Down Expand Up @@ -515,7 +515,7 @@ export default function AssetActionMarketOrders(props: IProps) {
</S.TotalQuantityLine>
</>
);
}
}, [props.asset, props.type, totalAssetBalance, totalSalesQuantity, connectedBalance, ucmReducer]);

function getTotalPriceDisplay() {
let amount = getTotalOrderAmount();
Expand Down Expand Up @@ -664,7 +664,7 @@ export default function AssetActionMarketOrders(props: IProps) {
<span>{formatCount(totalAssetBalance.toString())}</span>
</p>
</S.TotalQuantityLine>
{getTotals()}
{getTotals}
</S.TotalsWrapper>
{maxOrderQuantity > 0 && (
<S.InputWrapper>
Expand Down Expand Up @@ -801,7 +801,7 @@ export default function AssetActionMarketOrders(props: IProps) {
</S.Wrapper>
{showConfirmation && getConfirmation()}
{updating && (
<Notification message={`${language.updatingAsset}...`} type={'success'} callback={() => setUpdating(false)} />
<Notification message={`${language.fetchingAsset}...`} type={'success'} callback={() => setUpdating(false)} />
)}
</>
) : null;
Expand Down
2 changes: 2 additions & 0 deletions src/views/Asset/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useNavigate, useParams } from 'react-router-dom';
import { getAssetById } from 'api';

import { Loader } from 'components/atoms/Loader';
import { Notification } from 'components/atoms/Notification';
import { URLS } from 'helpers/config';
import { AssetDetailType } from 'helpers/types';
import { checkValidAddress } from 'helpers/utils';
Expand Down Expand Up @@ -79,6 +80,7 @@ export default function Asset() {
<S.ActionWrapper>
<AssetAction asset={asset} toggleUpdate={() => setToggleUpdate(!toggleUpdate)} />
</S.ActionWrapper>
{loading && <Notification message={`${language.updatingAsset}...`} type={'success'} callback={null} />}
</>
);
} else {
Expand Down
9 changes: 3 additions & 6 deletions src/views/Profile/ProfileAssets/ProfileAssets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';

import { getAssetIdsByUser } from 'api';

import { Loader } from 'components/atoms/Loader';
import { AssetsTable } from 'components/organisms/AssetsTable';
import { PAGINATORS } from 'helpers/config';

Expand All @@ -20,13 +19,11 @@ const ProfileAssets = React.memo((props: IProps) => {
})();
}, [props.address]);

return props.address && assetIds ? (
return props.address ? (
<S.Wrapper>
<AssetsTable ids={assetIds} type={'grid'} pageCount={PAGINATORS.profile.assets} />
<AssetsTable ids={assetIds} loadingIds={!assetIds} type={'grid'} pageCount={PAGINATORS.profile.assets} />
</S.Wrapper>
) : (
<Loader />
);
) : null;
});

export default ProfileAssets;
2 changes: 1 addition & 1 deletion src/wallet/WalletConnect/WalletConnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default function WalletConnect(_props: { callback?: () => void }) {

function handleProfileAction() {
if (arProvider.profile && arProvider.profile.id) {
navigate(`${URLS.profile}${arProvider.profile.id}`);
navigate(URLS.profileAssets(arProvider.profile.id));
setShowWalletDropdown(false);
} else {
setShowProfileManage(true);
Expand Down

0 comments on commit 5bae325

Please sign in to comment.