From 6c4d06249587804fbf8ee373840d238de3fd5fc5 Mon Sep 17 00:00:00 2001 From: Stanley Jones Date: Thu, 10 Aug 2023 10:08:41 -0700 Subject: [PATCH 1/5] feat: Allow arbitrary destination address for token creation --- .../services/ledger/create-token-modal.tsx | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/pages/services/ledger/create-token-modal.tsx b/src/pages/services/ledger/create-token-modal.tsx index a505e7c..32db642 100644 --- a/src/pages/services/ledger/create-token-modal.tsx +++ b/src/pages/services/ledger/create-token-modal.tsx @@ -8,14 +8,8 @@ import { FormLabel, Grid, GridItem, - HStack, - Icon, Input, Modal, - Popover, - PopoverBody, - PopoverContent, - PopoverTrigger, useToast, } from "@liftedinit/ui"; import { NeighborhoodContext } from "api/neighborhoods"; @@ -23,7 +17,6 @@ import { useCreateToken } from "api/services"; import { useAccountsStore } from "features/accounts"; import { useContext } from "react"; import { Controller, SubmitHandler, useForm } from "react-hook-form"; -import { FiInfo } from "react-icons/fi"; export interface CreateTokenInputs { name: string; @@ -71,7 +64,7 @@ export function CreateTokenModal({ description: "Token was created", }); }, - } + }, ); }; @@ -148,22 +141,26 @@ 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.address && ( + + Must be a valid Many address. + + )} From 9854bbb245286c325c166cd837d9c21a67aa3533 Mon Sep 17 00:00:00 2001 From: Stanley Jones Date: Thu, 31 Aug 2023 10:08:49 -0700 Subject: [PATCH 2/5] fix: Sending correct distribution param --- src/api/services/queries/ledger.ts | 22 +++++++++---------- .../services/ledger/create-token-modal.tsx | 19 ++++++++-------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/api/services/queries/ledger.ts b/src/api/services/queries/ledger.ts index d35e546..c7f7f1d 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,27 @@ export function useCreateToken(neighborhood: Network | undefined) { return useMutation( async ({ - address, amount, name, - symbol, + owner, precision = 9, + symbol, }: { - address: string; amount: 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), + [owner]: 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 32db642..a23ea14 100644 --- a/src/pages/services/ledger/create-token-modal.tsx +++ b/src/pages/services/ledger/create-token-modal.tsx @@ -19,10 +19,10 @@ import { useContext } from "react"; import { Controller, SubmitHandler, useForm } from "react-hook-form"; export interface CreateTokenInputs { + amount: string; name: string; + owner: string; symbol: string; - amount: string; - address: string; } export function CreateTokenModal({ @@ -49,12 +49,13 @@ export function CreateTokenModal({ const toast = useToast(); const onSubmit: SubmitHandler = ({ + amount, name, + owner, symbol, - amount, }) => { doCreateToken( - { name, symbol, amount, address }, + { amount, name, owner, symbol }, { onSuccess: () => { onClose(); @@ -64,7 +65,7 @@ export function CreateTokenModal({ description: "Token was created", }); }, - }, + } ); }; @@ -141,10 +142,10 @@ export function CreateTokenModal({ - - Destination Address + + Owner )} /> - {errors.address && ( + {errors.owner && ( Must be a valid Many address. From 170aece01a929fad1fbe18d4bc1ac58b0aaa04ac Mon Sep 17 00:00:00 2001 From: Stanley Jones Date: Thu, 31 Aug 2023 13:33:40 -0700 Subject: [PATCH 3/5] fix: Can only change destination address, not owner --- src/api/services/queries/ledger.ts | 4 +++- src/pages/services/ledger/create-token-modal.tsx | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/api/services/queries/ledger.ts b/src/api/services/queries/ledger.ts index c7f7f1d..aafc5e9 100644 --- a/src/api/services/queries/ledger.ts +++ b/src/api/services/queries/ledger.ts @@ -43,12 +43,14 @@ export function useCreateToken(neighborhood: Network | undefined) { return useMutation( async ({ amount, + destination, name, owner, precision = 9, symbol, }: { amount: string; + destination: string; name: string; owner: string; precision?: number; @@ -62,7 +64,7 @@ export function useCreateToken(neighborhood: Network | undefined) { }, owner, distribution: { - [owner]: 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 a23ea14..789c3da 100644 --- a/src/pages/services/ledger/create-token-modal.tsx +++ b/src/pages/services/ledger/create-token-modal.tsx @@ -20,6 +20,7 @@ import { Controller, SubmitHandler, useForm } from "react-hook-form"; export interface CreateTokenInputs { amount: string; + destination: string; name: string; owner: string; symbol: string; @@ -50,12 +51,13 @@ export function CreateTokenModal({ const onSubmit: SubmitHandler = ({ amount, + destination, name, owner, symbol, }) => { doCreateToken( - { amount, name, owner, symbol }, + { amount, destination, name, owner, symbol }, { onSuccess: () => { onClose(); @@ -142,10 +144,10 @@ export function CreateTokenModal({ - - Owner + + Destination Address )} /> - {errors.owner && ( + {errors.destination && ( Must be a valid Many address. From 79abf161586493710700a44f7beec8f75dc12a34 Mon Sep 17 00:00:00 2001 From: Stanley Jones Date: Thu, 7 Sep 2023 10:21:41 -0700 Subject: [PATCH 4/5] fix: Set default values at form level, not input --- src/pages/services/ledger/create-token-modal.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/pages/services/ledger/create-token-modal.tsx b/src/pages/services/ledger/create-token-modal.tsx index 789c3da..11d92f4 100644 --- a/src/pages/services/ledger/create-token-modal.tsx +++ b/src/pages/services/ledger/create-token-modal.tsx @@ -15,7 +15,7 @@ import { 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"; export interface CreateTokenInputs { @@ -40,13 +40,17 @@ 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 = ({ @@ -155,9 +159,7 @@ export function CreateTokenModal({ isManyAddress: (v) => new RegExp(/^m\w{24,}$/).test(v), }, }} - render={({ field }) => ( - - )} + render={({ field }) => } /> {errors.destination && ( From ecf4ee5348f483188a485584ac2e26de4b021428 Mon Sep 17 00:00:00 2001 From: Stanley Jones Date: Thu, 7 Sep 2023 11:36:43 -0700 Subject: [PATCH 5/5] empty