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(ui-ux): add hasFetchedEvmTokens flag in store for loader #4054

Merged
merged 3 commits into from
Oct 12, 2023
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
Expand Up @@ -134,6 +134,7 @@ export function PortfolioScreen({ navigation }: Props): JSX.Element {
const { hasFetchedToken, allTokens } = useSelector(
(state: RootState) => state.wallet,
);
const { hasFetchedEvmTokens } = useSelector((state: RootState) => state.evm);
const ref = useRef(null);
const logger = useLogger();
useScrollToTop(ref);
Expand Down Expand Up @@ -686,7 +687,8 @@ export function PortfolioScreen({ navigation }: Props): JSX.Element {
{activeButtonGroup === ButtonGroupTabKey.AllTokens && (
<DFIBalanceCard denominationCurrency={denominationCurrency} />
)}
{!hasFetchedToken ? (
{!hasFetchedToken ||
(domain === DomainType.EVM && !hasFetchedEvmTokens) ? (
<View style={tailwind("px-5")}>
<SkeletonLoader row={2} screen={SkeletonLoaderScreen.Portfolio} />
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function DFIBalanceCard({
unifiedDFISelector(state.wallet),
);
const { hasFetchedToken } = useSelector((state: RootState) => state.wallet);
const { hasFetchedEvmTokens } = useSelector((state: RootState) => state.evm);
const { getTokenPrice } = useTokenPrice(denominationCurrency); // input based on selected denomination from portfolio tab
const isEvmDomain = domain === DomainType.EVM;
const tokenAmount = isEvmDomain
Expand Down Expand Up @@ -92,7 +93,7 @@ export function DFIBalanceCard({
"pt-0.5": Platform.OS === "android",
})}
>
{hasFetchedToken ? (
{hasFetchedToken || (isEvmDomain && hasFetchedEvmTokens) ? (
<TokenAmountText
tokenAmount={tokenAmount.toString()}
usdAmount={usdAmount}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export function TokenSelectionScreen(): JSX.Element {
const { evmTokens } = useEvmTokenBalances();

const { hasFetchedToken } = useSelector((state: RootState) => state.wallet);
const { hasFetchedEvmTokens } = useSelector((state: RootState) => state.evm);
const [searchString, setSearchString] = useState("");
const { getTokenPrice } = useTokenPrice();
const debouncedSearchTerm = useDebounce(searchString, 250);
Expand All @@ -78,7 +79,9 @@ export function TokenSelectionScreen(): JSX.Element {
return filterTokensBySearchTerm(tokensWithBalance, debouncedSearchTerm);
}, [tokensWithBalance, debouncedSearchTerm]);

if (hasFetchedToken && tokensWithBalance.length === 0) {
const hasFetchedDvmEvmTokens =
hasFetchedToken || (domain === DomainType.EVM && hasFetchedEvmTokens);
if (hasFetchedDvmEvmTokens && tokensWithBalance.length === 0) {
return <EmptyAsset navigation={navigation} />;
}

Expand Down Expand Up @@ -151,7 +154,7 @@ export function TokenSelectionScreen(): JSX.Element {
ref={searchRef}
/>

{(!hasFetchedToken || debouncedSearchTerm.trim() === "") && (
{(!hasFetchedDvmEvmTokens || debouncedSearchTerm.trim() === "") && (
<ThemedTextV2
style={tailwind("text-xs pl-5 mt-6 mb-2 font-normal-v2")}
light={tailwind("text-mono-light-v2-500")}
Expand All @@ -161,7 +164,7 @@ export function TokenSelectionScreen(): JSX.Element {
</ThemedTextV2>
)}

{hasFetchedToken && debouncedSearchTerm.trim() !== "" && (
{hasFetchedDvmEvmTokens && debouncedSearchTerm.trim() !== "" && (
<ThemedTextV2
style={tailwind("text-xs pl-5 mt-6 mb-2 font-normal-v2")}
light={tailwind("text-mono-light-v2-700")}
Expand All @@ -176,7 +179,7 @@ export function TokenSelectionScreen(): JSX.Element {
</ThemedTextV2>
)}

{!hasFetchedToken && (
{!hasFetchedDvmEvmTokens && (
<SkeletonLoader
row={5}
screen={SkeletonLoaderScreen.TokenSelection}
Expand Down
3 changes: 3 additions & 0 deletions shared/store/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ interface EvmTokenBalance {
interface EvmState {
evmWalletDetails: EvmWalletDetails | null;
evmTokenBalances: EvmTokenBalance[];
hasFetchedEvmTokens: boolean;
}

const initialState: EvmState = {
evmWalletDetails: null,
evmTokenBalances: [],
hasFetchedEvmTokens: false,
};

export const fetchEvmWalletDetails = createAsyncThunk(
Expand Down Expand Up @@ -126,6 +128,7 @@ export const evm = createSlice({
fetchEvmTokenBalances.fulfilled,
(state, action: PayloadAction<EvmTokenBalance[]>) => {
state.evmTokenBalances = action.payload;
state.hasFetchedEvmTokens = true;
},
);
},
Expand Down