Collection Details
Namespace:
kage
Dataset:
Collection:
mydata
Owner:
0x4dd428432096de33fdd9de1aa60a80386b47c92b
Transaction:
Timestamp:
Nov.24.2023 05:08:00 AM
Status:
OnChain
Collection Documents
_id | delete | update | View |
---|---|---|---|
c2a5896721bb9a3ec75295fcc55ca3fac5d2c606b7db2a52168204ab4f3513822 | const client = useMemo(() => {
return new GlacierClient('https://p0.onebitdev.com/glacier-gateway', {
provider,
});
}, [provider]); | import { useState, useCallback, useMemo, useEffect } from 'react';
import { GlacierClient, NamespaceRecord } from '@glacier-network/client';
import useMetaMask from './useMetaMask';
export default function useGlacier() {
const [spaces, setSpaces] = useState<NamespaceRecord[]>([]);
const { provider, account, connect, eagerConnect } = useMetaMask();
const client = useMemo(() => {
return new GlacierClient('https://p0.onebitdev.com/glacier-gateway', {
provider,
});
}, [provider]);
const listNamespace = useCallback(async () => {
if (!account) return setSpaces([]);
const result = await client.namespaces(account);
setSpaces(result);
}, [client, account]);
const createNamespace = useCallback(
async (name: string) => {
const result = await client.createNamespace(name);
return result;
},
[client]
);
useEffect(() => {
listNamespace();
}, [listNamespace]);
return {
client,
spaces,
account,
connect,
eagerConnect,
listNamespace,
createNamespace,
};
} | View |
c2a5896721bb9a3ec75295fcc55ca3fac5d2c606b7db2a52168204ab4f3513821 | import { useState, useEffect, useCallback } from 'react';
import { MetaMaskInpageProvider } from '@metamask/providers';
export default function useMetaMask() {
const [account, setAccount] = useState<string>();
const [provider, setProvider] = useState<MetaMaskInpageProvider>();
const connect = useCallback(async () => {
const accounts = await window.ethereum.request<string[]>({
method: 'eth_requestAccounts',
params: [],
});
if (accounts) setAccount(accounts[0]);
}, []);
const eagerConnect = useCallback(async () => {
if (!window.ethereum) return;
const accounts = await window.ethereum?.request<string[]>({
method: 'eth_accounts',
params: [],
});
if (accounts) setAccount(accounts[0]);
setProvider(window.ethereum);
}, []);
useEffect(() => {
window.ethereum?.on('accountsChanged', (args) => {
const accounts = args as string[];
if (accounts) setAccount(accounts[0]);
setProvider(window.ethereum);
});
}, []);
return {
account,
provider,
connect,
eagerConnect,
};
} | pnpm create vite glacier-quickstart --template react-ts | View |