feat: Mocked PinningProvider

This commit is contained in:
Tania Gutierrez 2024-03-21 01:15:12 -04:00
parent 5aa62f7d82
commit 52fc50d480
Signed by: riobuenoDevelops
GPG Key ID: 53133EB28EB7E801
5 changed files with 92 additions and 8 deletions

View File

@ -4,10 +4,23 @@ import { SdkProvider } from "~/data/sdk-provider.js";
export const fileProvider = { export const fileProvider = {
getList: () => { getList: () => {
console.log("Not implemented"); console.log("Not implemented");
return Promise.resolve({ return {
data: [], data: [
total: 0, {
}); 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: () => { getOne: () => {
console.log("Not implemented"); console.log("Not implemented");

View File

@ -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;

View File

@ -5,7 +5,7 @@ interface PinningStatus {
} }
// biome-ignore lint/complexity/noStaticOnlyClass: <explanation> // biome-ignore lint/complexity/noStaticOnlyClass: <explanation>
class PinningProcess { export class PinningProcess {
private static instances: Map<string, PinningStatus> = new Map(); private static instances: Map<string, PinningStatus> = new Map();
static async pin(id: string): Promise<{ success: boolean; message: string }> { static async pin(id: string): Promise<{ success: boolean; message: string }> {

View File

@ -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 {fileProvider} from "~/data/file-provider.js";
import {Sdk} from "@lumeweb/portal-sdk"; import {Sdk} from "@lumeweb/portal-sdk";
import {accountProvider} from "~/data/account-provider.js"; import {accountProvider} from "~/data/account-provider.js";
import type {SdkProvider} from "~/data/sdk-provider.js"; import type {SdkProvider} from "~/data/sdk-provider.js";
import {createPortalAuthProvider} from "~/data/auth-provider.js"; import {createPortalAuthProvider} from "~/data/auth-provider.js";
import { pinningProvider } from "./pinning-provider";
interface DataProviders { interface DataProviders {
default: SdkProvider; default: SdkProvider;
auth: AuthProvider; auth: AuthProvider;
[key: string]: SdkProvider | AuthProvider; [key: string]: SdkProvider | AuthProvider;
} }
@ -25,6 +25,7 @@ export function getProviders(sdk: Sdk) {
default: accountProvider, default: accountProvider,
auth: createPortalAuthProvider(sdk), auth: createPortalAuthProvider(sdk),
files: fileProvider, files: fileProvider,
pinning: pinningProvider
}; };
return providers; return providers;

View File

@ -38,6 +38,7 @@ export function Layout({children}: { children: React.ReactNode }) {
} }
export default function App() { export default function App() {
console.log(import.meta.env.VITE_PORTAL_URL);
const sdk = Sdk.create(import.meta.env.VITE_PORTAL_URL) const sdk = Sdk.create(import.meta.env.VITE_PORTAL_URL)
const providers = getProviders(sdk); const providers = getProviders(sdk);
return ( return (
@ -45,7 +46,10 @@ export default function App() {
authProvider={providers.auth} authProvider={providers.auth}
routerProvider={routerProvider} routerProvider={routerProvider}
notificationProvider={notificationProvider} notificationProvider={notificationProvider}
dataProvider={providers.default} dataProvider={{
default: providers.default,
pinning: providers.pinning
}}
resources={resources} resources={resources}
options={{disableTelemetry: true}} options={{disableTelemetry: true}}
> >