Skip to content

Commit

Permalink
Adapt to new transfer Torii query in activity page
Browse files Browse the repository at this point in the history
  • Loading branch information
JunichiSugiura committed Nov 19, 2024
1 parent 6c8232b commit 8a7a7a2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
38 changes: 22 additions & 16 deletions packages/profile/src/components/activity.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Card, CardContent, CheckIcon, CopyAddress } from "@cartridge/ui-next";
import { useTransferQuery } from "@cartridge/utils/api/indexer";
import { useTokenTransfersQuery } from "@cartridge/utils/api/indexer";
import {
LayoutContainer,
LayoutContent,
Expand All @@ -10,10 +10,7 @@ import { useAccount } from "@/hooks/account";

export function Activity() {
const { address, username } = useAccount();
const { data } = useTransferQuery({
address,
limit: 100,
});
const { data } = useTokenTransfersQuery({ address });

return (
<LayoutContainer>
Expand All @@ -24,18 +21,27 @@ export function Activity() {
/>

<LayoutContent>
{data?.ercTransfer ? (
{data?.tokenTransfers?.edges ? (
<Card>
{data.ercTransfer.map((t) => (
<CardContent className="flex items-center gap-1">
<CheckIcon size="sm" />
<div>
Send{" "}
{Number(t.amount) / 10 ** Number(t.token_metadata?.decimals)}{" "}
{t.token_metadata?.symbol}
</div>
</CardContent>
))}
{data.tokenTransfers.edges.map(({ node: t }) => {
switch (t.tokenMetadata.__typename) {
case "ERC20__Token": {
return (
<CardContent className="flex items-center gap-1">
<CheckIcon size="sm" />
<div>
Send{" "}
{Number(t.tokenMetadata.amount) /
10 ** Number(t.tokenMetadata?.decimals)}{" "}
{t.tokenMetadata?.symbol}
</div>
</CardContent>
);
}
case "ERC721__Token":
return null;
}
})}
</Card>
) : (
<Card>
Expand Down
8 changes: 3 additions & 5 deletions packages/profile/src/components/inventory/token/send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export function SendToken() {
const { address } = useAccount();
const { parent } = useConnection();
const t = useToken({ tokenAddress: tokenAddress! });
console.log(t?.balance);

const formSchema = useMemo(() => {
// Avoid scientific notation in error message (e.g. `parseFloat(`1e-${decimals}`).toString() === "1e-18"`)
Expand Down Expand Up @@ -67,10 +66,9 @@ export function SendToken() {
.gte(parseFloat(minAmountStr), {
message: `Amount must be at least ${minAmountStr} ${t?.meta.symbol}`,
})
.refine(
(x) => BigInt((x * 10) ^ decimals) <= (t?.balance.value ?? 0n),
{ message: "Amount cannot exceed balance" },
),
.refine((x) => BigInt(x * 10 ** decimals) <= (t?.balance.value ?? 0n), {
message: "Amount cannot exceed balance",
}),
});
}, [t]);

Expand Down
1 change: 1 addition & 0 deletions packages/utils/bin/post-graphql-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ fs.readFile(indexerPath, "utf8", (err: Error, data: string) => {
if (err) {
return console.log(err);
}
// Suppress unused variable error from tsc in generated file
const res = data.replace(/, QueryFunctionContext /g, "");

fs.writeFile(indexerPath, res, "utf8", (err: Error) => {
Expand Down
16 changes: 8 additions & 8 deletions packages/utils/src/api/indexer/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ scalar Cursor

type World__PageInfo {
endCursor: Cursor
hasNextPage: Boolean
hasPreviousPage: Boolean
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: Cursor
}

Expand Down Expand Up @@ -53,14 +53,14 @@ type EventNode {
}

type Token__BalanceConnection {
edges: [Token__BalanceEdge]
edges: [Token__BalanceEdge!]!
pageInfo: World__PageInfo!
totalCount: Int!
}

type Token__BalanceEdge {
cursor: Cursor
node: Token__Balance
cursor: Cursor!
node: Token__Balance!
}

type Token__Balance {
Expand Down Expand Up @@ -90,14 +90,14 @@ type ERC721__Token {
}

type Token__TransferConnection {
edges: [Token__TransferEdge]
edges: [Token__TransferEdge!]!
pageInfo: World__PageInfo!
totalCount: Int!
}

type Token__TransferEdge {
cursor: Cursor
node: Token__Transfer
cursor: Cursor!
node: Token__Transfer!
}

type Token__Transfer {
Expand Down

0 comments on commit 8a7a7a2

Please sign in to comment.