Skip to content

Commit

Permalink
TW-1125: [epic] Assets rework (#1006)
Browse files Browse the repository at this point in the history
* TW-683: Tokens rework. Account's tokens -> Redux

* TW-683: Assets rework. Tokens. + Whitelist

* TW-683: Assets rework. Tokens. 'Add Asset' page

* TW-683: Assets rework. Collectibles. Redux

* TW-683: Assets rework. Tokens. Manage page. Fix: listing other account tokens too

* TW-683: Assets rework. Tokens. Refactor

* TW-683: Assets rework. Collectibles. Optimized loading

* TW-683: Assets rework. Collectibles. Optimized loading

* TW-683: Assets rework. Refactor

* TW-683: Assets rework. Optimized balances loading

* TW-683: Assets rework. Collectibles. Fix details loading from OBJKT

* TW-683: Assets rework. Migration from IndexedDB

* TW-683: Assets rework. Refactor

* TW-683: Assets rework. Refactor

* TW-683: Assets rework. Refactor

* TW-683: Assets rework. + ESLint no-cycle rule

* TW-683: Assets rework. Refactor

* TW-683: Assets rework. Migrations made async

* TW-683: Assets rework. Refactor

* TW-683: Assets rework. Refactor

* TW-683: Assets rework. Not keeping metadata from TZKT

* TW-683: Assets rework. Refactor

* TW-683: Assets rework. + __TEMPORARY_COLLECTIBLES_LOAD_LIMIT__

* TW-683: Assets rework. Fix tokens re-render on account switch

* TW-683: Assets rework. Fix page crash, when switching to Ghostnet

* TW-993: Assets rework. Collectibles pagination logic (#1018)

* TW-993: Assets rework. NFTs pagination. + buildCollectibleImagesStack

* TW-993: Assets rework. NFTs pagination. WIP. Not sending all NFTs. Not loading all NFTs meta

* TW-993: Assets rework. NFTs pagination. WIP. + type StoredCollectible

* TW-993: Assets rework. Collectibles pagination. Rolled back to not saving  &

* TW-993: Assets rework. Collectibles pagination. WIP. Grid. Without search

* TW-993: Assets rework. Collectibles pagination. WIP. Grid. + Search

* TW-993: Assets rework. Collectibles pagination. WIP. Tuned meta refresh

* TW-993: Assets rework. Collectibles pagination. + Search in grid

* TW-993: Assets rework. Collectibles pagination. Improved paginated loading

* TW-993: Assets rework. Collectibles pagination. Manage assets page. Refactor

* TW-993: Assets rework. + Manage Collectibles component

* TW-993: Assets rework. Pagination & listing logic. Refactor

* TW-993: Assets rework. Pagination logic. Cleared logs

* TW-993: Assets rework. Pagination logic. WIP. + ReduxStoreState.collectiblesMetadata

* TW-993: Assets rework. Pagination logic. Collectibles meta. WIP. + Slice size check

* TW-993: Assets rework. Pagination logic. Metadata refactor

* TW-993: Assets rework. Pagination logic. Metadata refactor. + Migration

* TW-993: Assets rework. Pagination logic. Refactor

* TW-993: Assets rework. Pagination logic. Refactor

* TW-993: Assets rework. Pagination logic. ++ To known meta when loading assets

* TW-993: Assets rework. Pagination logic. Manage assets page. Refactor

* TW-993: Assets rework. Pagination logic. Fix paginated list update + Fix search

* TW-993: Assets rework. Pagination logic. Using stored balances

* TW-993: Assets rework. Pagination logic. Refactor

* TW-993: Assets rework. Pagination logic. ++

* TW-993: Assets rework. Pagination logic. ++ useIntersectionDetection()

* TW-993: Assets rework. Pagination logic. ++

* TW-993: Assets rework. Pagination logic. ++ Persistance logic

* TW-993: Assets rework. Pagination logic. Refactor

* TW-993: Assets rework. Pagination logic. + Kept page items amount in URL

* TW-993: Assets rework. Pagination logic. + Map type to Redux store

* TW-993: Assets rework. Pagination logic. + <ImageStacked />

* TW-993: Assets rework. Pagination logic. Minor fixes

* TW-993: Assets rework. Pagination logic. Minor fixes

* TW-993: Assets rework. Pagination logic. ++ Performance

* TW-993: Assets rework. Pagination logic. ++ Performance. Removed bottleneck of reducing collectibles in Store

* TW-993: Assets rework. Pagination logic. Performance. Refactor

* TW-993: Assets rework. Pagination logic. Performance. Refactor

* TW-993: Assets rework. Pagination logic. Refactor. -- 'mem'

* TW-993: Assets rework. Pagination logic. Tiny fix

* TW-993: Fix unit tests

* TW-993: Assets rework. Pagination logic. Fix adding token

* TW-993: Assets rework. Pagination logic. Fix removing token

* TW-993: Fix unit tests. -- Send NFT

* TW-993: Assets rework. Clean-up deps

* TW-993: Assets rework. NFTs pagination. Loading 30+50 at a time

* TW-993: Assets rework. NFTs pagination. <SimpleInfiniteScroll> reduced scrollThreshold

* TW-993: Assets rework. NFTs pagination. Rearranged NFTs images sources

* TW-993: Assets rework. NFTs pagination. Fix gas balance loading

* TW-993: Assets rework. NFTs pagination. Overcome OBJKT API byte-size payload limit

* TW-993: Assets rework. NFTs pagination. Fix lost sorting in SendForm

* TW-993: Assets rework. NFTs pagination. Fix areStringArraysEqual

* TW-1225: [epic] Assets rework. Refactor
  • Loading branch information
alex-tsx authored Jan 17, 2024
1 parent 54d768a commit 63bbec8
Show file tree
Hide file tree
Showing 202 changed files with 3,906 additions and 3,436 deletions.
7 changes: 5 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"plugin:import/warnings",
"plugin:import/typescript"
],
"plugins": ["import", "prettier"],
"plugins": ["import", "prettier", "no-type-assertion"],
"parser": "@typescript-eslint/parser",
"overrides": [{
"files": ["*.ts", "*.tsx"],
Expand Down Expand Up @@ -51,9 +51,12 @@
"newlines-between": "always"
}
],
"no-type-assertion/no-type-assertion": "warn",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-non-null-assertion": "warn",
"react-hooks/rules-of-hooks": "warn",
"react-hooks/exhaustive-deps": "warn"
"react-hooks/exhaustive-deps": ["warn", {
"additionalHooks": "(useMemoWithCompare|useDidUpdate)"
}]
}
}
16 changes: 0 additions & 16 deletions e2e/src/features/send.feature
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,3 @@ Feature: Send
And I'm waiting for 'success ✓' operation status

And I am on the Send page
# Send NFT
And I press Asset Drop-down on the Send Form page
And I clear Asset Drop-down Search Input value on the Send Form page
And I enter OBJKTCOM into Asset Drop-down Search Input on the Send Form page
And I select OBJKTCOM token in the token drop-down list on the Send page
And I enter watchOnlyPublicKey into Recipient Input on the Send Form page
And I enter amount_1 into Amount Input on the Send Form page
And I press Send Button on the Send Form page

And I am on the InternalConfirmation page
And I press Confirm Button on the Internal Confirmation page

And I am on the OperationStatusAlert page
And I'm waiting for 'success ✓' operation status

Then I am on the Send page
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ManageAssetsSelectors } from 'src/app/pages/ManageAssets/ManageAssets.selectors';
import { ManageAssetsSelectors } from 'src/app/pages/ManageAssets/selectors';

import { Page } from '../../classes/page.class';
import { createPageElement } from '../../utils/search.utils';
Expand Down
2 changes: 1 addition & 1 deletion e2e/src/page-objects/pages/manage-assets-tokens.page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import retry from 'async-retry';
import { ManageAssetsSelectors } from 'src/app/pages/ManageAssets/ManageAssets.selectors';
import { ManageAssetsSelectors } from 'src/app/pages/ManageAssets/selectors';

import { RETRY_OPTIONS, SHORT_TIMEOUT, VERY_SHORT_TIMEOUT } from 'e2e/src/utils/timing.utils';

Expand Down
6 changes: 2 additions & 4 deletions e2e/src/utils/input-data.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ export const iEnterValues = {
kUSD: 'kUSD',
uUSD: 'uUSD',
WTZ: 'WTZ',
wUSDT: 'wUSDT',
OBJKTCOM: 'Temple NFT'
wUSDT: 'wUSDT'
};

export type IEnterValuesKey = keyof typeof iEnterValues;
Expand All @@ -82,8 +81,7 @@ export const iSelectTokenSlugs = {
kUSD: 'KT1K9gCRgaLRFKTErYt1wVxA3Frb9FjasjTV_0',
uUSD: 'KT1XRPEPXbZK25r3Htzp2o1x7xdMMmfocKNW_0',
WTZ: 'KT1PnUZCp3u2KzWr93pn4DD7HAJnm3rWVrgn_0',
wUSDT: 'KT18fp5rcTW7mbWDmzFwjLDUhs5MeJmagDSZ_18',
OBJKTCOM: 'KT1DGbb333QNo3e2cpN3YGL5aRwWzkADcPA3_2' // 'Temple NFT'
wUSDT: 'KT18fp5rcTW7mbWDmzFwjLDUhs5MeJmagDSZ_18'
};

export const clearDataFromCurrentInput = async () => {
Expand Down
6 changes: 0 additions & 6 deletions jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ Object.assign(global, {
CryptoKey
});

jest.mock('mem', () => {
return function memoize(fn) {
return fn;
};
});

jest.mock('lib/temple/repo', () => ({
db: {
delete: jest.fn(),
Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
"@types/react-modal": "3.13.1",
"@types/react-text-mask": "^5.4.11",
"@types/react-transition-group": "4.4.5",
"@types/react-virtualized": "^9.21.21",
"@types/resolve": "^1.20.2",
"@types/scryptsy": "^2.0.0",
"@types/typedarray-to-buffer": "^4.0.0",
Expand Down Expand Up @@ -127,6 +126,7 @@
"eslint-config-react-app": "^7.0.1",
"eslint-import-resolver-typescript": "^3",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-no-type-assertion": "^1.3.0",
"eslint-plugin-prettier": "^4",
"eslint-webpack-plugin": "^3.2.0",
"fast-glob": "^3.2.12",
Expand All @@ -142,7 +142,6 @@
"libsodium": "0.7.8",
"libsodium-wrappers": "0.7.8",
"lodash": "4.17.21",
"mem": "^9.0.2",
"micro-memoize": "4.0.9",
"mini-css-extract-plugin": "2.6.1",
"nanoid": "3.1.31",
Expand All @@ -163,15 +162,13 @@
"react-dev-utils": "^12",
"react-dom": "18.2.0",
"react-hook-form": "5.3.1",
"react-image-fallback": "^8.0.0",
"react-infinite-scroll-component": "^6.1.0",
"react-json-view": "1.21.3",
"react-modal": "3.15.1",
"react-qr-svg": "2.2.2",
"react-redux": "^8.0.2",
"react-text-mask": "^5.5.0",
"react-transition-group": "4.4.5",
"react-virtualized": "^9.22.3",
"redux-observable": "^2.0.0",
"redux-persist": "^6.0.0",
"regexparam": "1.3.0",
Expand Down Expand Up @@ -216,7 +213,7 @@
"@taquito/contracts-library": "17.0.0",
"@taquito/tzip16": "17.0.0",
"bignumber.js": "9.1.0",
"eslint-plugin-import": "2.29.0",
"eslint-plugin-import": "^2.29.0",
"graphql-request": "^6.1.0",
"json5": "^2.2.2",
"follow-redirects": "^1.15.4"
Expand Down
3 changes: 2 additions & 1 deletion src/app/ConfirmPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import { ModifyFeeAndLimit } from 'app/templates/ExpensesView/ExpensesView';
import NetworkBanner from 'app/templates/NetworkBanner';
import OperationView from 'app/templates/OperationView';
import { CustomRpcContext } from 'lib/analytics';
import { useGasToken } from 'lib/assets/hooks';
import { T, t } from 'lib/i18n';
import { useRetryableSWR } from 'lib/swr';
import { useTempleClient, useAccount, useRelevantAccounts, useCustomChainId, useGasToken } from 'lib/temple/front';
import { useTempleClient, useAccount, useRelevantAccounts, useCustomChainId } from 'lib/temple/front';
import { TempleAccountType, TempleDAppPayload, TempleAccount, TempleChainId } from 'lib/temple/types';
import { useSafeState } from 'lib/ui/hooks';
import { delay } from 'lib/utils';
Expand Down
2 changes: 1 addition & 1 deletion src/app/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import classNames from 'clsx';

import { ReactComponent as DangerIcon } from 'app/icons/danger.svg';
import { t, T } from 'lib/i18n';
import { getOnlineStatus } from 'lib/temple/front/get-online-status';
import { getOnlineStatus } from 'lib/ui/get-online-status';

interface ErrorBoundaryProps extends React.PropsWithChildren {
className?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/app/PageRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import DApps from 'app/pages/DApps';
import Delegate from 'app/pages/Delegate';
import Home from 'app/pages/Home/Home';
import ImportAccount from 'app/pages/ImportAccount';
import ManageAssets from 'app/pages/ManageAssets/ManageAssets';
import ManageAssets from 'app/pages/ManageAssets';
import { CreateWallet } from 'app/pages/NewWallet/CreateWallet';
import { ImportWallet } from 'app/pages/NewWallet/ImportWallet';
import AttentionPage from 'app/pages/Onboarding/pages/AttentionPage';
Expand Down
21 changes: 12 additions & 9 deletions src/app/WithDataLoading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ import React, { FC, useEffect } from 'react';

import { useDispatch } from 'react-redux';

import { useAdvertisingLoading } from 'app/hooks/use-advertising.hook';
import { useCollectiblesDetailsLoading } from 'app/hooks/use-collectibles-details-loading';
import { useTokensApyLoading } from 'app/hooks/use-load-tokens-apy.hook';
import { useLongRefreshLoading } from 'app/hooks/use-long-refresh-loading.hook';
import { useMetadataLoading } from 'app/hooks/use-metadata-loading';
import { useStorageAnalytics } from 'app/hooks/use-storage-analytics';
import { useTokensLoading } from 'app/hooks/use-tokens-loading';
import { loadSwapDexesAction, loadSwapTokensAction } from 'app/store/swap/actions';
import { useBalancesLoading } from 'lib/temple/front/load-balances';

import { useAdvertisingLoading } from './hooks/use-advertising.hook';
import { useAssetsLoading } from './hooks/use-assets-loading';
import { useAssetsMigrations } from './hooks/use-assets-migrations';
import { useBalancesLoading } from './hooks/use-balances-loading';
import { useCollectiblesDetailsLoading } from './hooks/use-collectibles-details-loading';
import { useTokensApyLoading } from './hooks/use-load-tokens-apy.hook';
import { useLongRefreshLoading } from './hooks/use-long-refresh-loading.hook';
import { useMetadataLoading } from './hooks/use-metadata-loading';
import { useMetadataRefresh } from './hooks/use-metadata-refresh';
import { useStorageAnalytics } from './hooks/use-storage-analytics';

export const WithDataLoading: FC<PropsWithChildren> = ({ children }) => {
useTokensLoading();
useAssetsMigrations();

useAssetsLoading();
useMetadataLoading();
useMetadataRefresh();
useBalancesLoading();
Expand Down
36 changes: 36 additions & 0 deletions src/app/atoms/SimpleInfiniteScroll.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { memo, PropsWithChildren, useCallback, useState } from 'react';

import InfiniteScroll from 'react-infinite-scroll-component';

interface Props {
loadNext: EmptyFn;
}

export const SimpleInfiniteScroll = memo<PropsWithChildren<Props>>(({ loadNext, children }) => {
const [seedForLoadNext, setSeedForLoadNext] = useState(0);

const loadNextLocal = useCallback(() => {
setSeedForLoadNext(val => (val % 2) + 1);
loadNext();
}, [loadNext]);

return (
<InfiniteScroll
// For non-array children (e.g. grid layout or other wrapper) this must be `true`
hasChildren={true}
hasMore={true}
/**
* Used only to determine, whether to call `next` on next scroll-to-end event.
* If not updated, `next` will not be triggered - need to update artificially.
* Example: If `loadNext` call throws an error, `dataLength` won't change & `next` is blocked.
*/
dataLength={seedForLoadNext}
next={loadNextLocal}
// `InfiniteScroll`'s loader conditions r not suited here
loader={null}
scrollThreshold="600px"
>
{children}
</InfiniteScroll>
);
});
4 changes: 1 addition & 3 deletions src/app/atoms/useTabSlug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import { useLocation } from 'lib/woozie';
export const useTabSlug = () => {
const { search } = useLocation();

const tabSlug = useMemo(() => {
return useMemo(() => {
const usp = new URLSearchParams(search);
return usp.get('tab');
}, [search]);

return useMemo(() => tabSlug, [tabSlug]);
};
3 changes: 2 additions & 1 deletion src/app/hooks/AliceBob/use-disabled-proceed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { useMemo } from 'react';

import BigNumber from 'bignumber.js';

import { useAccount, useBalance } from 'lib/temple/front';
import { useBalance } from 'lib/balances';
import { useAccount } from 'lib/temple/front';

export const useDisabledProceed = (
inputAmount: number | undefined,
Expand Down
42 changes: 42 additions & 0 deletions src/app/hooks/use-assets-loading.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { useEffect } from 'react';

import { dispatch } from 'app/store';
import {
loadAccountTokensActions,
loadTokensWhitelistActions,
loadAccountCollectiblesActions
} from 'app/store/assets/actions';
import { useAreAssetsLoading } from 'app/store/assets/selectors';
import { ASSETS_SYNC_INTERVAL } from 'lib/fixed-times';
import { useAccount, useChainId } from 'lib/temple/front';
import { TempleChainId } from 'lib/temple/types';
import { useInterval } from 'lib/ui/hooks';

export const useAssetsLoading = () => {
const chainId = useChainId()!;
const { publicKeyHash } = useAccount();

useEffect(() => {
if (chainId === TempleChainId.Mainnet) dispatch(loadTokensWhitelistActions.submit());
}, [chainId]);

const tokensAreLoading = useAreAssetsLoading('tokens');

useInterval(
() => {
if (!tokensAreLoading) dispatch(loadAccountTokensActions.submit({ account: publicKeyHash, chainId }));
},
ASSETS_SYNC_INTERVAL,
[chainId, publicKeyHash]
);

const collectiblesAreLoading = useAreAssetsLoading('collectibles');

useInterval(
() => {
if (!collectiblesAreLoading) dispatch(loadAccountCollectiblesActions.submit({ account: publicKeyHash, chainId }));
},
ASSETS_SYNC_INTERVAL,
[chainId, publicKeyHash]
);
};
18 changes: 18 additions & 0 deletions src/app/hooks/use-assets-migrations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useAllTokensMetadataSelector } from 'app/store/tokens-metadata/selectors';
import { migrateFromIndexedDB } from 'lib/assets/migrations';
import { migrate } from 'lib/local-storage/migrator';
import { useDidMount } from 'lib/ui/hooks';

export const useAssetsMigrations = () => {
const allMetadatas = useAllTokensMetadataSelector();

useDidMount(
() =>
void migrate([
{
name: '[email protected]',
up: () => migrateFromIndexedDB(allMetadatas)
}
])
);
};
27 changes: 27 additions & 0 deletions src/app/hooks/use-balances-loading.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useDispatch } from 'react-redux';

import { loadGasBalanceActions, loadAssetsBalancesActions } from 'app/store/balances/actions';
import { BALANCES_SYNC_INTERVAL } from 'lib/fixed-times';
import { useAccount, useChainId } from 'lib/temple/front';
import { useInterval } from 'lib/ui/hooks';

export const useBalancesLoading = () => {
const chainId = useChainId(true)!;
const { publicKeyHash } = useAccount();

const dispatch = useDispatch();

useInterval(
() => void dispatch(loadGasBalanceActions.submit({ publicKeyHash, chainId })),
BALANCES_SYNC_INTERVAL,
[chainId, publicKeyHash],
true
);

useInterval(
() => void dispatch(loadAssetsBalancesActions.submit({ publicKeyHash, chainId })),
BALANCES_SYNC_INTERVAL,
[chainId, publicKeyHash],
false // Not calling immediately, because balances are also loaded via assets loading
);
};
35 changes: 0 additions & 35 deletions src/app/hooks/use-balances-with-decimals.hook.ts

This file was deleted.

Loading

0 comments on commit 63bbec8

Please sign in to comment.