-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Allow arbitrary destination address for token creation #66
Changes from 4 commits
6c4d062
c2141f5
9854bbb
170aece
79abf16
ecf4ee5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,10 +29,10 @@ | |
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 @@ | |
|
||
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; | ||
Comment on lines
-51
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I sorted the arg list so the diff is a little messy, but I'm removing |
||
}) => | ||
await neighborhood?.tokens.create({ | ||
summary: { | ||
name, | ||
symbol: symbol.toUpperCase(), | ||
precision: 9, | ||
precision, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}, | ||
owner: address, | ||
owner, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
distribution: { | ||
[address]: BigInt(parseInt(amount) * 10 ** precision), | ||
[destination]: BigInt(parseInt(amount) * 10 ** precision), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...while the destination of the initial distribution will be set to the |
||
}, | ||
}), | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,28 +8,22 @@ | |
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 { 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({ | ||
|
@@ -56,12 +50,14 @@ | |
const toast = useToast(); | ||
|
||
const onSubmit: SubmitHandler<CreateTokenInputs> = ({ | ||
amount, | ||
destination, | ||
name, | ||
owner, | ||
symbol, | ||
amount, | ||
}) => { | ||
doCreateToken( | ||
{ name, symbol, amount, address }, | ||
{ amount, destination, name, owner, symbol }, | ||
{ | ||
onSuccess: () => { | ||
onClose(); | ||
|
@@ -148,22 +144,26 @@ | |
</FormControl> | ||
</GridItem> | ||
<GridItem colSpan={5}> | ||
<FormControl> | ||
<HStack> | ||
<FormLabel htmlFor="address">Destination Address</FormLabel> | ||
<Popover trigger="hover"> | ||
<PopoverTrigger> | ||
<Icon as={FiInfo} /> | ||
</PopoverTrigger> | ||
<PopoverContent bg="brand.teal.700" color="white" p={3}> | ||
<PopoverBody> | ||
The destination address is the current user and cannot be | ||
changed at this time. | ||
</PopoverBody> | ||
</PopoverContent> | ||
</Popover> | ||
</HStack> | ||
<Input fontFamily="mono" isDisabled value={address} /> | ||
<FormControl isInvalid={!!errors.destination}> | ||
<FormLabel htmlFor="destination">Destination Address</FormLabel> | ||
<Controller | ||
name="destination" | ||
control={control} | ||
rules={{ | ||
required: true, | ||
validate: { | ||
isManyAddress: (v) => new RegExp(/^m\w{24,}$/).test(v), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A more accurate regex for detecting a valid Many address is welcome if we have one (I looked in the spec and |
||
}, | ||
}} | ||
render={({ field }) => ( | ||
<Input fontFamily="mono" defaultValue={address} {...field} /> | ||
)} | ||
/> | ||
{errors.destination && ( | ||
<FormErrorMessage> | ||
Must be a valid Many address. | ||
</FormErrorMessage> | ||
)} | ||
</FormControl> | ||
</GridItem> | ||
</Grid> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just auto-formatting. No code changes.