Skip to content

Commit

Permalink
wip: Improve UX
Browse files Browse the repository at this point in the history
  • Loading branch information
carina-akaia committed Jun 22, 2024
1 parent 019cb54 commit 1964e6a
Show file tree
Hide file tree
Showing 17 changed files with 1,230 additions and 820 deletions.
24 changes: 3 additions & 21 deletions src/app/_layout/Nav.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"use client";

import { useCallback, useState } from "react";
import { useState } from "react";

import Image from "next/image";
import Link from "next/link";
import { usePathname } from "next/navigation";

import { walletApi } from "@/common/contracts";
import useIsClient from "@/common/lib/useIsClient";
import { Button } from "@/common/ui/components";
import { SignInButton } from "@/modules/auth";
import { useAuth } from "@/modules/auth/hooks/useAuth";
import routesPath from "@/modules/core/routes";

Expand Down Expand Up @@ -37,26 +36,9 @@ const AuthButton = () => {
const { isAuthenticated } = useAuth();
const isClient = useIsClient();

const loginHandler = useCallback(() => {
walletApi.signInModal();
}, []);

if (!isClient) return;

if (isAuthenticated) {
return <UserDropdown />;
}

return (
<Button
font="semibold"
variant="standard-filled"
onClick={loginHandler}
className="border-none bg-[#342823] shadow-none"
>
Sign In
</Button>
);
return isAuthenticated ? <UserDropdown /> : <SignInButton />;
};

const MobileMenuButton = ({ onClick }: { onClick: () => void }) => {
Expand Down
52 changes: 28 additions & 24 deletions src/common/api/pagoda/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,55 @@ import { AccountId, ByAccountId } from "@/common/types";

import { swrHooks } from "./generated";

export const useNearAccountBalance = ({ accountId }: ByAccountId) => {
const queryResult = swrHooks.useGetAccountsAccountIdBalancesNEAR(
accountId,
undefined,
PAGODA_REQUEST_CONFIG,
);

return { ...queryResult, data: queryResult.data?.data };
};

export const useFtAccountBalances = ({ accountId }: ByAccountId) => {
const queryResult = swrHooks.useGetAccountsAccountIdBalancesFT(
accountId,
undefined,
PAGODA_REQUEST_CONFIG,
);

return { ...queryResult, data: queryResult.data?.data };
};

export type TokenMetadataInputs = {
/**
* Either "NEAR" or FT contract account id.
*/
tokenId: "near" | AccountId;
disabled?: boolean;
};

export const useTokenMetadata = ({ tokenId }: TokenMetadataInputs) => {
export const useTokenMetadata = ({
tokenId,
disabled = false,
}: TokenMetadataInputs) => {
const nearQueryResult = swrHooks.useGetAccountsAccountIdBalancesNEAR(
walletApi.accountId ?? "unknown",
undefined,

{
...PAGODA_REQUEST_CONFIG,
swr: { enabled: tokenId === NEAR_TOKEN_DENOM },
swr: { enabled: !disabled && tokenId === NEAR_TOKEN_DENOM },
},
);

const ftQueryResult = swrHooks.useGetNep141MetadataContractAccountId(
walletApi.accountId ?? "unknown",
tokenId,
undefined,

{
...PAGODA_REQUEST_CONFIG,
swr: { enabled: tokenId !== NEAR_TOKEN_DENOM },
swr: { enabled: !disabled && tokenId !== NEAR_TOKEN_DENOM },
},
);

Expand All @@ -41,23 +65,3 @@ export const useTokenMetadata = ({ tokenId }: TokenMetadataInputs) => {
: ftQueryResult.data?.data.metadata,
};
};

export const useNearAccountBalance = ({ accountId }: ByAccountId) => {
const queryResult = swrHooks.useGetAccountsAccountIdBalancesNEAR(
accountId,
undefined,
PAGODA_REQUEST_CONFIG,
);

return { ...queryResult, data: queryResult.data?.data };
};

export const useFtAccountBalances = ({ accountId }: ByAccountId) => {
const queryResult = swrHooks.useGetAccountsAccountIdBalancesFT(
accountId,
undefined,
PAGODA_REQUEST_CONFIG,
);

return { ...queryResult, data: queryResult.data?.data };
};
Loading

0 comments on commit 1964e6a

Please sign in to comment.