Skip to content
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

Remove AddressBook feature #329

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apps/api/src/db/dbConnection.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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();
}
Expand Down
56 changes: 1 addition & 55 deletions apps/api/src/routers/userRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();
Expand Down
31 changes: 1 addition & 30 deletions apps/api/src/services/db/userDataService.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 } });

Expand Down
3 changes: 0 additions & 3 deletions apps/deploy-web/src/components/layout/AccountMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ export function AccountMenu() {
<CustomDropdownLinkItem onClick={() => window.open("https://blockspy.io", "_blank")?.focus()} icon={<Bell />}>
My Alerts
</CustomDropdownLinkItem>
<CustomDropdownLinkItem onClick={() => router.push(UrlService.userAddressBook())} icon={<Book />}>
Addresses
</CustomDropdownLinkItem>
<DropdownMenuSeparator />
<CustomDropdownLinkItem onClick={() => router.push(UrlService.logout())} icon={<LogOut />}>
Logout
Expand Down
8 changes: 0 additions & 8 deletions apps/deploy-web/src/components/layout/MobileSidebarUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ export const MobileSidebarUser: React.FunctionComponent = () => {
}}
/>
)}
<SidebarRouteButton
route={{
title: "Addresses",
icon: props => <BookStack {...props} />,
url: UrlService.userAddressBook(),
activeRoutes: [UrlService.userAddressBook()]
}}
/>
<SidebarRouteButton
route={{
title: "Settings",
Expand Down
95 changes: 0 additions & 95 deletions apps/deploy-web/src/components/user/AddressBookTable.tsx

This file was deleted.

8 changes: 2 additions & 6 deletions apps/deploy-web/src/components/user/UserProfileLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,9 +33,6 @@ export const UserProfileLayout: React.FunctionComponent<Props> = ({ page, childr
case "favorites":
router.push(UrlService.userFavorites());
break;
case "address-book":
router.push(UrlService.userAddressBook());
break;
case "settings":
router.push(UrlService.userSettings());
break;
Expand All @@ -51,12 +48,11 @@ export const UserProfileLayout: React.FunctionComponent<Props> = ({ page, childr
</div>

<Tabs value={page} onValueChange={handleTabChange}>
<TabsList className="mb-4 grid w-full grid-cols-4 border-b">
<TabsList className="mb-4 grid w-full grid-cols-3 border-b">
<TabsTrigger value="templates">Templates</TabsTrigger>
{user?.username === username && (
<>
<TabsTrigger value="favorites">Favorites</TabsTrigger>
<TabsTrigger value="address-book">Address Book</TabsTrigger>
<TabsTrigger value="settings">Settings</TabsTrigger>
</>
)}
Expand Down

This file was deleted.

Loading
Loading