mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-04-24 03:00:09 -04:00
@@ -107,7 +107,7 @@ export const EditProfileModal: React.FC<EditProfileModalProps> = ({
|
||||
const { username } = player.profile ?? {};
|
||||
const { save } = useSaveToComposeDB();
|
||||
const [, invalidateCache] = useInsertCacheInvalidationMutation();
|
||||
const { w3storage } = useWeb3();
|
||||
//const del = useW3upClient('Please verify space did exists prior to calling')
|
||||
const initialFormValues = useMemo(
|
||||
() => getDefaultFormValues(player),
|
||||
[player],
|
||||
@@ -187,8 +187,8 @@ export const EditProfileModal: React.FC<EditProfileModalProps> = ({
|
||||
if (Object.keys(pickedFiles).length > 0) {
|
||||
setStatus('Uploading images to web3.storage…');
|
||||
|
||||
//const rootCID = await uploadFiles(Object.values(pickedFiles));
|
||||
const rootCID = await w3storage?.uploadDirectory(Object.values(pickedFiles))
|
||||
const rootCID = await uploadFiles(Object.values(pickedFiles));
|
||||
|
||||
await Promise.all(
|
||||
Object.entries(pickedFileDataURLs).map(async ([key, val]) => {
|
||||
setStatus('Calculating image metadata…');
|
||||
|
||||
@@ -27,7 +27,6 @@ export const CONFIG = {
|
||||
googleDataAPIKey: process.env.NEXT_PUBLIC_YOUTUBE_API_KEY,
|
||||
web3StorageToken: process.env.WEB3_STORAGE_TOKEN,
|
||||
web3StorageKey: process.env.WEB3_STORAGE_KEY,
|
||||
web3StorageDID: process.env.NEXT_PUBLIC_WEB3_STORAGE_DID,
|
||||
web3StorageProof: process.env.WEB3_STORAGE_PROOF,
|
||||
openseaAPIKey: process.env.OPENSEA_API_KEY,
|
||||
alchemyAPIKey: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { ExternalProvider, Web3Provider } from '@ethersproject/providers';
|
||||
import { did, Maybe } from '@metafam/utils';
|
||||
import { Client as W3SClient } from '@web3-storage/w3up-client';
|
||||
import {
|
||||
clearDIDSessionCache,
|
||||
clearToken,
|
||||
@@ -19,7 +18,6 @@ import React, {
|
||||
import { errorHandler } from 'utils/errorHandler';
|
||||
import { providerOptions } from 'utils/walletOptions';
|
||||
import Web3Modal from 'web3modal';
|
||||
import { useW3upClient } from 'lib/hooks/useW3';
|
||||
|
||||
export type Web3ContextType = {
|
||||
provider: Maybe<Web3Provider>;
|
||||
@@ -31,7 +29,6 @@ export type Web3ContextType = {
|
||||
connecting: boolean;
|
||||
connected: boolean;
|
||||
isMetaMask: boolean;
|
||||
w3storage: Maybe<W3SClient>;
|
||||
};
|
||||
|
||||
export const Web3Context = createContext<Web3ContextType>({
|
||||
@@ -44,7 +41,6 @@ export const Web3Context = createContext<Web3ContextType>({
|
||||
connecting: false,
|
||||
connected: false,
|
||||
isMetaMask: false,
|
||||
w3storage: null,
|
||||
});
|
||||
|
||||
const web3Modal =
|
||||
@@ -91,7 +87,6 @@ type Web3State = {
|
||||
address: Maybe<string>;
|
||||
chainId: Maybe<string>;
|
||||
authToken: Maybe<string>;
|
||||
w3storage: Maybe<W3SClient>;
|
||||
};
|
||||
|
||||
export const Web3ContextProvider: React.FC<Web3ContextProviderOptions> = ({
|
||||
@@ -105,10 +100,9 @@ export const Web3ContextProvider: React.FC<Web3ContextProviderOptions> = ({
|
||||
address: null,
|
||||
chainId: null,
|
||||
authToken: null,
|
||||
w3storage: null,
|
||||
});
|
||||
const [connecting, setConnecting] = useState(false);
|
||||
const w3storage = useW3upClient();
|
||||
|
||||
const connected = useMemo(
|
||||
() =>
|
||||
!!wallet &&
|
||||
@@ -133,7 +127,6 @@ export const Web3ContextProvider: React.FC<Web3ContextProviderOptions> = ({
|
||||
address: null,
|
||||
chainId: null,
|
||||
authToken: null,
|
||||
w3storage: null,
|
||||
});
|
||||
setConnecting(false);
|
||||
resetUrqlClient?.();
|
||||
@@ -159,7 +152,6 @@ export const Web3ContextProvider: React.FC<Web3ContextProviderOptions> = ({
|
||||
chainId: networkId,
|
||||
address: addr,
|
||||
authToken: token,
|
||||
w3storage,
|
||||
});
|
||||
|
||||
resetUrqlClient?.();
|
||||
@@ -222,7 +214,6 @@ export const Web3ContextProvider: React.FC<Web3ContextProviderOptions> = ({
|
||||
authToken,
|
||||
chainId,
|
||||
isMetaMask,
|
||||
w3storage,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
||||
@@ -1,26 +1,18 @@
|
||||
import { delegate } from "pages/api/w3up-client";
|
||||
import { Client } from "@web3-storage/w3up-client";
|
||||
import { useState, useEffect } from "react";
|
||||
import { CONFIG } from "config";
|
||||
|
||||
export function useW3upClient() {
|
||||
const [w3upClient, setW3upClient] = useState<Client | null>(null);
|
||||
const { web3StorageDID } = CONFIG;
|
||||
useEffect(() => {
|
||||
if (!web3StorageDID) return;
|
||||
async function fetchW3upClient() {
|
||||
try {
|
||||
const result = await delegate(web3StorageDID);
|
||||
if (result) {
|
||||
setW3upClient(result[1] as Client);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error occurred during delegation:', error);
|
||||
}
|
||||
export async function useW3upClient(did: string) {
|
||||
try {
|
||||
const result = await delegate(did);
|
||||
console.log('result', result);
|
||||
if (result) {
|
||||
const res = (result[1] as Client)?.uploadFile(new File(['hello, is this working???'], 'file.txt'));
|
||||
console.log('res', res);
|
||||
return result[1];
|
||||
} else {
|
||||
console.log('Delegation failed');
|
||||
}
|
||||
|
||||
fetchW3upClient();
|
||||
}, [web3StorageDID]);
|
||||
|
||||
return w3upClient;
|
||||
} catch (error) {
|
||||
console.error('Error occurred during delegation:', error);
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,16 @@ import { importDAG } from "@ucanto/core/delegation";
|
||||
import * as Signer from "@ucanto/principal/ed25519";
|
||||
import * as Client from "@web3-storage/w3up-client";
|
||||
import { StoreMemory } from "@web3-storage/access/stores/store-memory";
|
||||
import { CONFIG } from 'config';
|
||||
|
||||
const principal = Signer.parse("pLEASE FIX ME");
|
||||
const principal = Signer.parse(CONFIG.web3StorageKey || "Please verify key exists prior to uploading.");
|
||||
|
||||
const initClient = async () => {
|
||||
// Add proof that this agent has been delegated capabilities on the space
|
||||
const client = await Client.create({ principal, store: new StoreMemory() });
|
||||
const space = client.spaces().find((space) => space.name === "metagame");
|
||||
if (!space) {
|
||||
const proof = parseProof("ahhhhh");
|
||||
const proof = parseProof(CONFIG.web3StorageProof || 'Please verify proof exists prior to uploading.');
|
||||
const space = await client.addSpace(proof);
|
||||
await client.setCurrentSpace(space.did());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user