types#DbState TypeScript Examples
The following examples show how to use
types#DbState.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: instantiate.ts From contracts-ui with GNU General Public License v3.0 | 6 votes |
export function onInsantiateFromHash(
{ db, identity }: DbState,
{ accountId, codeHash, name }: InstantiateData,
onSuccess: InstantiateState['onSuccess']
): OnInstantiateSuccess$Hash {
return async function ({ contract, status }): Promise<void> {
if (accountId && codeHash && contract && (status.isInBlock || status.isFinalized)) {
await createContract(db, identity, {
abi: contract.abi.json,
address: contract.address.toString(),
creator: accountId,
codeHash,
name: name,
tags: [],
});
onSuccess && onSuccess(contract);
}
};
}
Example #2
Source File: instantiate.ts From contracts-ui with GNU General Public License v3.0 | 6 votes |
export function onInstantiateFromCode(
{ db, identity }: DbState,
{ accountId, name }: InstantiateData,
onSuccess: InstantiateState['onSuccess']
): OnInstantiateSuccess$Code {
return async function (result): Promise<void> {
try {
const { blueprint, contract, status } = result;
if (accountId && contract && (status.isInBlock || status.isFinalized)) {
await createContract(db, identity, {
abi: contract.abi.json,
address: contract.address.toString(),
creator: accountId,
codeHash: blueprint?.codeHash.toHex() || contract.abi.info.source.wasmHash.toHex(),
name: name,
tags: [],
});
onSuccess && onSuccess(contract, blueprint);
}
} catch (e) {
console.error(e);
}
};
}
Example #3
Source File: DatabaseContext.tsx From contracts-ui with GNU General Public License v3.0 | 6 votes |
export function DatabaseContextProvider({
children,
}: React.HTMLAttributes<HTMLDivElement>): JSX.Element | null {
const { status, endpoint } = useApi();
const [state, setState] = useState<DbState>(INITIAL);
useEffect((): void => {
status === 'READY' &&
init(endpoint)
.then(([db, user, identity]): void => {
setState(state => ({ ...state, db, user, identity, isDbReady: true }));
})
.catch(e => {
console.error(e);
});
}, [endpoint, status]);
const refreshUserData = useCallback(async (): Promise<void> => {
const user = await getUser(state.db, state.identity);
const myContracts = await findMyContracts(state.db, state.identity);
setState(state => ({ ...state, user, myContracts }));
}, [state.db, state.identity]);
useEffect((): void => {
if (state.isDbReady) {
refreshUserData().then().catch(console.error);
}
}, [refreshUserData, state.isDbReady]);
return <DbContext.Provider value={{ ...state, refreshUserData }}>{children}</DbContext.Provider>;
}
Example #4
Source File: DatabaseContext.tsx From contracts-ui with GNU General Public License v3.0 | 5 votes |
export function useDatabase(): DbState {
return useContext(DbContext);
}
Example #5
Source File: DatabaseContext.tsx From contracts-ui with GNU General Public License v3.0 | 5 votes |
DbContext: React.Context<DbState> = createContext({} as unknown as DbState)
Example #6
Source File: DatabaseContext.tsx From contracts-ui with GNU General Public License v3.0 | 5 votes |
DbConsumer: React.Consumer<DbState> = DbContext.Consumer
Example #7
Source File: DatabaseContext.tsx From contracts-ui with GNU General Public License v3.0 | 5 votes |
DbProvider: React.Provider<DbState> = DbContext.Provider
Example #8
Source File: DatabaseContext.tsx From contracts-ui with GNU General Public License v3.0 | 5 votes |
INITIAL = { isDbReady: false } as unknown as DbState