-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #616 from alleslabs/feat/saved-accounts-table
Feat/saved accounts table
- Loading branch information
Showing
16 changed files
with
499 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { Flex, Text } from "@chakra-ui/react"; | ||
import { useCallback, useEffect, useMemo } from "react"; | ||
import { useForm } from "react-hook-form"; | ||
|
||
import { ActionModal } from "../ActionModal"; | ||
import { useCelatoneApp } from "lib/app-provider"; | ||
import { ExplorerLink } from "lib/components/ExplorerLink"; | ||
import { ControllerInput, ControllerTextarea } from "lib/components/forms"; | ||
import { useGetMaxLengthError, useHandleAccountSave } from "lib/hooks"; | ||
import type { AccountLocalInfo } from "lib/stores/account"; | ||
|
||
import type { SaveAccountDetail } from "./SaveNewAccount"; | ||
|
||
interface EditSavedAccountModalProps { | ||
account: AccountLocalInfo; | ||
triggerElement: JSX.Element; | ||
} | ||
|
||
export const EditSavedAccountModal = ({ | ||
account, | ||
triggerElement, | ||
}: EditSavedAccountModalProps) => { | ||
const { constants } = useCelatoneApp(); | ||
const getMaxLengthError = useGetMaxLengthError(); | ||
const defaultValues = useMemo(() => { | ||
return { | ||
address: account.address, | ||
name: account.name ?? "", | ||
description: account.description ?? "", | ||
}; | ||
}, [account]); | ||
|
||
const { | ||
control, | ||
watch, | ||
reset, | ||
formState: { errors }, | ||
} = useForm<SaveAccountDetail>({ | ||
defaultValues, | ||
mode: "all", | ||
}); | ||
|
||
const addressState = watch("address"); | ||
const nameState = watch("name"); | ||
const descriptionState = watch("description"); | ||
|
||
const resetForm = useCallback( | ||
() => reset(defaultValues), | ||
[defaultValues, reset] | ||
); | ||
|
||
useEffect(() => { | ||
resetForm(); | ||
}, [resetForm]); | ||
|
||
const handleSave = useHandleAccountSave({ | ||
title: `Updated Saved Account!`, | ||
address: addressState, | ||
name: nameState, | ||
description: descriptionState, | ||
actions: () => {}, | ||
}); | ||
|
||
return ( | ||
<ActionModal | ||
title="Edit account" | ||
icon="edit-solid" | ||
headerContent={ | ||
<Flex gap={4} alignItems="center" pt={6}> | ||
<Text variant="body2" fontWeight={500} color="text.dark"> | ||
Account Address | ||
</Text> | ||
<ExplorerLink value={account.address} type="user_address" /> | ||
</Flex> | ||
} | ||
trigger={triggerElement} | ||
mainBtnTitle="Save" | ||
mainAction={handleSave} | ||
disabledMain={!!errors.name || !!errors.description} | ||
otherBtnTitle="Cancel" | ||
otherAction={resetForm} | ||
closeOnOverlayClick={false} | ||
> | ||
<Flex direction="column" gap={6}> | ||
<ControllerInput | ||
name="name" | ||
control={control} | ||
label="Account Name" | ||
variant="fixed-floating" | ||
// placeholder="ex. Celatone Account 1" | ||
labelBgColor="gray.900" | ||
rules={{ | ||
maxLength: constants.maxAccountNameLength, | ||
}} | ||
error={ | ||
errors.name && getMaxLengthError(nameState.length, "account_name") | ||
} | ||
/> | ||
<ControllerTextarea | ||
name="description" | ||
control={control} | ||
label="Account Description" | ||
// placeholder="Help understanding what this account do ..." | ||
variant="fixed-floating" | ||
labelBgColor="gray.900" | ||
rules={{ | ||
maxLength: constants.maxAccountDescriptionLength, | ||
}} | ||
error={ | ||
errors.description && | ||
getMaxLengthError(descriptionState.length, "account_desc") | ||
} | ||
/> | ||
</Flex> | ||
</ActionModal> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { | ||
useToast, | ||
Text, | ||
chakra, | ||
IconButton, | ||
Highlight, | ||
} from "@chakra-ui/react"; | ||
import { useCallback } from "react"; | ||
|
||
import { ActionModal } from "../ActionModal"; | ||
import { CustomIcon } from "lib/components/icon"; | ||
import { useAccountStore } from "lib/providers/store"; | ||
import type { AccountLocalInfo } from "lib/stores/account"; | ||
import { truncate } from "lib/utils"; | ||
|
||
const StyledIconButton = chakra(IconButton, { | ||
baseStyle: { | ||
display: "flex", | ||
alignItems: "center", | ||
fontSize: "22px", | ||
borderRadius: "36px", | ||
}, | ||
}); | ||
|
||
interface RemoveSavedAccountModalProps { | ||
account: AccountLocalInfo; | ||
trigger?: JSX.Element; | ||
} | ||
export function RemoveSavedAccountModal({ | ||
account, | ||
trigger = ( | ||
<StyledIconButton | ||
icon={<CustomIcon name="delete" />} | ||
variant="ghost-gray" | ||
/> | ||
), | ||
}: RemoveSavedAccountModalProps) { | ||
const toast = useToast(); | ||
const { removeSavedAccount } = useAccountStore(); | ||
const handleRemove = useCallback(() => { | ||
removeSavedAccount(account.address); | ||
|
||
toast({ | ||
title: `Removed \u2018${account.name}\u2019 from Saved Codes`, | ||
status: "success", | ||
duration: 5000, | ||
isClosable: false, | ||
position: "bottom-right", | ||
icon: <CustomIcon name="check-circle-solid" color="success.main" />, | ||
}); | ||
}, [removeSavedAccount, account.address, account.name, toast]); | ||
return ( | ||
<ActionModal | ||
title={ | ||
account.name | ||
? `Remove account \u2018${account.name}\u2019?` | ||
: `Remove account \u2018${truncate(account.address)}\u2019 ?` | ||
} | ||
icon="delete-solid" | ||
iconColor="error.light" | ||
mainVariant="error" | ||
mainBtnTitle="Yes, Remove It" | ||
mainAction={handleRemove} | ||
otherBtnTitle="No, Keep It" | ||
trigger={trigger} | ||
> | ||
<Text> | ||
<Highlight | ||
query={[ | ||
account.name ?? "", | ||
truncate(account.address), | ||
"Saved Accounts", | ||
]} | ||
styles={{ fontWeight: "bold", color: "inherit" }} | ||
> | ||
{`This action will remove \u2018${ | ||
account.name ?? truncate(account.address) | ||
}\u2019 from Saved Accounts. | ||
You can save this address again later, but you will need to add its new account name and description.`} | ||
</Highlight> | ||
</Text> | ||
</ActionModal> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/lib/components/table/accounts/SavedAccountsNameCell.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { EditableCell } from "../EditableCell"; | ||
import { useCelatoneApp } from "lib/app-provider"; | ||
import { useHandleAccountSave } from "lib/hooks"; | ||
import type { AccountLocalInfo } from "lib/stores/account"; | ||
|
||
interface SaveAccountsNameCellProps { | ||
account: AccountLocalInfo; | ||
} | ||
export const SaveAccountsNameCell = ({ | ||
account, | ||
}: SaveAccountsNameCellProps) => { | ||
const { constants } = useCelatoneApp(); | ||
const onSave = useHandleAccountSave({ | ||
title: "Changed name successfully!", | ||
address: account.address, | ||
name: account.name ?? "", | ||
description: account.description, | ||
actions: () => {}, | ||
}); | ||
return ( | ||
<EditableCell | ||
initialValue={account.name} | ||
defaultValue="Untitled Name" | ||
maxLength={constants.maxAccountNameLength} | ||
onSave={onSave} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.
7770e13
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.
Successfully deployed to the following URLs:
osmosis-celatone-frontend-staging – ./
osmosis-celatone-frontend-staging-alleslabs.vercel.app
osmosis-celatone-frontend-staging-git-develop-alleslabs.vercel.app
osmosis-celatone-frontend-staging.vercel.app
staging.osmoscan.io
osmosis-staging.celat.one
celatone-staging.osmosis.zone
7770e13
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.
Successfully deployed to the following URLs:
stargaze-celatone-frontend-staging – ./
stargaze-celatone-frontend-staging-git-develop-alleslabs.vercel.app
stargaze-celatone-frontend-staging.vercel.app
stargaze-celatone-frontend-staging-alleslabs.vercel.app
7770e13
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.
Successfully deployed to the following URLs:
celatone-frontend-staging – ./
celatone-frontend-staging-git-develop-alleslabs.vercel.app
celatone-frontend-staging.vercel.app
dev.celat.one
celatone-frontend-staging-alleslabs.vercel.app