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

Feature/refine trustline management features #46

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
32 changes: 9 additions & 23 deletions src/app/assets/[param]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
"use client";
import { AssetActionPanel } from "@/components/Assets/AssetActionPanel";
import { AssetCard } from "@/components/Assets/AssetCard";
import { ManageTrustlineButton } from "@/components/Buttons/ManageTrustlineButton";
import { CommingSoon } from "@/components/DisabledComponents/CommingSoon";
import { ConnectWalletToUse } from "@/components/DisabledComponents/ConnectWalletToUse";
import { isAddress, isCodeIssuerPair, shortenAddress } from "@/helpers/address";
import { UseAssetProps, useAsset } from "@/hooks/useAsset";
import {
UseAssetInformationProps,
useAssetInformation,
} from "@/hooks/useAssetInformation";
import { useClipboard } from "@/hooks/useClipboard";
import {
Box,
VStack,
Link,
Button,
Text,
Skeleton,
Stack,
Card,
Grid,
useMediaQuery,
GridItem,
Tabs,
TabList,
Tab,
TabPanels,
TabPanel,
HStack,
SimpleGrid,
Tooltip,
} from "@chakra-ui/react";
import { AssetActionPanel } from "@/components/Assets/AssetActionPanel";
import { AssetCard } from "@/components/Assets/AssetCard";
import { isAddress, isCodeIssuerPair } from "@/helpers/address";
import { UseAssetProps, useAsset } from "@/hooks/useAsset";
import {
UseAssetInformationProps,
useAssetInformation,
} from "@/hooks/useAssetInformation";
import { useClipboard } from "@/hooks/useClipboard";
import { useParams } from "next/navigation";
import { Asset as AssetType } from "@stellar-asset-lists/sdk";
import { DexPoolTable } from "@/components/Assets/pools/DexPoolTable";
Expand Down
56 changes: 49 additions & 7 deletions src/components/Buttons/ManageTrustlineButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import {
useToast,
Spinner,
Icon,
UnorderedList,
ListItem,
HStack,
} from "@chakra-ui/react";
import { Asset as AssetType } from "@stellar-asset-lists/sdk";
import { useAssetForAccount } from "@/hooks/useAsset";
Expand Down Expand Up @@ -43,10 +46,18 @@ export function ManageTrustlineButton({ asset }: ManageTrustlineProps) {
const [newLimit, setNewLimit] = useState("");
const [submittingTx, setSubmittingTx] = useState<boolean>(false);
const { account } = useAccount();
const haveBalance = assetForAccount?.balance
? Number(assetForAccount?.balance) !== 0
: false;

const handleLimitChange = (event: React.ChangeEvent<HTMLInputElement>) =>
setNewLimit(event.target.value);

const handleRevokeChange = () => {
setNewLimit("0");
handleSubmit();
};

const handleSubmit = async () => {
if (!asset || !account) return;
if (Number(newLimit) < Number(assetForAccount?.balance)) {
Expand Down Expand Up @@ -145,7 +156,12 @@ export function ManageTrustlineButton({ asset }: ManageTrustlineProps) {
<Modal
isOpen={isOpen}
onClose={
submittingTx ? () => console.log("submitting tx cant close") : onClose
submittingTx
? () => console.log("submitting tx cant close")
: () => {
onClose();
setNewLimit("");
}
}
size={"md"}
isCentered
Expand All @@ -155,12 +171,26 @@ export function ManageTrustlineButton({ asset }: ManageTrustlineProps) {
<ModalHeader>Adjust Trustline</ModalHeader>
<ModalCloseButton />
<ModalBody>
<VStack alignItems="baseline" mb={5}>
<Text letterSpacing={0.5} color="gray">
CURRENT LIMIT
</Text>
<Text fontWeight="bold">
{assetForAccount?.limit || "NOT SET"}
</Text>
</VStack>
<VStack spacing={4}>
<Text>Current limit: {assetForAccount?.limit || "Not set"}</Text>
<Text fontSize="sm" color="gray.500">
Enter a new limit for your trustline. Setting the limit to 0
will revoke the trustline. Note that the limit cannot be lower
than your current balance ({assetForAccount?.balance ?? 0}).
<UnorderedList>
<ListItem>
Enter a new limit for your trustline. Setting the limit to 0
will revoke the trustline.
</ListItem>
<ListItem>
Note that the limit cannot be lower than your current
balance ({assetForAccount?.balance ?? 0}).
</ListItem>
</UnorderedList>
</Text>
<Input
placeholder="New limit"
Expand All @@ -169,8 +199,20 @@ export function ManageTrustlineButton({ asset }: ManageTrustlineProps) {
/>
</VStack>
</ModalBody>
<ModalFooter>
<Button disabled={submittingTx} onClick={handleSubmit}>
<ModalFooter gap={5}>
<Button
isDisabled={!haveBalance || submittingTx}
onClick={handleRevokeChange}
variant="outline"
colorScheme="blue"
>
{submittingTx ? <Spinner /> : "Revoke Trustline"}
</Button>
<Button
isDisabled={submittingTx}
onClick={handleSubmit}
colorScheme="blue"
>
{submittingTx ? <Spinner /> : "Update Trustline"}
</Button>
</ModalFooter>
Expand Down