diff --git a/src/api/services/queries/ledger.ts b/src/api/services/queries/ledger.ts index d35e546..aafc5e9 100644 --- a/src/api/services/queries/ledger.ts +++ b/src/api/services/queries/ledger.ts @@ -29,10 +29,10 @@ export function useTokenInfo(neighborhood: Network | undefined) { return useQueries({ queries: tokenList ? [...tokenList.symbols.entries()].map(([address]) => ({ - queryKey: [neighborhood?.url, "tokens.info", address], - queryFn: async () => await neighborhood?.tokens.info({ address }), - enabled: !!neighborhood, - })) + queryKey: [neighborhood?.url, "tokens.info", address], + queryFn: async () => await neighborhood?.tokens.info({ address }), + enabled: !!neighborhood, + })) : [], }); } @@ -42,27 +42,29 @@ export function useCreateToken(neighborhood: Network | undefined) { return useMutation( async ({ - address, amount, + destination, name, - symbol, + owner, precision = 9, + symbol, }: { - address: string; amount: string; + destination: string; name: string; - symbol: string; + owner: string; precision?: number; + symbol: string; }) => await neighborhood?.tokens.create({ summary: { name, symbol: symbol.toUpperCase(), - precision: 9, + precision, }, - owner: address, + owner, distribution: { - [address]: BigInt(parseInt(amount) * 10 ** precision), + [destination]: BigInt(parseInt(amount) * 10 ** precision), }, }), { diff --git a/src/pages/services/ledger/create-token-modal.tsx b/src/pages/services/ledger/create-token-modal.tsx index a505e7c..11d92f4 100644 --- a/src/pages/services/ledger/create-token-modal.tsx +++ b/src/pages/services/ledger/create-token-modal.tsx @@ -8,28 +8,22 @@ import { FormLabel, Grid, GridItem, - HStack, - Icon, Input, Modal, - Popover, - PopoverBody, - PopoverContent, - PopoverTrigger, useToast, } from "@liftedinit/ui"; import { NeighborhoodContext } from "api/neighborhoods"; import { useCreateToken } from "api/services"; import { useAccountsStore } from "features/accounts"; -import { useContext } from "react"; +import { useContext, useEffect } from "react"; import { Controller, SubmitHandler, useForm } from "react-hook-form"; -import { FiInfo } from "react-icons/fi"; export interface CreateTokenInputs { + amount: string; + destination: string; name: string; + owner: string; symbol: string; - amount: string; - address: string; } export function CreateTokenModal({ @@ -46,22 +40,28 @@ export function CreateTokenModal({ isError, isLoading, } = useCreateToken(neighborhood); + const account = useAccountsStore((s) => s.byId.get(s.activeId)); + const address = account?.address ?? ""; const { control, formState: { errors }, + reset, handleSubmit, - } = useForm(); - const account = useAccountsStore((s) => s.byId.get(s.activeId)); - const address = account?.address ?? ""; + } = useForm({ + defaultValues: { destination: address }, + }); + useEffect(() => reset({ destination: address }), [address, reset]); const toast = useToast(); const onSubmit: SubmitHandler = ({ + amount, + destination, name, + owner, symbol, - amount, }) => { doCreateToken( - { name, symbol, amount, address }, + { amount, destination, name, owner, symbol }, { onSuccess: () => { onClose(); @@ -148,22 +148,24 @@ export function CreateTokenModal({ - - - Destination Address - - - - - - - The destination address is the current user and cannot be - changed at this time. - - - - - + + Destination Address + new RegExp(/^m\w{24,}$/).test(v), + }, + }} + render={({ field }) => } + /> + {errors.destination && ( + + Must be a valid Many address. + + )}