Skip to content

Commit

Permalink
🔄 synced file(s) with circlefin/pw-sample-app-internal (#16)
Browse files Browse the repository at this point in the history
synced local file(s) with
[circlefin/pw-sample-app-internal](https://github.com/circlefin/pw-sample-app-internal).



<details>
<summary>Changed files</summary>
<ul>
<li>synced local directory <code>app/</code> with remote directory
<code>app/</code></li><li>synced local directory <code>public/</code>
with remote directory <code>public/</code></li>
</ul>
</details>

---

This PR was created automatically by the
[repo-file-sync-action](https://github.com/BetaHuhn/repo-file-sync-action)
workflow run
[#10097212592](https://github.com/circlefin/pw-sample-app-internal/actions/runs/10097212592)
  • Loading branch information
circle-github-action-bot authored Aug 5, 2024
1 parent 13298a1 commit c504df2
Show file tree
Hide file tree
Showing 12 changed files with 308 additions and 94 deletions.
51 changes: 44 additions & 7 deletions app/(pages)/(authorized)/wallets/[id]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ import {
Tooltip,
} from "@mui/joy";
import { signOut } from "next-auth/react";
import { useRestorePinMutation, useWallet } from "@/app/axios";
import { useRestorePinMutation, useWallet, useWallets } from "@/app/axios";
import Image from "next/image";
import {
ArrowRightStartOnRectangleIcon,
Cog6ToothIcon,
EllipsisVerticalIcon,
PlusIcon,
QuestionMarkCircleIcon,
} from "@heroicons/react/16/solid";
import { useRouter } from "next/navigation";
import { blockchainNames } from "@/app/shared/types";

type WalletLayoutParams = {
/*
Expand All @@ -49,8 +53,10 @@ export default function WalletLayout({
children: React.ReactNode;
params: WalletLayoutParams;
}) {
const router = useRouter();
const { client } = useW3sContext();
const { data: wallet } = useWallet(params.id);
const { data: wallets } = useWallets();
const restorePin = useRestorePinMutation();

const blockchainInfo = blockchainMeta(wallet?.data.wallet.blockchain);
Expand Down Expand Up @@ -81,12 +87,16 @@ export default function WalletLayout({
<div className='flex p-5 justify-between items-center relative gap-x-4'>
<Tooltip title={blockchainInfo.testnet} placement='bottom-start'>
<IconButton>
<Image
alt='blockchain'
src={blockchainInfo.svg}
width={20}
height={20}
/>
{blockchainInfo.svg ? (
<Image
alt='blockchain'
src={blockchainInfo.svg}
width={20}
height={20}
/>
) : (
<QuestionMarkCircleIcon width={20} className='text-gray-400' />
)}
</IconButton>
</Tooltip>

Expand All @@ -108,6 +118,33 @@ export default function WalletLayout({
)}
</MenuButton>
<Menu placement='bottom-end' size='sm'>
{wallets?.data.wallets.map((wallet) => {
// hide currently selected wallet
if (wallet.id === params.id) return null;
return (
<MenuItem
key={wallet.id}
onClick={() => {
router.push(`/wallets/${wallet.id}`);
}}
>
<Image
src={blockchainMeta(wallet.blockchain).svg}
alt={`${wallet.blockchain}-icon`}
width={16}
height={16}
/>{" "}
{blockchainNames[wallet.blockchain]}
</MenuItem>
);
})}
<MenuItem
onClick={() => {
router.push("/wallets/create");
}}
>
<PlusIcon width={16} /> Create new wallet
</MenuItem>
<MenuItem onClick={handleChangePin}>
<Cog6ToothIcon width={16} /> Change Pin
</MenuItem>
Expand Down
137 changes: 137 additions & 0 deletions app/(pages)/(authorized)/wallets/create/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
"use client";

import { useCreateWallet, useWallets } from "@/app/axios";
import { BackButton, Content, useW3sContext } from "@/app/components";
import { BlockchainEnum, blockchainNames } from "@/app/shared/types";
import { blockchainMeta } from "@/app/shared/utils";
import { CheckIcon } from "@heroicons/react/16/solid";
import { Button, Radio, RadioGroup, Sheet, Typography } from "@mui/joy";
import Image from "next/image";
import { useRouter } from "next/navigation";
import { useEffect, useRef, useState } from "react";

export default function CreateWalletPage() {
const createWalletMutation = useCreateWallet();
const router = useRouter();
const { client } = useW3sContext();

const previousWalletsCount = useRef<number>(0); // Ref to hold the previous value

const [selected, setSelected] = useState<BlockchainEnum>();
const [loading, setLoading] = useState(false);

const walletsQuery = useWallets(
undefined,
createWalletMutation.status === "success" ? 1000 : undefined,
);

useEffect(() => {
// make sure first wallet is created.
if (
previousWalletsCount?.current > 0 &&
previousWalletsCount.current !== walletsQuery.data?.data.wallets.length
) {
router.push("/wallets");
}

previousWalletsCount.current = walletsQuery.data?.data.wallets.length ?? 0;
}, [router, walletsQuery.data?.data.wallets.length]);

const createLoading = createWalletMutation.isLoading || loading;

return (
<Content>
<nav className='pt-4'>
<BackButton onClick={() => router.push("/wallets")}>
<Typography level='title-md'>Create Wallet</Typography>
</BackButton>
</nav>
Select a chain to deploy your wallet
<RadioGroup
className='flex flex-col gap-y-2'
value={selected}
onChange={(e) => setSelected(e.currentTarget.value as BlockchainEnum)}
>
{[
BlockchainEnum.MATIC_AMOY,
BlockchainEnum.ETH_SEPOLIA,
BlockchainEnum.AVAX_FUJI,
BlockchainEnum.SOL_DEVNET,
].map((blockchain) => (
<Sheet
key={blockchain}
sx={{
borderRadius: "sm",
boxShadow: "none",
}}
>
<Radio
disabled={
createLoading ||
!!walletsQuery.data?.data.wallets.find(
(wallet) => wallet.blockchain === blockchain,
)
}
label={
<div className='w-full justify-between flex'>
<span className='flex items-center gap-x-2'>
<Image
alt={`${blockchain}-icon`}
src={blockchainMeta(blockchain).svg}
width={16}
height={16}
/>
{blockchainNames[blockchain]}
</span>
{selected === blockchain ? <CheckIcon width={16} /> : null}
</div>
}
value={blockchain}
disableIcon
className={`w-full p-2`}
slotProps={{
action({ checked }) {
return {
sx: {
border: "none",
borderRadius: "sm",
},
className: checked ? `bg-blue-100` : undefined,
};
},
}}
/>
</Sheet>
))}
</RadioGroup>
<div className='grow' />
{createLoading && (
<Typography level='body-xs' className='text-center'>
Please wait while we create your brand new wallet.
</Typography>
)}
<Button
disabled={!selected}
loading={createLoading}
onClick={async () => {
if (selected) {
const { data: challengeId } =
await createWalletMutation.mutateAsync({
blockchain: selected,
});

client?.execute(challengeId, (err) => {
setLoading(true);
if (err) {
setLoading(false);
return; // handle error
}
});
}
}}
>
Create Wallet
</Button>
</Content>
);
}
11 changes: 9 additions & 2 deletions app/axios/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

"use client";
import { axios } from "@/app/axios";
import { useQuery } from "react-query";
import { useMutation, useQuery } from "react-query";
import {
BlockchainEnum,
TokenBalance,
Wallet,
WalletBalancesInput,
Expand All @@ -26,7 +27,7 @@ import {

const walletBalanceHelper = async (
id: string,
params?: WalletBalancesInput
params?: WalletBalancesInput,
) => {
return axios.get<{
tokenBalances: TokenBalance[];
Expand Down Expand Up @@ -74,3 +75,9 @@ export const useWallet = (id: string) => {
queryFn: () => walletHelper(id),
});
};

export const useCreateWallet = () => {
return useMutation((input: { blockchain: BlockchainEnum }) => {
return axios.post<string>(`/wallets`, input);
});
};
10 changes: 5 additions & 5 deletions app/components/Cards/TokenCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ export const TokenCard: React.FC<TokenCardProps> = ({
className={`rounded-lg bg-white ${onClick ? "cursor-pointer hover:bg-slate-50 transition-all" : ""}`}
onClick={onClick}
>
<CardContent className="flex flex-row gap-6">
<CardContent className='flex flex-row gap-6'>
{tokenMeta.svg !== "" ? (
<Image
alt="token"
alt='token'
height={36}
width={36}
src={tokenMeta.svg}
className="my-auto"
className='my-auto'
/>
) : (
<ExclamationCircleIcon width={40} height={40} />
)}
<div>
<Typography level="body-md">{tokenMeta.name}</Typography>
<Typography level='body-md'>{tokenMeta.name}</Typography>

<Typography level="body-sm">{`${amount} ${tokenMeta.name}`}</Typography>
<Typography level='body-sm'>{`${amount} ${tokenMeta.name}`}</Typography>
</div>
</CardContent>
</Card>
Expand Down
7 changes: 4 additions & 3 deletions app/containers/Wallets/Send/SendTokenSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ import Image from "next/image";
import { formatDate, tokenHelper } from "@/app/shared/utils";
import { Button } from "@mui/joy";
import { Content, CopyButton, useSendTokenContext } from "@/app/components";
import { useRouter } from "next/navigation";
import { useParams, useRouter } from "next/navigation";
import { useMemo } from "react";
import { BlockchainEnum, blockchainNames } from "@/app/shared/types";
import { TextField } from "@/app/components/TextField";

export const SendTokenSummary: React.FC = () => {
const { tokenName, tokenAndRecipient } = useSendTokenContext();
const router = useRouter();
const params = useParams();

const imageSymbol = tokenHelper(tokenName);
const router = useRouter();
const date = useMemo(() => new Date(), []);
return (
<>
Expand Down Expand Up @@ -63,7 +64,7 @@ export const SendTokenSummary: React.FC = () => {
className='w-full'
variant='solid'
onClick={() => {
router.push("/wallets");
router.push(`/wallets/${params.id}`);
}}
>
Go to home
Expand Down
14 changes: 7 additions & 7 deletions app/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export type WalletsInput = {
export type Wallet = {
id: string;
address: string;
blockchain: string;
blockchain: BlockchainEnum | string;
createDate: Date;
custodyType: string;
accountType?: AccountType;
Expand Down Expand Up @@ -161,25 +161,25 @@ export enum CustodyTypeEnum {
}

export enum BlockchainEnum {
ETH_GOERLI = "ETH-GOERLI",
ETH_SEPOLIA = "ETH-SEPOLIA",
ETH = "ETH",
AVAX_FUJI = "AVAX-FUJI",
AVAX = "AVAX",
MATIC_MUMBAI = "MATIC-MUMBAI",
MATIC_AMOY = "MATIC-AMOY",
MATIC = "MATIC",
SOL_DEVNET = "SOL-DEVNET",
SOL = "SOL",
}

export const blockchainNames = {
[BlockchainEnum.ETH_GOERLI]: "Ethereum Goerli",
export const blockchainNames: Record<BlockchainEnum | string, string> = {
[BlockchainEnum.ETH_SEPOLIA]: "Ethereum Sepolia",
[BlockchainEnum.ETH]: "Ethereum",
[BlockchainEnum.AVAX_FUJI]: "Avalanche Fuji",
[BlockchainEnum.AVAX]: "Avalanche",
[BlockchainEnum.MATIC_MUMBAI]: "Polygon Mumbai",
[BlockchainEnum.MATIC_AMOY]: "Polygon Amoy",
[BlockchainEnum.MATIC]: "Polygon",
[BlockchainEnum.SOL]: "Solana",
[BlockchainEnum.SOL_DEVNET]: "Solana Devnet",
"": "Unknown blockchain",
};

Expand All @@ -193,7 +193,7 @@ export type EstimateFeeInput = {
export type GasFeeObject = {
gasLimit: string;
gasPrice: string;
maxFee: string;
maxFee?: string;
priorityFee: string;
};

Expand Down
Loading

0 comments on commit c504df2

Please sign in to comment.