diff --git a/apps/api/src/db/dbConnection.ts b/apps/api/src/db/dbConnection.ts index dd82647c3..3d36b29fa 100644 --- a/apps/api/src/db/dbConnection.ts +++ b/apps/api/src/db/dbConnection.ts @@ -1,6 +1,6 @@ import { chainDefinitions } from "@akashnetwork/database/chainDefinitions"; import { chainModels, getChainModels, userModels } from "@akashnetwork/database/dbSchemas"; -import { Template, TemplateFavorite, UserAddressName, UserSetting } from "@akashnetwork/database/dbSchemas/user"; +import { Template, TemplateFavorite, UserSetting } from "@akashnetwork/database/dbSchemas/user"; import pg from "pg"; import { Transaction as DbTransaction } from "sequelize"; import { Sequelize } from "sequelize-typescript"; @@ -77,7 +77,6 @@ export const userDb = new Sequelize(env.UserDatabaseCS, { export async function syncUserSchema() { await UserSetting.sync(); - await UserAddressName.sync(); await Template.sync(); await TemplateFavorite.sync(); } diff --git a/apps/api/src/routers/userRouter.ts b/apps/api/src/routers/userRouter.ts index 4e95d7ef4..57a36ce52 100644 --- a/apps/api/src/routers/userRouter.ts +++ b/apps/api/src/routers/userRouter.ts @@ -14,17 +14,7 @@ import { saveTemplate, saveTemplateDesc } from "@src/services/db/templateService"; -import { - checkUsernameAvailable, - getAddressNames, - getSettingsOrInit, - getUserByUsername, - removeAddressName, - saveAddressName, - subscribeToNewsletter, - updateSettings -} from "@src/services/db/userDataService"; -import { isValidBech32Address } from "@src/utils/addresses"; +import { checkUsernameAvailable, getSettingsOrInit, getUserByUsername, subscribeToNewsletter, updateSettings } from "@src/services/db/userDataService"; export const userRouter = new Hono(); @@ -46,50 +36,6 @@ userOptionalRouter.get("/byUsername/:username", async c => { return c.json(user); }); -userRequiredRouter.get("/addressNames", async c => { - const userId = getCurrentUserId(c); - const addressNames = await getAddressNames(userId); - - return c.json(addressNames); -}); - -userRequiredRouter.post("/saveAddressName", async c => { - const userId = getCurrentUserId(c); - const { address, name } = await c.req.json(); - - if (!address) { - return c.text("Address is required", 400); - } - - if (!name) { - return c.text("Name is required", 400); - } - - if (!isValidBech32Address(address, "akash")) { - return c.text("Invalid address", 400); - } - - await saveAddressName(userId, address, name); - - return c.text("Saved"); -}); - -userRequiredRouter.delete("/removeAddressName/:address", async c => { - const userId = getCurrentUserId(c); - - if (!c.req.param("address")) { - return c.text("Address is required", 400); - } - - if (!isValidBech32Address(c.req.param("address"), "akash")) { - return c.text("Invalid address", 400); - } - - await removeAddressName(userId, c.req.param("address")); - - return c.text("Removed"); -}); - userRequiredRouter.post("/tokenInfo", async c => { const userId = getCurrentUserId(c); const { wantedUsername, email, emailVerified, subscribedToNewsletter } = await c.req.json(); diff --git a/apps/api/src/services/db/userDataService.ts b/apps/api/src/services/db/userDataService.ts index 9f30d4c0a..7e3b11f9e 100644 --- a/apps/api/src/services/db/userDataService.ts +++ b/apps/api/src/services/db/userDataService.ts @@ -1,4 +1,4 @@ -import { UserAddressName, UserSetting } from "@akashnetwork/database/dbSchemas/user"; +import { UserSetting } from "@akashnetwork/database/dbSchemas/user"; import pick from "lodash/pick"; import { Transaction } from "sequelize"; import { container } from "tsyringe"; @@ -168,35 +168,6 @@ async function tryToTransferWallet(prevUserId: string, nextUserId: string) { } } -export async function getAddressNames(userId: string) { - const addressNames = await UserAddressName.findAll({ - where: { - userId: userId - } - }); - - return addressNames.reduce((obj, current) => ({ ...obj, [current.address]: current.name }), {}); -} - -export async function saveAddressName(userId: string, address: string, name: string) { - let addressName = await UserAddressName.findOne({ where: { userId: userId, address: address } }); - - if (!addressName) { - addressName = UserAddressName.build({ - userId: userId, - address: address - }); - } - - addressName.name = name; - - await addressName.save(); -} - -export async function removeAddressName(userId: string, address: string) { - await UserAddressName.destroy({ where: { userId: userId, address: address } }); -} - export async function getUserByUsername(username: string) { const user = await UserSetting.findOne({ where: { username: username } }); diff --git a/apps/deploy-web/src/components/layout/AccountMenu.tsx b/apps/deploy-web/src/components/layout/AccountMenu.tsx index 990cbc25d..b2ab437ba 100644 --- a/apps/deploy-web/src/components/layout/AccountMenu.tsx +++ b/apps/deploy-web/src/components/layout/AccountMenu.tsx @@ -80,9 +80,6 @@ export function AccountMenu() { window.open("https://blockspy.io", "_blank")?.focus()} icon={}> My Alerts - router.push(UrlService.userAddressBook())} icon={}> - Addresses - router.push(UrlService.logout())} icon={}> Logout diff --git a/apps/deploy-web/src/components/layout/MobileSidebarUser.tsx b/apps/deploy-web/src/components/layout/MobileSidebarUser.tsx index ed87faace..d0f87b58e 100644 --- a/apps/deploy-web/src/components/layout/MobileSidebarUser.tsx +++ b/apps/deploy-web/src/components/layout/MobileSidebarUser.tsx @@ -53,14 +53,6 @@ export const MobileSidebarUser: React.FunctionComponent = () => { }} /> )} - , - url: UrlService.userAddressBook(), - activeRoutes: [UrlService.userAddressBook()] - }} - /> { - const { addressNames, editAddressName, isLoading: isLoadingAddressBook } = useAddressBook(); - const { user, isLoading } = useCustomUser(); - - const addressNamesArray = Object.keys(addressNames || {}).map(address => ({ address, name: addressNames[address] })); - - return ( - - - - - - {(isLoading || isLoadingAddressBook) && ( -
- -
- )} - - {!isLoading && addressNamesArray?.length === 0 && ( -
-

No saved addresses.

-
- )} - - {addressNamesArray.length > 0 && ( - - - - Address - Name - - - - - - {addressNamesArray.map(({ address, name }) => ( - - - - - {name} - - - - - ))} - -
- )} - - {!isLoading && !isLoadingAddressBook && ( - - )} -
-
-
-
- ); -}; diff --git a/apps/deploy-web/src/components/user/UserProfileLayout.tsx b/apps/deploy-web/src/components/user/UserProfileLayout.tsx index 6307f58e5..6f9944e16 100644 --- a/apps/deploy-web/src/components/user/UserProfileLayout.tsx +++ b/apps/deploy-web/src/components/user/UserProfileLayout.tsx @@ -8,7 +8,7 @@ import { useCustomUser } from "@src/hooks/useCustomUser"; import { AnalyticsEvents } from "@src/utils/analytics"; import { UrlService } from "@src/utils/urlUtils"; -type UserProfileTab = "templates" | "favorites" | "address-book" | "settings"; +type UserProfileTab = "templates" | "favorites" | "settings"; type Props = { username?: string; bio?: string; @@ -33,9 +33,6 @@ export const UserProfileLayout: React.FunctionComponent = ({ page, childr case "favorites": router.push(UrlService.userFavorites()); break; - case "address-book": - router.push(UrlService.userAddressBook()); - break; case "settings": router.push(UrlService.userSettings()); break; @@ -51,12 +48,11 @@ export const UserProfileLayout: React.FunctionComponent = ({ page, childr - + Templates {user?.username === username && ( <> Favorites - Address Book Settings )} diff --git a/apps/deploy-web/src/context/AddressBookProvider/AddressBookProvider.tsx b/apps/deploy-web/src/context/AddressBookProvider/AddressBookProvider.tsx deleted file mode 100644 index 0473673af..000000000 --- a/apps/deploy-web/src/context/AddressBookProvider/AddressBookProvider.tsx +++ /dev/null @@ -1,36 +0,0 @@ -"use client"; -import React, { useState } from "react"; - -import { EditAddressBookmarkModal } from "@src/context/AddressBookProvider/EditAddressBookmarkModal"; -import { useAddressNames } from "@src/queries/useAddressNames"; - -type ContextType = { - isLoading: boolean; - addressNames: { [key: string]: string }; - editAddressName: (address: string) => void; -}; - -const AddressBookProviderContext = React.createContext({} as ContextType); - -export const AddressBookProvider = ({ children }) => { - const [editingAddress, setEditingAddress] = useState(null); - const { data: addressNames, isLoading } = useAddressNames(); - - function editAddressName(address: string) { - setEditingAddress(address); - } - - return ( - - {!isLoading && editingAddress !== null && ( - setEditingAddress(null)} /> - )} - {children} - - ); -}; - -// Hook -export function useAddressBook() { - return { ...React.useContext(AddressBookProviderContext) }; -} diff --git a/apps/deploy-web/src/context/AddressBookProvider/EditAddressBookmarkModal.tsx b/apps/deploy-web/src/context/AddressBookProvider/EditAddressBookmarkModal.tsx deleted file mode 100644 index 48beba4ec..000000000 --- a/apps/deploy-web/src/context/AddressBookProvider/EditAddressBookmarkModal.tsx +++ /dev/null @@ -1,134 +0,0 @@ -"use client"; -import { ReactNode, useEffect, useState } from "react"; -import { Input, Popup, Snackbar } from "@akashnetwork/ui/components"; -import { Bin, Check } from "iconoir-react"; -import { event } from "nextjs-google-analytics"; -import { useSnackbar } from "notistack"; - -import { FormPaper } from "@src/components/sdl/FormPaper"; -import { getSplitText } from "@src/hooks/useShortText"; -import { useRemoveAddressName, useSaveAddressName } from "@src/queries/useAddressNames"; -import { AnalyticsEvents } from "@src/utils/analytics"; - -type Props = { - open: boolean; - onClose: () => void; - address: string; - addressNames: { [key: string]: string }; - children?: ReactNode; -}; - -export const EditAddressBookmarkModal: React.FunctionComponent = ({ open, address, addressNames, onClose }) => { - const [customName, setCustomName] = useState(""); - const [_address, setAddress] = useState(address); - const { mutate: saveAddress, isLoading: isSaving } = useSaveAddressName(_address); - const { mutate: deleteAddress, isLoading: isDeleting } = useRemoveAddressName(_address); - const { enqueueSnackbar } = useSnackbar(); - - useEffect(() => { - if (open) { - setCustomName(addressNames[_address] || ""); - } - }, [open]); - - async function onSaveClick() { - await saveAddress(customName); - - enqueueSnackbar(, { - variant: "success" - }); - - event(AnalyticsEvents.ADDRESS_BOOK_SAVE_ADDRESS, { - category: "settings", - label: "Save address for address book" - }); - - onClose(); - } - - async function onDeleteClick() { - await deleteAddress(); - - event(AnalyticsEvents.ADDRESS_BOOK_REMOVE_ADDRESS, { - category: "settings", - label: "Remove address from address book" - }); - - onClose(); - } - - function onCloseClick() { - onClose(); - } - - return ( - Edit {getSplitText(_address)} name : <>Add {getSplitText(_address)} to Address Book} - actions={[ - { - label: ( - <> - Remove - - - ), - variant: "ghost", - side: "left", - disabled: isSaving || isDeleting || !(_address in addressNames), - onClick: onDeleteClick - }, - { - label: "Cancel", - color: "primary", - variant: "text", - side: "right", - disabled: isSaving || isDeleting, - onClick: onClose - }, - { - label: ( - <> - Save  - - - ), - variant: "default", - side: "right", - disabled: !customName || isSaving || isDeleting, - onClick: onSaveClick - } - ]} - onClose={onCloseClick} - maxWidth="sm" - enableCloseOnBackdropClick={!isSaving && !isDeleting} - > - -
- setAddress(ev.target.value)} - // Disabled if saving, deleting or if there is an address - disabled={isSaving || isDeleting || !!address} - className="w-full" - /> -
- -
- setCustomName(ev.target.value)} - disabled={isSaving || isDeleting} - className="w-full" - /> -
-
-
- ); -}; diff --git a/apps/deploy-web/src/context/AddressBookProvider/index.ts b/apps/deploy-web/src/context/AddressBookProvider/index.ts deleted file mode 100644 index 19e1bb17c..000000000 --- a/apps/deploy-web/src/context/AddressBookProvider/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { useAddressBook, AddressBookProvider } from "./AddressBookProvider"; diff --git a/apps/deploy-web/src/pages/_app.tsx b/apps/deploy-web/src/pages/_app.tsx index 6e56a265d..c435c9a8e 100644 --- a/apps/deploy-web/src/pages/_app.tsx +++ b/apps/deploy-web/src/pages/_app.tsx @@ -18,7 +18,6 @@ import GoogleAnalytics from "@src/components/layout/CustomGoogleAnalytics"; import { CustomIntlProvider } from "@src/components/layout/CustomIntlProvider"; import { PageHead } from "@src/components/layout/PageHead"; import { UserProviders } from "@src/components/user/UserProviders"; -import { AddressBookProvider } from "@src/context/AddressBookProvider"; import { BackgroundTaskProvider } from "@src/context/BackgroundTaskProvider"; import { CertificateProvider } from "@src/context/CertificateProvider"; import { ChainParamProvider } from "@src/context/ChainParamProvider"; @@ -59,30 +58,28 @@ const App: React.FunctionComponent = props => { - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + diff --git a/apps/deploy-web/src/pages/user/settings/address-book/index.tsx b/apps/deploy-web/src/pages/user/settings/address-book/index.tsx deleted file mode 100644 index ca062b6df..000000000 --- a/apps/deploy-web/src/pages/user/settings/address-book/index.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import { AddressBookTable } from "@src/components/user/AddressBookTable"; -import { withCustomPageAuthRequired } from "@src/utils/withCustomPageAuthRequired"; - -const UserAddressBookPage: React.FunctionComponent = () => { - return ; -}; - -export default UserAddressBookPage; - -export const getServerSideProps = withCustomPageAuthRequired({ - async getServerSideProps() { - return { - props: {} - }; - } -}); diff --git a/apps/deploy-web/src/queries/queryKeys.ts b/apps/deploy-web/src/queries/queryKeys.ts index 84fd26d1c..942c10432 100644 --- a/apps/deploy-web/src/queries/queryKeys.ts +++ b/apps/deploy-web/src/queries/queryKeys.ts @@ -1,7 +1,6 @@ export class QueryKeys { static getFinancialDataKey = () => ["MARKET_DATA"]; static getDashboardDataKey = () => ["DASHBOARD_DATA"]; - static getAddressNamesKey = (userId: string) => ["ADDRESS_NAMES", userId]; static getBlocksKey = (limit: number) => ["BLOCKS", limit]; static getTransactionsKey = (limit: number) => ["TRANSACTIONS", limit]; static getAddressTransactionsKey = (address: string, skip: number, limit: number) => ["ADDRESS_TRANSACTIONS", address, skip, limit]; diff --git a/apps/deploy-web/src/queries/useAddressNames.ts b/apps/deploy-web/src/queries/useAddressNames.ts deleted file mode 100644 index 930a7856f..000000000 --- a/apps/deploy-web/src/queries/useAddressNames.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { QueryKey, useMutation, useQuery, useQueryClient, UseQueryOptions } from "react-query"; -import axios from "axios"; - -import { useCustomUser } from "@src/hooks/useCustomUser"; -import { QueryKeys } from "./queryKeys"; - -type AddressNamesType = { [key: string]: string }; - -async function getAddressNames(): Promise { - const response = await axios.get("/api/proxy/user/addressNames"); - - return response.data; -} - -export function useAddressNames(options?: Omit, "queryKey" | "queryFn">) { - const { user } = useCustomUser(); - return useQuery(QueryKeys.getAddressNamesKey(user?.sub as string), () => (user ? getAddressNames() : {}), options); -} - -export function useSaveAddressName(address: string) { - const { user } = useCustomUser(); - const queryClient = useQueryClient(); - - return useMutation((name: string) => axios.post("/api/proxy/user/saveAddressName", { address: address, name: name }), { - onSuccess: (_response, newName) => { - queryClient.setQueryData(QueryKeys.getAddressNamesKey(user?.sub as string), (oldData: AddressNamesType) => { - return { ...oldData, [address]: newName }; - }); - } - }); -} - -export function useRemoveAddressName(address: string) { - const { user } = useCustomUser(); - const queryClient = useQueryClient(); - - return useMutation(() => axios.delete(`/api/proxy/user/removeAddressName/${address}`), { - onSuccess: () => { - queryClient.setQueryData(QueryKeys.getAddressNamesKey(user?.sub as string), (oldData: AddressNamesType) => { - const { [address]: removedAddress, ...newData } = oldData; - - return newData; - }); - } - }); -} diff --git a/apps/deploy-web/src/utils/urlUtils.ts b/apps/deploy-web/src/utils/urlUtils.ts index a77817be0..282268b40 100644 --- a/apps/deploy-web/src/utils/urlUtils.ts +++ b/apps/deploy-web/src/utils/urlUtils.ts @@ -42,7 +42,6 @@ export class UrlService { // User static userSettings = () => "/user/settings"; - static userAddressBook = () => `/user/settings/address-book`; static userFavorites = () => `/user/settings/favorites`; static userProfile = (username: string) => `/profile/${username}`; static login = (returnUrl?: string) => { diff --git a/apps/provider-console/src/queries/queryKeys.ts b/apps/provider-console/src/queries/queryKeys.ts index 84fd26d1c..942c10432 100644 --- a/apps/provider-console/src/queries/queryKeys.ts +++ b/apps/provider-console/src/queries/queryKeys.ts @@ -1,7 +1,6 @@ export class QueryKeys { static getFinancialDataKey = () => ["MARKET_DATA"]; static getDashboardDataKey = () => ["DASHBOARD_DATA"]; - static getAddressNamesKey = (userId: string) => ["ADDRESS_NAMES", userId]; static getBlocksKey = (limit: number) => ["BLOCKS", limit]; static getTransactionsKey = (limit: number) => ["TRANSACTIONS", limit]; static getAddressTransactionsKey = (address: string, skip: number, limit: number) => ["ADDRESS_TRANSACTIONS", address, skip, limit]; diff --git a/packages/database/dbSchemas/index.ts b/packages/database/dbSchemas/index.ts index cd89e1983..66018c517 100644 --- a/packages/database/dbSchemas/index.ts +++ b/packages/database/dbSchemas/index.ts @@ -2,7 +2,7 @@ import { Model, ModelCtor } from "sequelize-typescript"; import { activeChain, chainDefinitions } from "../chainDefinitions"; import { AddressReference, Block as BaseBlock, Day, Message as BaseMessage, MonitoredValue, Transaction, Validator } from "./base"; -import { Template, TemplateFavorite, UserAddressName, UserSetting } from "./user"; +import { Template, TemplateFavorite, UserSetting } from "./user"; function getFilteredBaseModel(): ModelCtor>[] { let models: ModelCtor>[] = baseModels; @@ -31,6 +31,6 @@ export function getChainModels(chainName: string) { } export const chainModels = [...getFilteredBaseModel(), ...(activeChain.customModels ?? [])]; -export const userModels: ModelCtor>[] = [UserSetting, Template, TemplateFavorite, UserAddressName]; +export const userModels: ModelCtor>[] = [UserSetting, Template, TemplateFavorite]; export const Block = activeChain.customBlockModel || BaseBlock; export const Message = activeChain.customMessageModel || BaseMessage; diff --git a/packages/database/dbSchemas/user/index.ts b/packages/database/dbSchemas/user/index.ts index 79e7b6439..949281f50 100644 --- a/packages/database/dbSchemas/user/index.ts +++ b/packages/database/dbSchemas/user/index.ts @@ -1,4 +1,3 @@ export { Template } from "./template"; export { TemplateFavorite } from "./templateFavorite"; -export { UserAddressName } from "./userAddressName"; export { UserSetting } from "./userSetting"; diff --git a/packages/database/dbSchemas/user/userAddressName.ts b/packages/database/dbSchemas/user/userAddressName.ts deleted file mode 100644 index 80b93268b..000000000 --- a/packages/database/dbSchemas/user/userAddressName.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { DataTypes, UUIDV4 } from "sequelize"; -import { Column, Default, Model, PrimaryKey, Table } from "sequelize-typescript"; - -import { Required } from "../decorators/requiredDecorator"; - -@Table({ - modelName: "userAddressName", - indexes: [{ unique: true, fields: ["userId", "address"] }] -}) -export class UserAddressName extends Model { - @Required @PrimaryKey @Default(UUIDV4) @Column(DataTypes.UUID) id: string; - @Required @Column userId: string; - @Required @Column address: string; - @Required @Column name: string; -}