@msquared/etherbase-client
Version:
React hooks for interacting with Etherbase smart contracts
55 lines (50 loc) • 1.41 kB
JavaScript
// src/config.ts
var config = null;
function initializeApp(userConfig) {
if (!userConfig.wsReaderUrl && !userConfig.wsWriterUrl && !userConfig.httpReaderUrl) {
throw new Error(
"wsReaderUrl or wsWriterUrl or httpReaderUrl must be provided in etherbase config"
);
}
config = userConfig;
}
function getConfig() {
if (!config) {
throw new Error(
"Etherbase must be initialized with initializeApp() before use, or use the EtherbaseProvider"
);
}
return config;
}
// src/etherbaseSource.ts
async function fetchEventDefinitionsData(sourceAddress, config2) {
const { httpReaderUrl } = config2 || getConfig();
const response = await fetch(
`${httpReaderUrl}/event-definitions?sourceAddress=${sourceAddress}`,
{ cache: "no-store" }
);
return response.json();
}
// src/server/etherbaseSource.ts
async function getEventDefinitions(sourceAddress, config2) {
return fetchEventDefinitionsData(sourceAddress, config2);
}
// src/etherbase.ts
async function fetchSourcesData(config2) {
const { httpReaderUrl } = config2 || getConfig();
const response = await fetch(`${httpReaderUrl}/sources`, {
cache: "no-store"
});
const data = await response.json();
return data;
}
// src/server/etherbase.ts
async function getSources(config2) {
return fetchSourcesData(config2);
}
export {
getConfig,
getEventDefinitions,
getSources,
initializeApp
};