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

Design review changes #262

Closed
wants to merge 7 commits into from
Closed
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
1 change: 1 addition & 0 deletions services/postgres/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ model PaymentLedger {
tenant Tenant @relation(fields: [tenantId], references: [id])
tenantId String
referenceId String @unique
network String?
amount BigInt
transactionType TransactionType
createdAt DateTime @default(now())
Expand Down
10 changes: 3 additions & 7 deletions web-portal/backend/src/apps/apps.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,8 @@ export class AppsService {

async updateApp(appId: string, updateAppDto: any) {
const updatedApp = await this.prisma.client.app.update({
where: {
id: appId, deletedAt: {
not: null
}
},
data: updateAppDto,
where: {id: appId, deletedAt: { not : null }},
data: {...updateAppDto},
});

if (!updatedApp) {
Expand All @@ -123,7 +119,7 @@ export class AppsService {
const deletedAt = new Date()

const deletedApp = await this.prisma.client.app.update({
where: { id: appId },
where: { id: appId, deletedAt: { not: null } },
data: { deletedAt },
});

Expand Down
74 changes: 50 additions & 24 deletions web-portal/backend/src/utils/utils.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { CustomPrismaService } from 'nestjs-prisma';
import { PrismaClient, TransactionType } from '@/.generated/client';
import { Cron, CronExpression } from '@nestjs/schedule';
import { parseAbiItem, fromHex, isAddress } from 'viem';
import { viemClient } from './viemClient';
import { opClient, baseClient, gnosisClient } from './viemClient';

interface IParsedLog {
tenantId: string;
amount: number;
referenceId: string;
transactionType: TransactionType;
network: string;
}

const portrAddress = '0x54d5f8a0e0f06991e63e46420bcee1af7d9fe944';
Expand All @@ -22,7 +23,7 @@ export class UtilsService {
constructor(
@Inject('Postgres')
private prisma: CustomPrismaService<PrismaClient>, // <-- Inject the PrismaClient
) {}
) { }

async getChains() {
const chains = this.prisma.client.products.findMany({
Expand Down Expand Up @@ -168,39 +169,64 @@ export class UtilsService {

@Cron(CronExpression.EVERY_MINUTE)
async watchEvent() {
console.log('Getting Event Logs');
const blockNumber = await viemClient.getBlockNumber();
const logs = await viemClient.getLogs({
event,
address: portrAddress,
fromBlock: blockNumber - BigInt(1000),
toBlock: blockNumber,
});
console.log('Getting Event Logs from all clients');

// Define clients and their respective names
const clients = [
{ client: opClient, name: 'optimism' },
{ client: gnosisClient, name: 'gnosis' },
{ client: baseClient, name: 'base' }
];

// Fetch and parse logs for all clients
const allParsedLogs = await Promise.all(
clients.map(async ({ client, name }) => {
console.log(`Getting Event Logs from ${name}`);
const blockNumber = await client.getBlockNumber();
const logs = await client.getLogs({
event,
address: portrAddress,
fromBlock: blockNumber - BigInt(1000),
toBlock: blockNumber,
});

return this.parseLogs(logs, name);
})
);

const parsedLogs: IParsedLog[] = logs.map((log: any) => ({
tenantId: fromHex(log?.args?._identifier, 'string').replaceAll(
`\x00`,
'',
),
amount: Number(log?.args?._amount),
referenceId: log.transactionHash!,
transactionType: TransactionType.CREDIT!,
}));
const [parsedLogsOP, parsedLogsGnosis, parsedLogsBase] = allParsedLogs;

console.log({ parsedLogs });
console.log({ parsedLogsOP, parsedLogsGnosis, parsedLogsBase });

if (!parsedLogs) console.log('No New Redemptions');
if (!parsedLogsOP.length && !parsedLogsGnosis.length && !parsedLogsBase.length) {
console.log('No New Redemptions');
return;
}

// Create records for unique logs
const appliedLogs = await this.prisma.client.paymentLedger.createMany({
skipDuplicates: true,
data: parsedLogs,
data: [...parsedLogsOP, ...parsedLogsGnosis, ...parsedLogsBase],
});

console.log({ appliedLogs });

if (!appliedLogs) console.log('Error Applying logs');
if (!appliedLogs) {
console.log('Error Applying logs');
} else {
console.log('Applied New logs');
}
}

console.log('Applied New logs');
// Helper function to parse logs
parseLogs(logs: any[], network: string): IParsedLog[] {
return logs.map((log: any) => ({
tenantId: fromHex(log?.args?._identifier, 'string').replaceAll(`\x00`, ''),
amount: Number(log?.args?._amount),
referenceId: log.transactionHash!,
transactionType: TransactionType.CREDIT!,
network
}));
}

}
14 changes: 12 additions & 2 deletions web-portal/backend/src/utils/viemClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { createPublicClient, http } from 'viem';
import { optimism } from 'viem/chains';
import { optimism, base, gnosis } from 'viem/chains';

export const viemClient = createPublicClient({
export const opClient = createPublicClient({
chain: optimism,
transport: http(),
});

export const baseClient = createPublicClient({
chain: base,
transport: http(),
});

export const gnosisClient = createPublicClient({
chain: gnosis,
transport: http(),
});
5 changes: 0 additions & 5 deletions web-portal/frontend/components/apps/appRules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ const AppRules: React.FC<{ rule: Partial<IRuleType> }> = ({ rule }) => {
const values = existingData?.map((item) => (
<Pill
key={item.ruleId}
size="lg"
m={2}
bg={"blue"}
style={{
color: "white",
}}
>
{item.value
?.replace("P1D", "Daily")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ export default function AllowedOriginsForm() {
key={item}
withRemoveButton
onRemove={() => handleValueRemove(item)}
size="lg"
m={2}
bg={"blue"}
style={{
color: "white",
}}
>
{item}
</Pill>
Expand All @@ -65,11 +60,9 @@ export default function AllowedOriginsForm() {
placeholder="Enter a valid Url"
type="url"
inputWrapperOrder={["label", "input", "description"]}
style={{ width: "100%" }}
{...form.getInputProps("url")}
/>
<Button
h={36}
onClick={() => {
if (formValidation().hasErrors) return;
setValue((current: any) => [form.values.url, ...current]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ export default function AllowedUserAgentsForm() {
key={item}
withRemoveButton
onRemove={() => handleValueRemove(item)}
size="lg"
m={2}
bg={"blue"}
style={{
color: "white",
}}
>
{item}
</Pill>
Expand All @@ -66,7 +61,6 @@ export default function AllowedUserAgentsForm() {
{...form.getInputProps("userAgent")}
/>
<Button
h={36}
onClick={() => {
if (formValidation().hasErrors) return;
setValue((current: any) => [form.values.userAgent, ...current]),
Expand Down
6 changes: 0 additions & 6 deletions web-portal/frontend/components/apps/forms/rateLimitForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@ export default function RateLimitForm() {
key={val}
withRemoveButton
onRemove={() => handleValueRemove(val)}
size="lg"
m={2}
bg="blue"
style={{
color: "white",
}}
>
{val
?.replace("P1D", "Daily")
Expand Down Expand Up @@ -115,7 +110,6 @@ export default function RateLimitForm() {
{...form.getInputProps("period")}
/>
<Button
h={36}
onClick={() => {
if (formValidation().hasErrors) return;
if (value.some((v) => v.includes(form.values.period))) {
Expand Down
24 changes: 18 additions & 6 deletions web-portal/frontend/components/common/SearchableMultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
Pill,
PillsInput,
useCombobox,
ScrollArea,
Text
} from "@mantine/core";

export function SearchableMultiSelect({
Expand Down Expand Up @@ -37,9 +39,6 @@ export function SearchableMultiSelect({
key={item}
withRemoveButton
onRemove={() => handleValueRemove(item)}
bg="blue"
c="#fff"
size="lg"
>
{item}
</Pill>
Expand All @@ -61,9 +60,15 @@ export function SearchableMultiSelect({
store={combobox}
onOptionSubmit={handleValueSelect}
withinPortal={true}
size="md"
>
<Combobox.DropdownTarget>
<PillsInput onClick={() => combobox.openDropdown()}>
<Combobox.DropdownTarget >
<PillsInput onClick={() => combobox.openDropdown()} size="md" styles={{
input: {
backgroundColor:'#FEFCFA'
},

}}>
<Pill.Group>
{values}

Expand All @@ -89,14 +94,21 @@ export function SearchableMultiSelect({
</PillsInput>
</Combobox.DropdownTarget>

<Combobox.Dropdown>
<Combobox.Dropdown style={{
backgroundColor:'#FEFCFA'
}}>
<ScrollArea.Autosize mah={200} type="scroll">
<Combobox.Options>
<Combobox.Header>
<Text fz="xs">Scroll to see more networks</Text>
</Combobox.Header>
{options.length > 0 ? (
options
) : (
<Combobox.Empty>Nothing found...</Combobox.Empty>
)}
</Combobox.Options>
</ScrollArea.Autosize>
</Combobox.Dropdown>
</Combobox>
);
Expand Down
10 changes: 9 additions & 1 deletion web-portal/frontend/pages/login/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import background from "@frontend/public/background.png";
import { Button, Container, Title, Box, BackgroundImage } from "@mantine/core";
import { Button, Container, Title, Box, BackgroundImage, Stack } from "@mantine/core";
import Image from "next/image";
import { useWeb3Modal } from "@web3modal/wagmi/react";
import logo from "@frontend/public/logo.png";
import WelcomeShape from "@frontend/components/login/welcomeshape";
import poweredByPokt from "@frontend/public/powered-by-pokt.png";
import { useAccount, useDisconnect } from "wagmi";
import { useAtomValue } from "jotai";
import { sessionAtom } from "@frontend/utils/atoms";
Expand Down Expand Up @@ -54,7 +55,14 @@ export default function Login() {
: "Connect Wallet"}
</Button>
</WelcomeShape>
<Container style={{
position: 'absolute',
bottom: 30
}}>
<Image src={poweredByPokt.src} width={poweredByPokt.width*0.35} height={poweredByPokt.height*0.35} alt="Powered By Pokt Network"/>
</Container>
</Container>

</BackgroundImage>
</Box>
);
Expand Down
Binary file added web-portal/frontend/public/powered-by-pokt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions web-portal/frontend/utils/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const supportedChains = [
id: "8543",
name: "base",
exchangeProxy: `0xdef1c0ded9bec7f1a1670819833240f027b25eff` as Address,
portrAddress: "to-be-deployed",
portrAddress: "0x54d5f8a0e0f06991e63e46420bcee1af7d9fe944",
},
];

Expand Down Expand Up @@ -112,4 +112,4 @@ export const timeOptions = [
option: "30d",
format: "MM/dd",
},
];
];
Loading
Loading