Skip to content

Commit

Permalink
Fix:BalanceReminder
Browse files Browse the repository at this point in the history
  • Loading branch information
lq0-github committed Jan 20, 2025
1 parent 679ba7d commit e0016e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
27 changes: 24 additions & 3 deletions components/BalanceReminder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,46 @@ import { RemindCloseIcon, RemindIcon } from "./icon";
import { useAppSelector } from "../../redux/hooks";
import { getAccountId } from "../../redux/accountSelectors";
import { setAccountDetailsOpen, setActiveTab, setSelectedTab } from "../../redux/marginTabSlice";
import {
getMarginAccountSupplied,
getMarginAccountSuppliedMEME,
} from "../../redux/marginAccountSelectors";
import { useMarginAccount } from "../../hooks/useMarginAccount";

const BalanceReminder = () => {
const router = useRouter();
const { getAssetById, getAssetByIdMEME } = useMarginAccount();
const accountId = useAppSelector(getAccountId);
const [shouldShow, setShouldShow] = useState(false);
const accountSupplied = useAppSelector(getMarginAccountSupplied);
const accountSuppliedMEME = useAppSelector(getMarginAccountSuppliedMEME);
const combinedAccountSupplied = [
...accountSupplied.map((token) => ({ ...token, type: "main" })),
...accountSuppliedMEME.map((token) => ({ ...token, type: "meme" })),
];
const Unreminded = useMemo(() => {
const lastClosedDate = localStorage.getItem("balanceReminderLastClosed");
const today = new Date().toDateString();
return !lastClosedDate || lastClosedDate !== today;
}, []);
const dispatch = useDispatch();
useEffect(() => {
if (accountId && Unreminded) {
const hasValidAccountSupplied =
combinedAccountSupplied.length > 0 &&
combinedAccountSupplied.some((token) => {
const assetDetails =
token.type === "main" ? getAssetById(token.token_id) : getAssetByIdMEME(token.token_id);
return (
assetDetails && token.balance.toString().length >= assetDetails.config.extra_decimals
);
});

if (accountId && Unreminded && hasValidAccountSupplied) {
setShouldShow(true);
// setPersonalDataUpdatedSerialNumber(personalDataUpdatedSerialNumber + 1);
} else {
setShouldShow(false);
}
}, [accountId, router.pathname, Unreminded]);
}, [accountId, router.pathname, Unreminded, combinedAccountSupplied]);
const handleClaim = () => {
dispatch(setActiveTab("my"));
dispatch(setSelectedTab("account"));
Expand Down
16 changes: 1 addition & 15 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,12 @@ const Init = () => {
return null;
};
function Upgrade({ Component, pageProps }) {
const { getAssetById, getAssetByIdMEME } = useMarginAccount();
const [upgrading, setUpgrading] = useState<boolean>(true);
const accountSupplied = useAppSelector(getMarginAccountSupplied);
const accountSuppliedMEME = useAppSelector(getMarginAccountSuppliedMEME);
const combinedAccountSupplied = [
...accountSupplied.map((token) => ({ ...token, type: "main" })),
...accountSuppliedMEME.map((token) => ({ ...token, type: "meme" })),
];
const dispatch = useAppDispatch();
const accountId = useAppSelector(getAccountId);
const portfolio = useAppSelector(getAccountPortfolio());
const assets = useAppSelector(getAssets);
const config = useAppSelector(getConfig);
const hasValidAccountSupplied =
combinedAccountSupplied?.length > 0 &&
combinedAccountSupplied?.some((token) => {
const assetDetails =
token.type === "main" ? getAssetById(token.token_id) : getAssetByIdMEME(token.token_id);
return assetDetails && token.balance.toString().length >= assetDetails.config.extra_decimals;
});
useEffect(() => {
if (
!portfolio.positions ||
Expand Down Expand Up @@ -181,7 +167,7 @@ function Upgrade({ Component, pageProps }) {
<ToastMessage />
<Component {...pageProps} />
{/* <Popup className="xsm:hidden" /> */}
{hasValidAccountSupplied && <BalanceReminder />}
<BalanceReminder />
<RpcList />
<PubTestModal />
</Layout>
Expand Down

0 comments on commit e0016e5

Please sign in to comment.