Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysu committed Jan 23, 2025
1 parent f57c915 commit 745c9e0
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const Default: Story = {
name: 'My Wallet',
address: '0xc9758de68b17837dadf51616ac77d634bca848d5',
blockchain: Blockchain.MaticAmoy,
accountType: 'EOA',
updateDate: '2024-12-09T14:38:51Z',
createDate: '2024-12-09T14:38:51Z',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { FormErrorText } from '~/components/FormErrorText';
import { Button } from '~/components/ui/button';
import { Input } from '~/components/ui/input';
import { Textarea } from '~/components/ui/textarea';
import { FeeLevel } from '~/lib/constants';
import { CircleError, ErrorResponse } from '~/lib/responses';
import { isAddress, isNumber } from '~/lib/utils';

Expand Down Expand Up @@ -80,7 +79,7 @@ export function SendTransactionForm({
fee: {
type: 'level',
config: {
feeLevel: FeeLevel.Medium,
feeLevel: 'MEDIUM',
},
},
} as CreateTransactionInput);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Database, LayoutDashboard } from 'lucide-react';
import React from 'react';

import { DarkModeToggle } from '~/components/DarkModeToggle';
import { WalletSet } from '~/lib/types';
import { ElementsWalletSet } from '~/lib/types';

import circleLogoWhite from './circle-logo-white.svg';
import circleLogo from './circle-logo.svg';
Expand Down Expand Up @@ -33,7 +33,7 @@ function SidebarNavLink({ to, icon, label }: SidebarNavLinkProps) {
}

export interface SidebarProps {
walletSets: WalletSet[];
walletSets: ElementsWalletSet[];
}

export function Sidebar({ walletSets = [] }: SidebarProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { useMemo } from 'react';
import { Badge } from '~/components/ui/badge';
import { Button } from '~/components/ui/button';
import { shortenAddress } from '~/lib/format';
import { Wallet } from '~/lib/types';
import { ElementsWallet } from '~/lib/types';

export interface WalletDetailsProps {
/** The wallet associated with the on-chain account */
wallet: Wallet;
wallet: ElementsWallet;
/** Child components to associate with the wallet */
children?: React.ReactNode;
/** Copy the wallet address to the clipboard */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Badge } from '~/components/ui/badge';
import { formatDate } from '~/lib/format';
import { WalletSet } from '~/lib/types';
import { ElementsWalletSet } from '~/lib/types';

export interface WalletSetDetailsProps {
/** The wallet set */
walletSet: WalletSet;
walletSet: ElementsWalletSet;
/** Child components to associate with the wallet set */
children?: React.ReactNode;
}
Expand Down
9 changes: 4 additions & 5 deletions packages/circle-demo-webapp/app/hooks/useToast.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use client';

// Inspired by react-hot-toast library
import * as React from 'react';
import { useEffect, useState } from 'react';

import type { ToastActionElement, ToastProps } from '~/components/ui/toast';

Expand Down Expand Up @@ -140,7 +139,7 @@ function dispatch(action: Action) {

type Toast = Omit<ToasterToast, 'id'>;

function toast({ ...props }: Toast) {
function toast(props: Toast) {
const id = genId();

const update = (props: ToasterToast) =>
Expand Down Expand Up @@ -170,9 +169,9 @@ function toast({ ...props }: Toast) {
}

function useToast() {
const [state, setState] = React.useState<State>(memoryState);
const [state, setState] = useState<State>(memoryState);

React.useEffect(() => {
useEffect(() => {
listeners.push(setState);
return () => {
const index = listeners.indexOf(setState);
Expand Down
14 changes: 0 additions & 14 deletions packages/circle-demo-webapp/app/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
export const TestnetBlockchain = {
ArbSepolia: 'ARB-SEPOLIA',
AvaxFuji: 'AVAX-FUJI',
EthSepolia: 'ETH-SEPOLIA',
MaticAmoy: 'MATIC-AMOY',
SolDevnet: 'SOL-DEVNET',
UniSepolia: 'UNI-SEPOLIA',
} as const;

export const Blockchain = {
Arb: 'ARB',
Avax: 'AVAX',
Expand All @@ -28,11 +19,6 @@ export const TransactionType = {
Inbound: 'INBOUND',
Outbound: 'OUTBOUND',
};
export const FeeLevel = {
High: 'HIGH',
Medium: 'MEDIUM',
Low: 'LOW',
} as const;

export const TransactionState = {
Cancelled: 'CANCELLED',
Expand Down
6 changes: 3 additions & 3 deletions packages/circle-demo-webapp/app/lib/memcache.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Token } from '@circle-fin/developer-controlled-wallets';

import { sdk } from '~/lib/sdk';
import { WalletSet } from '~/lib/types';
import { ElementsWalletSet } from '~/lib/types';

class MemCache<ReturnType extends { id: string }> {
private map: Map<string, ReturnType>;
Expand Down Expand Up @@ -65,9 +65,9 @@ export const cachedCoins = new MemCache<Token>({
},
});

export const cachedWalletSets = new MemCache<WalletSet>({
export const cachedWalletSets = new MemCache<ElementsWalletSet>({
loadAllFunction: async () => {
const resp = await sdk.listWalletSets();
return resp?.data?.walletSets as WalletSet[];
return resp?.data?.walletSets as ElementsWalletSet[];
},
});
24 changes: 5 additions & 19 deletions packages/circle-demo-webapp/app/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,19 @@
/**
* Request types
*/
import type {
Blockchain,
Token,
TransactionType,
} from '@circle-fin/developer-controlled-wallets';
import type { Token } from '@circle-fin/developer-controlled-wallets';
import type {
Transaction,
Wallet as SdkWallet,
WalletSet as SdkWalletSet,
Wallet,
WalletSet,
} from '@circle-fin/developer-controlled-wallets/dist/types/clients/developer-controlled-wallets';

import { TestnetBlockchain } from '~/lib/constants';

export type TypeBlockchain = (typeof Blockchain)[keyof typeof Blockchain];
export type TypeTestnetBlockchain =
(typeof TestnetBlockchain)[keyof typeof TestnetBlockchain];
export type TypeTransactionType = (typeof TransactionType)[keyof typeof TransactionType];

export interface TransactionWithToken extends Transaction {
token?: Token;
}

export interface WalletSet extends SdkWalletSet {
export interface ElementsWalletSet extends WalletSet {
name?: string;
custodyType?: string;
}

export interface Wallet extends SdkWallet {
export interface ElementsWallet extends Wallet {
accountType?: string;
}
6 changes: 3 additions & 3 deletions packages/circle-demo-webapp/app/routes/api.faucet.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TestnetBlockchain } from '@circle-fin/developer-controlled-wallets';
import { ActionFunctionArgs } from '@remix-run/node';

import { sdk } from '~/lib/sdk';
Expand All @@ -6,11 +7,10 @@ import {
errorResponse,
successResponse,
} from '~/lib/server.responses';
import { TypeTestnetBlockchain } from '~/lib/types';
import { isValidString } from '~/lib/utils';

interface RequestBody {
blockchain: string;
blockchain: TestnetBlockchain;
address: string;
}

Expand All @@ -27,7 +27,7 @@ export async function action({ request }: ActionFunctionArgs) {

try {
await sdk.requestTestnetTokens({
blockchain: blockchain as TypeTestnetBlockchain,
blockchain: blockchain,
address,
native: true,
usdc: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
DialogTitle,
DialogTrigger,
} from '~/components/ui/dialog';
import { WalletSet } from '~/lib/types';
import { ElementsWalletSet } from '~/lib/types';

import { EditWalletSetForm } from './EditWalletSetForm';

interface EditWalletSetDialogProps {
walletSet: WalletSet;
walletSet: ElementsWalletSet;
onSuccess?: () => void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { FormEvent } from 'react';
import { Button } from '~/components/ui/button';
import { Input } from '~/components/ui/input';
import { useUpdateWalletSet } from '~/hooks/useUpdateWalletSet';
import { WalletSet } from '~/lib/types';
import { ElementsWalletSet } from '~/lib/types';

interface EditWalletSetFormProps {
walletSet: WalletSet;
walletSet: ElementsWalletSet;
onSuccess?: () => void;
}

Expand Down
8 changes: 4 additions & 4 deletions packages/circle-demo-webapp/app/routes/wallets.$id/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { WalletDetails } from '~/components/WalletDetails';
import { useToast } from '~/hooks/useToast';
import { formatDate } from '~/lib/format';
import { sdk } from '~/lib/sdk';
import { Wallet, WalletSet } from '~/lib/types';
import { ElementsWallet, ElementsWalletSet } from '~/lib/types';

import { EditWalletSetDialog } from './components/EditWalletSetDialog';
import { NewWalletDialog } from './components/NewWalletDialog';
Expand All @@ -27,13 +27,13 @@ export async function loader({ params }: { params: { id: string } }) {

return {
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
wallets: walletsResp?.data?.wallets! as Wallet[],
wallets: walletsResp?.data?.wallets! as ElementsWallet[],
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
walletSet: walletSetResp?.data?.walletSet! as WalletSet,
walletSet: walletSetResp?.data?.walletSet! as ElementsWalletSet,
};
}

function Header({ walletSet }: { walletSet: WalletSet }) {
function Header({ walletSet }: { walletSet: ElementsWalletSet }) {
const revalidator = useRevalidator();

const revalidate = () => {
Expand Down

0 comments on commit 745c9e0

Please sign in to comment.