From 52fc50d480c0f570da32e99013a2e7df2ec50537 Mon Sep 17 00:00:00 2001 From: Tania Gutierrez Date: Thu, 21 Mar 2024 01:15:12 -0400 Subject: [PATCH] feat: Mocked PinningProvider --- app/data/file-provider.ts | 21 +++++++++--- app/data/pinning-provider.ts | 66 ++++++++++++++++++++++++++++++++++++ app/data/pinning.ts | 2 +- app/data/providers.ts | 5 +-- app/root.tsx | 6 +++- 5 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 app/data/pinning-provider.ts diff --git a/app/data/file-provider.ts b/app/data/file-provider.ts index dc6528a..4c92366 100644 --- a/app/data/file-provider.ts +++ b/app/data/file-provider.ts @@ -4,10 +4,23 @@ import { SdkProvider } from "~/data/sdk-provider.js"; export const fileProvider = { getList: () => { console.log("Not implemented"); - return Promise.resolve({ - data: [], - total: 0, - }); + return { + data: [ + { + name: "whirly-final-draft.psd", + cid: "0xB45165ED3CD437B", + size: "1.89 MB", + createdOn: " 03/02/2024 at 13:29 PM", + }, + { + name: "whirly-final-draft.psd", + cid: "0xB45165ED3CD437B", + size: "1.89 MB", + createdOn: " 03/02/2024 at 13:29 PM", + }, + ], + total: 2 + } }, getOne: () => { console.log("Not implemented"); diff --git a/app/data/pinning-provider.ts b/app/data/pinning-provider.ts new file mode 100644 index 0000000..7ef3c93 --- /dev/null +++ b/app/data/pinning-provider.ts @@ -0,0 +1,66 @@ +import { SdkProvider } from "~/data/sdk-provider.js"; +import { PinningProcess } from "./pinning"; + +export const pinningProvider = { + getList: () => { + console.log("Not implemented"); + return { + data: [], + total: 0, + }; + }, + getOne: () => { + console.log("Not implemented"); + return Promise.resolve({ + data: { + id: 1, + }, + }); + }, + update: () => { + console.log("Not implemented"); + return Promise.resolve({ + data: {}, + }); + }, + create: () => { + console.log("Not implemented"); + return Promise.resolve({ + data: {}, + }); + }, + deleteOne: () => { + console.log("Not implemented"); + return Promise.resolve({ + data: {}, + }); + }, + getApiUrl: () => "", + custom: () => { + + const pinCid = async (cid: string) => { + return await PinningProcess.pin(cid); + } + + const unpinCid = async (cid: string) => { + console.log("Not Implemented"); + } + + const checkCid = async (cid: string) => { + console.log("Not Implemented"); + } + + const checkCidProgress = (cid: string) => { + const progressGenerator = PinningProcess.pollProgress(cid); + + return progressGenerator.next(); + } + + return { + pinCid, + unpinCid, + checkCid, + checkCidProgress + } + }, +} satisfies SdkProvider; diff --git a/app/data/pinning.ts b/app/data/pinning.ts index 80d9540..d5643f6 100644 --- a/app/data/pinning.ts +++ b/app/data/pinning.ts @@ -5,7 +5,7 @@ interface PinningStatus { } // biome-ignore lint/complexity/noStaticOnlyClass: -class PinningProcess { +export class PinningProcess { private static instances: Map = new Map(); static async pin(id: string): Promise<{ success: boolean; message: string }> { diff --git a/app/data/providers.ts b/app/data/providers.ts index ee47b55..51453d3 100644 --- a/app/data/providers.ts +++ b/app/data/providers.ts @@ -1,14 +1,14 @@ -import type {AuthProvider, DataProvider} from "@refinedev/core"; +import type {AuthProvider} from "@refinedev/core"; import {fileProvider} from "~/data/file-provider.js"; import {Sdk} from "@lumeweb/portal-sdk"; import {accountProvider} from "~/data/account-provider.js"; import type {SdkProvider} from "~/data/sdk-provider.js"; import {createPortalAuthProvider} from "~/data/auth-provider.js"; +import { pinningProvider } from "./pinning-provider"; interface DataProviders { default: SdkProvider; auth: AuthProvider; - [key: string]: SdkProvider | AuthProvider; } @@ -25,6 +25,7 @@ export function getProviders(sdk: Sdk) { default: accountProvider, auth: createPortalAuthProvider(sdk), files: fileProvider, + pinning: pinningProvider }; return providers; diff --git a/app/root.tsx b/app/root.tsx index 5f17966..6f0e1fa 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -38,6 +38,7 @@ export function Layout({children}: { children: React.ReactNode }) { } export default function App() { + console.log(import.meta.env.VITE_PORTAL_URL); const sdk = Sdk.create(import.meta.env.VITE_PORTAL_URL) const providers = getProviders(sdk); return ( @@ -45,7 +46,10 @@ export default function App() { authProvider={providers.auth} routerProvider={routerProvider} notificationProvider={notificationProvider} - dataProvider={providers.default} + dataProvider={{ + default: providers.default, + pinning: providers.pinning + }} resources={resources} options={{disableTelemetry: true}} >