Skip to content

Commit

Permalink
chore: revert auth procedures on submit
Browse files Browse the repository at this point in the history
Co-authored-by: Kelvin Steiner <[email protected]>
  • Loading branch information
EdSDR and steinerkelvin committed Oct 15, 2024
1 parent dde25f4 commit 95dca4d
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ export const tutorialData = {
},
"2": {
icon: <BoltIcon className="h-5 w-5" />,
description: "Staking on the CommuneX Validator",
description: "Staking on the Community Validator",
steps: [
"Navigate to the staking tab in your wallet",
"Add this validator address: 5DUWKpGBneBbna6PFHZk18Gp9wyvLUFPiWy5maAARjRjayPp (CommuneX)",
"Stake your desired amount (this determines your voting weight for modules)",
"Add this validator address: 5DUWKpGBneBbna6PFHZk18Gp9wyvLUFPiWy5maAARjRjayPp (Community Validator official validator)",
"Stake your desired amount (this determines your allocation power for modules and subnets)",
"Note: Your staked balance remains untouched; it only represents your voting power",
],
},
"3": {
icon: <ScaleIcon className="h-5 w-5" />,
description: "Assigning weights to modules",
description: "Assigning weights to modules or subnets",
steps: [
"Visit the modules page and select your preferred modules",
"Review your selected modules in 'Your Modules List'",
Expand Down
27 changes: 19 additions & 8 deletions apps/commune-validator/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ import {
CardHeader,
CardTitle,
Container,
Label,
Separator,
} from "@commune-ts/ui";
import { fromNano } from "@commune-ts/utils";

// import { fromNano } from "@commune-ts/utils";

import { useDelegateModuleStore } from "~/stores/delegateModuleStore";
import { useDelegateSubnetStore } from "~/stores/delegateSubnetStore";
Expand Down Expand Up @@ -75,13 +78,11 @@ export default function Page() {
const { data: computedWeightedSubnets } =
api.subnet.allComputedSubnetWeightsLastBlock.useQuery();
console.log(computedWeightedSubnets);
const subnetData = computedWeightedSubnets?.map((s) => ({
stakeWeight: parseInt(fromNano(s.stakeWeight)),
subnetName: s.subnetName,
percWeight: s.percWeight,
}));

console.log("subnetStakeData", subnetData);
// const subnetData = computedWeightedSubnets?.map((s) => ({
// stakeWeight: parseInt(fromNano(s.stakeWeight)),
// subnetName: s.subnetName,
// percWeight: s.percWeight,
// }));

const delegatedSubnetsData = delegatedSubnets.map((subnet) => ({
name: subnet.name,
Expand Down Expand Up @@ -172,6 +173,16 @@ export default function Page() {
{subnetData ? <SubnetPieChart chartData={subnetData} /> : <></>}
<CombinedAreaChart />
</div> */}
<Card className="flex w-full animate-fade-down flex-col items-center justify-between p-4 animate-delay-[650ms] md:flex-row">
<Label>
Feeling lost? Check out our tutorial on how to get started with the{" "}
<b className="text-green-500">Community Validator</b>:
</Label>
<Button variant="default-green" asChild>
<Link href="/tutorial">Get Started!</Link>
</Button>
</Card>
<Separator className="my-4" />
<div className="p flex w-full animate-fade-down flex-col gap-3 pb-4 animate-delay-700 md:flex-row">
<Card className="w-full">
<CardHeader>
Expand Down
52 changes: 28 additions & 24 deletions packages/api/src/router/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
USER_MODULE_DATA_INSERT_SCHEMA,
} from "@commune-ts/db/validation";

import { publicProcedure } from "../trpc";
import { authenticatedProcedure, publicProcedure } from "../trpc";

export const moduleRouter = {
// GET
Expand Down Expand Up @@ -94,24 +94,45 @@ export const moduleRouter = {
where: eq(moduleReport.id, input.id),
});
}),
allComputedModuleWeightsLastBlock: publicProcedure.query(async ({ ctx }) => {
return await ctx.db
.select({
moduleName: moduleData.name,
moduleId: computedModuleWeightsSchema.moduleId,
stakeWeight: computedModuleWeightsSchema.stakeWeight,
percWeight: computedModuleWeightsSchema.percWeight,
})
.from(computedModuleWeightsSchema)
.where(
sql`computed_module_weights.at_block = (SELECT MAX(computed_module_weights.at_block) FROM computed_module_weights)`,
)
.innerJoin(
moduleData,
eq(computedModuleWeightsSchema.moduleId, moduleData.id),
);
}),
// POST
deleteUserModuleData: publicProcedure
deleteUserModuleData: authenticatedProcedure
.input(z.object({ userKey: z.string() }))
.mutation(async ({ ctx, input }) => {
.mutation(async ({ ctx }) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const userKey = ctx.sessionData!.userKey;
await ctx.db
.delete(userModuleData)
.where(eq(userModuleData.userKey, input.userKey));
.where(eq(userModuleData.userKey, userKey));
}),
createUserModuleData: publicProcedure
createUserModuleData: authenticatedProcedure
.input(USER_MODULE_DATA_INSERT_SCHEMA)
.mutation(async ({ ctx, input }) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const userKey = ctx.sessionData!.userKey;
await ctx.db.insert(userModuleData).values({
moduleId: input.moduleId,
weight: input.weight,
userKey: input.userKey,
userKey,
});
}),
createModuleReport: publicProcedure
createModuleReport: authenticatedProcedure
.input(MODULE_REPORT_INSERT_SCHEMA)
.mutation(async ({ ctx, input }) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand All @@ -123,21 +144,4 @@ export const moduleRouter = {
userKey,
});
}),
allComputedModuleWeightsLastBlock: publicProcedure.query(async ({ ctx }) => {
return await ctx.db
.select({
moduleName: moduleData.name,
moduleId: computedModuleWeightsSchema.moduleId,
stakeWeight: computedModuleWeightsSchema.stakeWeight,
percWeight: computedModuleWeightsSchema.percWeight,
})
.from(computedModuleWeightsSchema)
.where(
sql`computed_module_weights.at_block = (SELECT MAX(computed_module_weights.at_block) FROM computed_module_weights)`,
)
.innerJoin(
moduleData,
eq(computedModuleWeightsSchema.moduleId, moduleData.id),
);
}),
} satisfies TRPCRouterRecord;
52 changes: 28 additions & 24 deletions packages/api/src/router/subnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@commune-ts/db/schema";
import { USER_SUBNET_DATA_INSERT_SCHEMA } from "@commune-ts/db/validation";

import { publicProcedure } from "../trpc";
import { authenticatedProcedure, publicProcedure } from "../trpc";

export const subnetRouter = {
// GET
Expand Down Expand Up @@ -38,29 +38,6 @@ export const subnetRouter = {
.where(eq(userSubnetDataSchema.userKey, input.userKey))
.execute();
}),
// POST
deleteUserSubnetData: publicProcedure
.input(z.object({ userKey: z.string() }))
.mutation(async ({ ctx, input }) => {
await ctx.db
.delete(userSubnetDataSchema)
.where(eq(userSubnetDataSchema.userKey, input.userKey));
}),
createUserSubnetData: publicProcedure
.input(USER_SUBNET_DATA_INSERT_SCHEMA)
.mutation(async ({ ctx, input }) => {
await ctx.db
.insert(userSubnetDataSchema)
.values({
netuid: input.netuid,
userKey: input.userKey,
weight: input.weight,
})
.onConflictDoUpdate({
target: [userSubnetDataSchema.userKey, userSubnetDataSchema.netuid],
set: { weight: input.weight },
});
}),
allComputedSubnetWeightsLastBlock: publicProcedure.query(async ({ ctx }) => {
return await ctx.db
.select({
Expand All @@ -81,4 +58,31 @@ export const subnetRouter = {
eq(computedSubnetWeights.netuid, subnetDataSchema.netuid),
);
}),
// POST
deleteUserSubnetData: authenticatedProcedure
.input(z.object({ userKey: z.string() }))
.mutation(async ({ ctx }) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const userKey = ctx.sessionData!.userKey;
await ctx.db
.delete(userSubnetDataSchema)
.where(eq(userSubnetDataSchema.userKey, userKey));
}),
createUserSubnetData: authenticatedProcedure
.input(USER_SUBNET_DATA_INSERT_SCHEMA)
.mutation(async ({ ctx, input }) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const userKey = ctx.sessionData!.userKey;
await ctx.db
.insert(userSubnetDataSchema)
.values({
netuid: input.netuid,
userKey,
weight: input.weight,
})
.onConflictDoUpdate({
target: [userSubnetDataSchema.userKey, userSubnetDataSchema.netuid],
set: { weight: input.weight },
});
}),
} satisfies TRPCRouterRecord;

0 comments on commit 95dca4d

Please sign in to comment.