Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/calm-foxes-tick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@exactly/mobile": patch
---

🩹 ground date calculations in block timestamp
6 changes: 3 additions & 3 deletions src/components/add-funds/Bridge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import {
} from "viem";
import { useReadContract, useSendCalls, useSendTransaction, useSimulateContract, useWriteContract } from "wagmi";

import chain, { previewerAddress } from "@exactly/common/generated/chain";
import { useReadPreviewerExactly } from "@exactly/common/generated/hooks";
import chain from "@exactly/common/generated/chain";
import shortenHex from "@exactly/common/shortenHex";
import { WAD } from "@exactly/lib";

Expand All @@ -35,6 +34,7 @@ import openBrowser from "../../utils/openBrowser";
import queryClient from "../../utils/queryClient";
import reportError from "../../utils/reportError";
import useAccount from "../../utils/useAccount";
import useMarkets from "../../utils/useMarkets";
import ownerConfig from "../../utils/wagmi/owner";
import AssetLogo from "../shared/AssetLogo";
import ChainLogo from "../shared/ChainLogo";
Expand Down Expand Up @@ -62,7 +62,7 @@ export default function Bridge() {
const [destinationModalOpen, setDestinationModalOpen] = useState(false);

const { address: account } = useAccount();
const { data: markets } = useReadPreviewerExactly({ address: previewerAddress, args: [zeroAddress] });
const { markets } = useMarkets();

const [selectedSource, setSelectedSource] = useState<undefined | { address: string; chain: number }>();
const [selectedDestinationAddress, setSelectedDestinationAddress] = useState<string | undefined>();
Expand Down
18 changes: 4 additions & 14 deletions src/components/card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ import { ScrollView, Separator, Spinner, Square, Switch, XStack, YStack } from "
import { useMutation, useQuery } from "@tanstack/react-query";

import accountInit from "@exactly/common/accountInit";
import { marketUSDCAddress, previewerAddress } from "@exactly/common/generated/chain";
import {
useReadPreviewerExactly,
useReadUpgradeableModularAccountGetInstalledPlugins,
} from "@exactly/common/generated/hooks";
import { marketUSDCAddress } from "@exactly/common/generated/chain";
import { useReadUpgradeableModularAccountGetInstalledPlugins } from "@exactly/common/generated/hooks";

import CardDetails from "./CardDetails";
import CardDisclaimer from "./CardDisclaimer";
Expand All @@ -38,6 +35,7 @@ import {
} from "../../utils/server";
import useAccount from "../../utils/useAccount";
import useAsset from "../../utils/useAsset";
import useMarkets from "../../utils/useMarkets";
import useTabPress from "../../utils/useTabPress";
import InfoAlert from "../shared/InfoAlert";
import LatestActivity from "../shared/LatestActivity";
Expand Down Expand Up @@ -104,15 +102,7 @@ export default function Card() {
query: { enabled: !!address && !!credential },
});

const {
data: markets,
refetch: refetchMarkets,
isFetching: isFetchingMarkets,
} = useReadPreviewerExactly({
address: previewerAddress,
args: address ? [address] : undefined,
query: { enabled: !!address },
});
const { markets, refetch: refetchMarkets, isFetching: isFetchingMarkets } = useMarkets();

let usdBalance = 0n;
if (markets) {
Expand Down
12 changes: 3 additions & 9 deletions src/components/card/exa-card/CardContents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import { useAnimatedStyle, useSharedValue } from "react-native-reanimated";
import { Loader, LockKeyhole, Snowflake } from "@tamagui/lucide-icons";
import { AnimatePresence, XStack, YStack } from "tamagui";

import { marketUSDCAddress, previewerAddress } from "@exactly/common/generated/chain";
import { useReadPreviewerExactly } from "@exactly/common/generated/hooks";
import { marketUSDCAddress } from "@exactly/common/generated/chain";
import { PLATINUM_PRODUCT_ID } from "@exactly/common/panda";
import { borrowLimit, withdrawLimit } from "@exactly/lib";

import SignatureCard from "../../../assets/images/card-signature.svg";
import Card from "../../../assets/images/card.svg";
import useAccount from "../../../utils/useAccount";
import useMarkets from "../../../utils/useMarkets";
import AnimatedView from "../../shared/AnimatedView";
import Text from "../../shared/Text";
import View from "../../shared/View";
Expand All @@ -31,12 +30,7 @@ export default function CardContents({
productId?: string;
revealing: boolean;
}) {
const { address } = useAccount();
const { data: markets } = useReadPreviewerExactly({
address: previewerAddress,
args: address ? [address] : undefined,
query: { enabled: !!address },
});
const { markets } = useMarkets();
const {
t,
i18n: { language },
Expand Down
16 changes: 3 additions & 13 deletions src/components/home/AssetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import { XStack, YStack } from "tamagui";

import { parseUnits } from "viem";

import { previewerAddress, ratePreviewerAddress } from "@exactly/common/generated/chain";
import { useReadPreviewerExactly, useReadRatePreviewerSnapshot } from "@exactly/common/generated/hooks";
import { floatingDepositRates } from "@exactly/lib";

import useAccount from "../../utils/useAccount";
import useMarkets from "../../utils/useMarkets";
import usePortfolio from "../../utils/usePortfolio";
import AssetLogo from "../shared/AssetLogo";
import Skeleton from "../shared/Skeleton";
Expand Down Expand Up @@ -106,18 +104,10 @@ function AssetSection({ title, assets }: { assets: AssetItem[]; title: string })

export default function AssetList() {
const { t } = useTranslation();
const { address } = useAccount();
const { data: markets } = useReadPreviewerExactly({
address: previewerAddress,
args: address ? [address] : undefined,
query: { enabled: !!address },
});
const { markets, rateSnapshot, timestamp } = useMarkets();
const { externalAssets } = usePortfolio();
const { data: snapshots, dataUpdatedAt } = useReadRatePreviewerSnapshot({
address: ratePreviewerAddress,
});

const rates = snapshots ? floatingDepositRates(snapshots, Math.floor(dataUpdatedAt / 1000)) : [];
const rates = rateSnapshot ? floatingDepositRates(rateSnapshot, Number(timestamp)) : [];

const collateralAssets =
markets
Expand Down
19 changes: 3 additions & 16 deletions src/components/home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@ import { useMutation, useQuery } from "@tanstack/react-query";
import { useBytecode } from "wagmi";

import accountInit from "@exactly/common/accountInit";
import {
exaPluginAddress,
exaPreviewerAddress,
marketUSDCAddress,
previewerAddress,
} from "@exactly/common/generated/chain";
import { exaPluginAddress, exaPreviewerAddress, marketUSDCAddress } from "@exactly/common/generated/chain";
import {
useReadExaPreviewerPendingProposals,
useReadPreviewerExactly,
useReadUpgradeableModularAccountGetInstalledPlugins,
} from "@exactly/common/generated/hooks";
import { PLATINUM_PRODUCT_ID } from "@exactly/common/panda";
Expand All @@ -43,6 +37,7 @@ import queryClient from "../../utils/queryClient";
import reportError from "../../utils/reportError";
import { cardModeMutationOptions } from "../../utils/server";
import useAccount from "../../utils/useAccount";
import useMarkets from "../../utils/useMarkets";
import usePortfolio from "../../utils/usePortfolio";
import useTabPress from "../../utils/useTabPress";
import BenefitsSection from "../benefits/BenefitsSection";
Expand Down Expand Up @@ -125,15 +120,7 @@ export default function Home() {
query: { enabled: !!account && !!bytecode, gcTime: 0, refetchInterval: 30_000 },
});
const { data: activity, isFetching: isFetchingActivity } = useQuery<ActivityItem[]>({ queryKey: ["activity"] });
const {
data: markets,
refetch: refetchMarkets,
isFetching: isFetchingPreviewer,
} = useReadPreviewerExactly({
address: previewerAddress,
args: account ? [account] : undefined,
query: { enabled: !!account },
});
const { markets, refetch: refetchMarkets, isFetching: isFetchingPreviewer } = useMarkets();
const {
data: kycStatus,
isFetched: isKYCFetched,
Expand Down
10 changes: 2 additions & 8 deletions src/components/home/Portfolio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import { useRouter } from "expo-router";
import { ArrowLeft, CircleHelp } from "@tamagui/lucide-icons";
import { ScrollView, XStack } from "tamagui";

import { previewerAddress } from "@exactly/common/generated/chain";
import { useReadPreviewerExactly } from "@exactly/common/generated/hooks";

import AssetList from "./AssetList";
import { presentArticle } from "../../utils/intercom";
import openBrowser from "../../utils/openBrowser";
import reportError from "../../utils/reportError";
import useAccount from "../../utils/useAccount";
import useMarkets from "../../utils/useMarkets";
import usePortfolio from "../../utils/usePortfolio";
import SafeView from "../shared/SafeView";
import Text from "../shared/Text";
Expand All @@ -31,11 +29,7 @@ export default function Portfolio() {
} = useTranslation();
const { balanceUSD } = portfolio;

const { refetch: refetchMarkets, isFetching: isFetchingMarkets } = useReadPreviewerExactly({
address: previewerAddress,
args: address ? [address] : undefined,
query: { enabled: !!address },
});
const { refetch: refetchMarkets, isFetching: isFetchingMarkets } = useMarkets();

return (
<SafeView fullScreen backgroundColor="$backgroundMild">
Expand Down
10 changes: 2 additions & 8 deletions src/components/loans/Amount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ import { useQuery } from "@tanstack/react-query";
import { formatUnits } from "viem";
import { useBytecode } from "wagmi";

import { previewerAddress } from "@exactly/common/generated/chain";
import { useReadPreviewerExactly } from "@exactly/common/generated/hooks";

import AmountSelector from "./AmountSelector";
import { presentArticle } from "../../utils/intercom";
import queryClient from "../../utils/queryClient";
import reportError from "../../utils/reportError";
import useAccount from "../../utils/useAccount";
import useAsset from "../../utils/useAsset";
import useMarkets from "../../utils/useMarkets";
import SafeView from "../shared/SafeView";
import Button from "../shared/StyledButton";
import Text from "../shared/Text";
Expand All @@ -35,11 +33,7 @@ export default function Amount() {
i18n: { language },
} = useTranslation();
const { data: bytecode } = useBytecode({ address, query: { enabled: !!address } });
const { data: markets } = useReadPreviewerExactly({
address: previewerAddress,
args: address ? [address] : undefined,
query: { enabled: !!bytecode && !!address },
});
const { markets } = useMarkets({ enabled: !!bytecode });
const { data: loan } = useQuery<Loan>({ queryKey: ["loan"], enabled: !!address });
const { market, borrowAvailable } = useAsset(loan?.market);

Expand Down
12 changes: 2 additions & 10 deletions src/components/loans/Asset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ import { useRouter } from "expo-router";
import { ArrowLeft, ArrowRight, Check, CircleHelp } from "@tamagui/lucide-icons";
import { ScrollView, XStack, YStack } from "tamagui";

import { previewerAddress } from "@exactly/common/generated/chain";
import { useReadPreviewerExactly } from "@exactly/common/generated/hooks";

import { presentArticle } from "../../utils/intercom";
import queryClient, { type Loan } from "../../utils/queryClient";
import reportError from "../../utils/reportError";
import useAccount from "../../utils/useAccount";
import useMarkets from "../../utils/useMarkets";
import AssetLogo from "../shared/AssetLogo";
import Button from "../shared/Button";
import SafeView from "../shared/SafeView";
Expand All @@ -25,13 +22,8 @@ import type { Address } from "viem";
export default function Asset() {
const router = useRouter();
const { t } = useTranslation();
const { address } = useAccount();
const [selectedMarket, setSelectedMarket] = useState<Address>();
const { data: markets } = useReadPreviewerExactly({
address: previewerAddress,
args: address ? [address] : undefined,
query: { enabled: !!address },
});
const { markets } = useMarkets();
return (
<SafeView fullScreen>
<View
Expand Down
28 changes: 13 additions & 15 deletions src/components/loans/CreditLine.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useMemo } from "react";
import { useTranslation } from "react-i18next";

import { useRouter } from "expo-router";
Expand All @@ -9,13 +9,12 @@ import { Separator, XStack, YStack } from "tamagui";
import { formatUnits } from "viem";
import { useBytecode } from "wagmi";

import { marketUSDCAddress, previewerAddress } from "@exactly/common/generated/chain";
import { useReadPreviewerExactly } from "@exactly/common/generated/hooks";
import { marketUSDCAddress } from "@exactly/common/generated/chain";
import { borrowLimit } from "@exactly/lib";

import queryClient, { type Loan } from "../../utils/queryClient";
import useAccount from "../../utils/useAccount";
import useInstallments from "../../utils/useInstallments";
import useMarkets from "../../utils/useMarkets";
import AssetLogo from "../shared/AssetLogo";
import Button from "../shared/StyledButton";
import Text from "../shared/Text";
Expand All @@ -28,12 +27,7 @@ export default function CreditLine() {
i18n: { language },
} = useTranslation();
const { data: bytecode } = useBytecode({ address, query: { enabled: !!address } });
const { data: markets } = useReadPreviewerExactly({
address: previewerAddress,
args: address ? [address] : undefined,
query: { enabled: !!bytecode && !!address },
});
const { firstMaturity } = useInstallments({ totalAmount: 100n, installments: 1 });
const { markets, firstMaturity } = useMarkets({ enabled: !!bytecode });
return (
<YStack backgroundColor="$backgroundSoft" borderRadius="$s3">
<XStack padding="$s4">
Expand All @@ -59,11 +53,15 @@ export default function CreditLine() {
{t("Next due date:")}{" "}
</Text>
<Text primary footnote>
{new Date(firstMaturity * 1000).toLocaleDateString(language, {
year: "numeric",
month: "short",
day: "numeric",
})}
{useMemo(
() =>
new Date(firstMaturity * 1000).toLocaleDateString(language, {
year: "numeric",
month: "short",
day: "numeric",
}),
[firstMaturity, language],
)}
</Text>
</XStack>
<XStack alignItems="center" flexWrap="wrap">
Expand Down
20 changes: 10 additions & 10 deletions src/components/loans/LoanSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useBytecode } from "wagmi";

import { previewerAddress } from "@exactly/common/generated/chain";
import { useReadPreviewerPreviewBorrowAtMaturity } from "@exactly/common/generated/hooks";
import { MATURITY_INTERVAL, WAD } from "@exactly/lib";
import { WAD } from "@exactly/lib";

import useAccount from "../../utils/useAccount";
import useAsset from "../../utils/useAsset";
Expand All @@ -25,20 +25,21 @@ export default function LoanSummary({ loan }: { loan: Loan }) {
} = useTranslation();
const { address } = useAccount();
const { data: bytecode } = useBytecode({ address: previewerAddress, query: { enabled: !!address } });
const { market, isFetching: isMarketFetching } = useAsset(loan.market);
const { market, timestamp, isFetching: isMarketFetching } = useAsset(loan.market);
const symbol = market?.symbol.slice(3) === "WETH" ? "ETH" : market?.symbol.slice(3);
const isBorrow = loan.installments === 1;
const timestamp = useMemo(() => Math.floor(Date.now() / 1000), []);
const defaultMaturity = timestamp - (timestamp % MATURITY_INTERVAL) + MATURITY_INTERVAL;
const { data: installments, isFetching: isInstallmentsPending } = useInstallments({
timestamp: loan.maturity ? Number(loan.maturity) : defaultMaturity,
const {
data: installments,
firstMaturity,
isFetching: isInstallmentsPending,
} = useInstallments({
totalAmount: loan.amount ?? 0n,
installments: loan.installments ?? 1,
marketAddress: market?.market,
});
Comment thread
cruzdanilo marked this conversation as resolved.
const { data: borrow, isLoading: isBorrowPending } = useReadPreviewerPreviewBorrowAtMaturity({
address: previewerAddress,
args: loan.market && loan.amount ? [loan.market, loan.maturity ?? BigInt(defaultMaturity), loan.amount] : undefined,
args: loan.market && loan.amount ? [loan.market, loan.maturity ?? BigInt(firstMaturity), loan.amount] : undefined,
query: {
enabled: isBorrow && !!loan.amount && !!loan.market && !!address && !!bytecode,
},
Expand All @@ -48,10 +49,9 @@ export default function LoanSummary({ loan }: { loan: Loan }) {
const value =
!isBorrow && installments
? Number(installments.effectiveRate) / 1e18
: borrow && loan.amount && loan.amount > 0n && borrow.maturity > BigInt(timestamp)
: borrow && loan.amount && loan.amount > 0n && borrow.maturity > timestamp
? Number(
((borrow.assets - loan.amount) * WAD * 31_536_000n) /
(loan.amount * (borrow.maturity - BigInt(timestamp))),
((borrow.assets - loan.amount) * WAD * 31_536_000n) / (loan.amount * (borrow.maturity - timestamp)),
) / 1e18
: null;
return (
Expand Down
Loading
Loading