Skip to content

Commit

Permalink
feat: implement edit/delete accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
brusherru committed Sep 5, 2024
1 parent 80c9c94 commit c871e7f
Show file tree
Hide file tree
Showing 6 changed files with 567 additions and 63 deletions.
43 changes: 22 additions & 21 deletions src/components/CreateAccountModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ function CreateAccountModal({
const keys = wallet?.keychain || [];
const defaultValues = {
displayName: '',
required: 1,
publicKeys: [keys[0]?.publicKey || '0x1'],
Required: 1,
PublicKeys: [keys[0]?.publicKey || '0x1'],
};
const {
watch,
Expand All @@ -73,36 +73,36 @@ function CreateAccountModal({
defaultValues,
});
const selectedTemplate = watch('templateAddress');
const selectedOwner = watch('owner');
const totalAmount = watch('totalAmount');
const selectedOwner = watch('Owner');
const totalAmount = watch('TotalAmount');

useEffect(() => {
if (selectedTemplate === StdPublicKeys.Vault) {
register('initialUnlockAmount', {
register('InitialUnlockAmount', {
required: 'Please specify the initial unlock amount',
});
return () => unregister('initialUnlockAmount');
return () => unregister('InitialUnlockAmount');
}
return noop;
}, [register, selectedTemplate, unregister]);

useEffect(() => {
const owner = selectedOwner || getValues('owner');
const owner = selectedOwner || getValues('Owner');
if (Object.hasOwn(GENESIS_VESTING_ACCOUNTS, owner)) {
const amount =
GENESIS_VESTING_ACCOUNTS[
owner as keyof typeof GENESIS_VESTING_ACCOUNTS
];
setValue('totalAmount', String(amount));
setValue('initialUnlockAmount', String(amount / 4n));
setValue('vestingStart', GENESIS_VESTING_START);
setValue('vestingEnd', GENESIS_VESTING_END);
setValue('TotalAmount', String(amount));
setValue('InitialUnlockAmount', String(amount / 4n));
setValue('VestingStart', GENESIS_VESTING_START);
setValue('VestingEnd', GENESIS_VESTING_END);
}
}, [getValues, selectedOwner, selectedTemplate, setValue]);

useEffect(() => {
if (totalAmount) {
setValue('initialUnlockAmount', String(BigInt(totalAmount) / 4n));
setValue('InitialUnlockAmount', String(BigInt(totalAmount) / 4n));
}
}, [totalAmount, setValue]);

Expand Down Expand Up @@ -138,7 +138,7 @@ function CreateAccountModal({
pre-defined vesting schedule.
</Text>
<FormAddressSelect
fieldName="owner"
fieldName="Owner"
accounts={accounts.filter(
(acc) => acc.templateAddress === StdPublicKeys.Vesting
)}
Expand All @@ -153,7 +153,7 @@ function CreateAccountModal({
<FormInput
label="Total amount"
inputProps={{ type: 'number' }}
register={register('totalAmount', {
register={register('TotalAmount', {
required: 'Please specify total amount locked in the vault',
})}
errors={errors}
Expand All @@ -162,7 +162,7 @@ function CreateAccountModal({
<FormInput
label="Vesting start (layer number)"
inputProps={{ type: 'number' }}
register={register('vestingStart', {
register={register('VestingStart', {
required: 'Please specify the epoch when the vesting starts',
valueAsNumber: true,
})}
Expand All @@ -172,7 +172,7 @@ function CreateAccountModal({
<FormInput
label="Vesting end (layer number)"
inputProps={{ type: 'number' }}
register={register('vestingEnd', {
register={register('VestingEnd', {
required: 'Please specify the epoch when the vesting ends',
valueAsNumber: true,
})}
Expand All @@ -191,7 +191,7 @@ function CreateAccountModal({
<FormInput
label="Required amount of signatures"
inputProps={{ type: 'number' }}
register={register('required', {
register={register('Required', {
required: 'Please specify any number from 0 to 10',
valueAsNumber: true,
validate: (n) => {
Expand All @@ -210,7 +210,7 @@ function CreateAccountModal({
<FormMultiKeySelect
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
fieldName="publicKeys"
fieldName="PublicKeys"
keys={keys}
control={control}
register={register}
Expand All @@ -232,7 +232,7 @@ function CreateAccountModal({
<FormInput
label="Required amount of signatures"
inputProps={{ type: 'number' }}
register={register('required', {
register={register('Required', {
required: 'Please specify any number from 0 to 10',
valueAsNumber: true,
validate: (n) => {
Expand All @@ -251,7 +251,7 @@ function CreateAccountModal({
<FormMultiKeySelect
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
fieldName="publicKeys"
fieldName="PublicKeys"
keys={keys}
control={control}
register={register}
Expand All @@ -271,13 +271,14 @@ function CreateAccountModal({
transaction.
</Text>
<FormKeySelect
fieldName="publicKey"
fieldName="PublicKey"
keys={keys}
register={register}
unregister={unregister}
errors={errors}
isSubmitted={isSubmitted}
isRequired
value={keys[0]?.publicKey}
/>
</>
);
Expand Down
Loading

0 comments on commit c871e7f

Please sign in to comment.