Skip to content

Commit

Permalink
feat: update dust assets logic
Browse files Browse the repository at this point in the history
  • Loading branch information
naturexie committed Jan 29, 2025
1 parent c53a366 commit b474a92
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 170 deletions.
140 changes: 0 additions & 140 deletions components/Header/Menu.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions components/Header/MenuMobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { MenuButton, CloseIcon, ArrowRightIcon, ArrowTopRightIcon, ArrowDownIcon
import { WrapperMenuMobile } from "./style";
import { bridgeList } from "./Bridge";
import { mainMenuList, helpMenu, Imenu } from "./menuData";
import { toggleShowDust } from "../../redux/appSlice";
import { getShowDust } from "../../redux/appSelectors";
import { toggleShowDust } from "../../redux/marginTrading";
import { getShowDust } from "../../redux/categorySelectors";
import { useAppSelector, useAppDispatch } from "../../redux/hooks";
import { DiscordIcon, MediumIcon, TwitterIcon } from "../Footer/svg";

Expand Down
4 changes: 2 additions & 2 deletions components/Header/Set.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useState } from "react";
import { twMerge } from "tailwind-merge";
import { SetIcon } from "./svg";
import { toggleShowDust } from "../../redux/appSlice";
import { getShowDust } from "../../redux/appSelectors";
import { toggleShowDust } from "../../redux/marginTrading";
import { getShowDust } from "../../redux/categorySelectors";
import { useAppSelector, useAppDispatch } from "../../redux/hooks";

const Set = () => {
Expand Down
3 changes: 2 additions & 1 deletion components/Table/common/cells.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { Box, Tooltip, Skeleton } from "@mui/material";
import { USD_FORMAT, TOKEN_FORMAT, APY_FORMAT, DUST_FORMAT, NUMBER_FORMAT } from "../../../store";
import type { IReward, UIAsset } from "../../../interfaces";
import { useAppSelector } from "../../../redux/hooks";
import { getDisplayAsTokenValue, getShowDust } from "../../../redux/appSelectors";
import { getDisplayAsTokenValue } from "../../../redux/appSelectors";
import { getShowDust } from "../../../redux/categorySelectors";
import { Rewards } from "../../index";
import { useFullDigits } from "../../../hooks/useFullDigits";

Expand Down
5 changes: 0 additions & 5 deletions redux/appSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ export const getAppState = (memeCategory?) => {
);
};

export const getShowDust = createSelector(
(state: RootState) => state.app,
(app) => app.showDust,
);

export const getShowTicker = createSelector(
(state: RootState) => state.app,
(app) => app.showTicker,
Expand Down
6 changes: 0 additions & 6 deletions redux/appSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export interface AppState {
protocolStats: boolean;
displayAsTokenValue: boolean;
showTicker: boolean;
showDust: boolean;
slimStats: boolean;
showDailyReturns: boolean;
fullDigits: {
Expand Down Expand Up @@ -80,7 +79,6 @@ export const initialState: AppState = {
showInfo: true,
protocolStats: true,
displayAsTokenValue: true,
showDust: false,
showTicker: false,
slimStats: false,
showDailyReturns: false,
Expand Down Expand Up @@ -174,9 +172,6 @@ export const appSlice = createSlice({
toggleDisplayValues(state) {
state.displayAsTokenValue = !state.displayAsTokenValue;
},
toggleShowDust(state) {
state.showDust = !state.showDust;
},
toggleSlimStats(state) {
state.slimStats = !state.slimStats;
},
Expand Down Expand Up @@ -245,7 +240,6 @@ export const {
updateAmount,
toggleUseAsCollateral,
toggleDisplayValues,
toggleShowDust,
toggleSlimStats,
setFullDigits,
toggleShowTicker,
Expand Down
6 changes: 0 additions & 6 deletions redux/appSliceMEME.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export interface AppState {
protocolStats: boolean;
displayAsTokenValue: boolean;
showTicker: boolean;
showDust: boolean;
slimStats: boolean;
showDailyReturns: boolean;
fullDigits: {
Expand Down Expand Up @@ -80,7 +79,6 @@ export const initialState: AppState = {
showInfo: true,
protocolStats: true,
displayAsTokenValue: true,
showDust: false,
showTicker: false,
slimStats: false,
showDailyReturns: false,
Expand Down Expand Up @@ -174,9 +172,6 @@ export const appSliceMEME = createSlice({
toggleDisplayValues(state) {
state.displayAsTokenValue = !state.displayAsTokenValue;
},
toggleShowDust(state) {
state.showDust = !state.showDust;
},
toggleSlimStats(state) {
state.slimStats = !state.slimStats;
},
Expand Down Expand Up @@ -245,7 +240,6 @@ export const {
updateAmount,
toggleUseAsCollateral,
toggleDisplayValues,
toggleShowDust,
toggleSlimStats,
setFullDigits,
toggleShowTicker,
Expand Down
4 changes: 4 additions & 0 deletions redux/categorySelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ export const getActiveCategory = createSelector(
return category.activeCategory;
},
);
export const getShowDust = createSelector(
(state: RootState) => state.category,
(app) => app.showDust,
);
7 changes: 7 additions & 0 deletions redux/marginTrading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface commonAssets {
ReduxTotalPLN: any;
ReduxRangeMount: any;
ReduxActiveTab: string;
showDust: boolean;
}

const initialState: commonAssets = {
Expand All @@ -22,6 +23,7 @@ const initialState: commonAssets = {
ReduxTotalPLN: 0,
ReduxRangeMount: 1,
ReduxActiveTab: "long",
showDust: false,
};

const marginCategory = createSlice({
Expand Down Expand Up @@ -55,6 +57,9 @@ const marginCategory = createSlice({
setReduxActiveTab(state, action) {
state.ReduxActiveTab = action.payload;
},
toggleShowDust(state) {
state.showDust = !state.showDust;
},
},
});

Expand All @@ -68,6 +73,7 @@ const {
setReduxTotalPLN,
setReduxRangeMount,
setReduxActiveTab,
toggleShowDust,
} = marginCategory.actions;
const marginCategoryReducer = marginCategory.reducer;
export {
Expand All @@ -80,5 +86,6 @@ export {
setReduxTotalPLN,
setReduxRangeMount,
setReduxActiveTab,
toggleShowDust,
};
export default marginCategoryReducer;
10 changes: 5 additions & 5 deletions redux/selectors/getAccountRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ export const getAccountDailyRewards = (memeCategory?: boolean) => {
const accountDustProcess = dustProcess({
accountSource: account,
assets,
app,
showDust: category.showDust,
});
const baseCollateralUsdDaily =
getGainsArr(accountDustProcess.portfolio.collaterals, assets)[0] / 365;
Expand Down Expand Up @@ -959,11 +959,11 @@ export function filterAccountEndedFarms(userFarms, allFarms): IAccountFarms {
function dustProcess({
accountSource,
assets,
app,
showDust,
}: {
accountSource: AccountState;
assets: AssetsState;
app: AppState;
showDust: boolean;
}) {
const account = Copy(accountSource);
const portfolioAssets = {
Expand All @@ -987,7 +987,7 @@ function dustProcess({
supplied: suppliedToken,
};
})
.filter(app.showDust ? Boolean : emptySuppliedAsset)
.filter(showDust ? Boolean : emptySuppliedAsset)
.reduce((acc, cur) => [...acc, cur.tokenId], [] as any);

const borrowed = Object.keys(account.portfolio.borrowed)
Expand All @@ -1002,7 +1002,7 @@ function dustProcess({
borrowed: borrowedToken,
};
})
.filter(app.showDust ? Boolean : emptyBorrowedAsset)
.filter(showDust ? Boolean : emptyBorrowedAsset)
.reduce((acc, cur) => [...acc, cur.tokenId], [] as any);
const newSupplied = {};
const newCollateral = {};
Expand Down
6 changes: 3 additions & 3 deletions redux/selectors/getPortfolioAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const getPortfolioAssets = (memeCategory?: boolean) => {
totalSupplyMoney: toUsd(totalSupplyD, asset),
});
})
.filter(app.showDust ? Boolean : emptySuppliedAsset);
.filter(category.showDust ? Boolean : emptySuppliedAsset);
// borrow from regular position
const borrowed = Object.keys(account.portfolio.borrowed || {})
.map((tokenId) => {
Expand Down Expand Up @@ -180,7 +180,7 @@ export const getPortfolioAssets = (memeCategory?: boolean) => {
totalSupplyMoney: toUsd(totalSupplyD, asset),
});
})
.filter(app.showDust ? Boolean : emptyBorrowedAsset);
.filter(category.showDust ? Boolean : emptyBorrowedAsset);
// borrow from lp position
const borrowed_LP = Object.keys(lpPositions).reduce((acc, shadow_id: string) => {
const b = Object.keys(lpPositions[shadow_id].borrowed)
Expand Down Expand Up @@ -223,7 +223,7 @@ export const getPortfolioAssets = (memeCategory?: boolean) => {
totalSupplyMoney: toUsd(totalSupplyD, asset),
});
})
.filter(app.showDust ? Boolean : emptyBorrowedAsset);
.filter(category.showDust ? Boolean : emptyBorrowedAsset);
return { ...acc, [shadow_id]: b };
}, {});
const borrowedAll = Array.from(borrowed);
Expand Down

0 comments on commit b474a92

Please sign in to comment.