Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@helium/account-fetch-cache-hooks

Package Overview
Dependencies
Maintainers
6
Versions
171
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@helium/account-fetch-cache-hooks - npm Package Compare versions

Comparing version 0.2.11 to 0.2.14

115

lib/cjs/hooks/useAccounts.js

@@ -28,40 +28,59 @@ "use strict";

const cache = (0, useAccountFetchCache_1.useAccountFetchCache)();
const [accounts, setAccounts] = (0, react_1.useState)();
const parsedAccountBaseParser = (0, react_1.useMemo)(() => (pubkey, data) => {
try {
if (parser) {
const info = parser(pubkey, data);
return {
pubkey,
account: data,
info,
};
}
return {
pubkey,
account: data,
info: undefined,
const [accounts, setAccounts] = (0, react_1.useState)([]);
const parsedAccountBaseParser = (0, react_1.useMemo)(() => {
if (parser) {
return (pubkey, data) => {
try {
if (parser) {
const info = parser(pubkey, data);
return {
pubkey,
account: data,
info,
};
}
return {
pubkey,
account: data,
info: undefined,
};
}
catch (e) {
console.error(`Error while parsing: ${e.message}`);
return {
pubkey,
account: data,
info: undefined,
};
}
};
}
catch (e) {
console.error(`Error while parsing: ${e.message}`);
return {
pubkey,
account: data,
info: undefined,
};
}
}, [parser]);
const { result, loading, error } = (0, react_async_hook_1.useAsync)((keys, parser) => __awaiter(this, void 0, void 0, function* () {
const { result, loading, error } = (0, react_async_hook_1.useAsync)((keys, parsedAccountBaseParser) => __awaiter(this, void 0, void 0, function* () {
return (keys &&
(yield Promise.all(keys.map((key) => __awaiter(this, void 0, void 0, function* () {
const acc = yield cache.search(key, parser ? parsedAccountBaseParser : undefined, isStatic);
return {
info: acc && parser && parser(acc.pubkey, acc === null || acc === void 0 ? void 0 : acc.account),
account: acc && acc.account,
publicKey: acc.pubkey,
parser: parser ? parsedAccountBaseParser : undefined,
};
const acc = yield cache.search(key, parsedAccountBaseParser, isStatic);
// The cache caches the parser, so we need to check if the parser is different
let info = acc === null || acc === void 0 ? void 0 : acc.info;
if (cache.keyToAccountParser[key.toBase58()] !=
parsedAccountBaseParser &&
parsedAccountBaseParser &&
(acc === null || acc === void 0 ? void 0 : acc.account)) {
info = parsedAccountBaseParser(key, acc === null || acc === void 0 ? void 0 : acc.account).info;
}
if (acc) {
return {
info,
account: acc.account,
publicKey: acc.pubkey,
parser: parsedAccountBaseParser,
};
}
else {
return {
publicKey: key,
};
}
})))));
}), [keys, parser]);
}), [keys, parsedAccountBaseParser]);
// Start watchers

@@ -86,13 +105,19 @@ (0, react_1.useEffect)(() => {

const acc = yield cache.get(event.id);
const newAccounts = [
...accounts.slice(0, index),
{
info: mergePublicKeys(accounts[index].info, acc && parser && parser(acc.pubkey, acc === null || acc === void 0 ? void 0 : acc.account)),
account: acc && acc.account,
publicKey: acc.pubkey,
parser: parser ? parsedAccountBaseParser : undefined,
},
...accounts.slice(index + 1),
];
setAccounts(newAccounts);
if (acc) {
const parsed = parser && parser(acc.pubkey, acc === null || acc === void 0 ? void 0 : acc.account);
const newParsed = accounts[index]
? mergePublicKeys(accounts[index].info, parsed)
: parsed;
const newAccounts = [
...accounts.slice(0, index),
{
info: newParsed,
account: acc.account,
publicKey: acc.pubkey,
parser: parsedAccountBaseParser,
},
...accounts.slice(index + 1),
];
setAccounts(newAccounts);
}
}

@@ -103,3 +128,3 @@ }));

};
}, [accounts, keys]);
}, [accounts, keys, parsedAccountBaseParser, parser]);
return {

@@ -119,3 +144,3 @@ loading,

return (input !== null &&
typeof input === 'object' &&
typeof input === "object" &&
Object.getPrototypeOf(input).isPrototypeOf(Object));

@@ -122,0 +147,0 @@ }

@@ -16,40 +16,59 @@ import { useEffect, useMemo, useState } from "react";

const cache = useAccountFetchCache();
const [accounts, setAccounts] = useState();
const parsedAccountBaseParser = useMemo(() => (pubkey, data) => {
try {
if (parser) {
const info = parser(pubkey, data);
return {
pubkey,
account: data,
info,
};
}
return {
pubkey,
account: data,
info: undefined,
const [accounts, setAccounts] = useState([]);
const parsedAccountBaseParser = useMemo(() => {
if (parser) {
return (pubkey, data) => {
try {
if (parser) {
const info = parser(pubkey, data);
return {
pubkey,
account: data,
info,
};
}
return {
pubkey,
account: data,
info: undefined,
};
}
catch (e) {
console.error(`Error while parsing: ${e.message}`);
return {
pubkey,
account: data,
info: undefined,
};
}
};
}
catch (e) {
console.error(`Error while parsing: ${e.message}`);
return {
pubkey,
account: data,
info: undefined,
};
}
}, [parser]);
const { result, loading, error } = useAsync(async (keys, parser) => {
const { result, loading, error } = useAsync(async (keys, parsedAccountBaseParser) => {
return (keys &&
(await Promise.all(keys.map(async (key) => {
const acc = await cache.search(key, parser ? parsedAccountBaseParser : undefined, isStatic);
return {
info: acc && parser && parser(acc.pubkey, acc?.account),
account: acc && acc.account,
publicKey: acc.pubkey,
parser: parser ? parsedAccountBaseParser : undefined,
};
const acc = await cache.search(key, parsedAccountBaseParser, isStatic);
// The cache caches the parser, so we need to check if the parser is different
let info = acc?.info;
if (cache.keyToAccountParser[key.toBase58()] !=
parsedAccountBaseParser &&
parsedAccountBaseParser &&
acc?.account) {
info = parsedAccountBaseParser(key, acc?.account).info;
}
if (acc) {
return {
info,
account: acc.account,
publicKey: acc.pubkey,
parser: parsedAccountBaseParser,
};
}
else {
return {
publicKey: key,
};
}
}))));
}, [keys, parser]);
}, [keys, parsedAccountBaseParser]);
// Start watchers

@@ -74,13 +93,19 @@ useEffect(() => {

const acc = await cache.get(event.id);
const newAccounts = [
...accounts.slice(0, index),
{
info: mergePublicKeys(accounts[index].info, acc && parser && parser(acc.pubkey, acc?.account)),
account: acc && acc.account,
publicKey: acc.pubkey,
parser: parser ? parsedAccountBaseParser : undefined,
},
...accounts.slice(index + 1),
];
setAccounts(newAccounts);
if (acc) {
const parsed = parser && parser(acc.pubkey, acc?.account);
const newParsed = accounts[index]
? mergePublicKeys(accounts[index].info, parsed)
: parsed;
const newAccounts = [
...accounts.slice(0, index),
{
info: newParsed,
account: acc.account,
publicKey: acc.pubkey,
parser: parsedAccountBaseParser,
},
...accounts.slice(index + 1),
];
setAccounts(newAccounts);
}
}

@@ -91,3 +116,3 @@ });

};
}, [accounts, keys]);
}, [accounts, keys, parsedAccountBaseParser, parser]);
return {

@@ -106,3 +131,3 @@ loading,

return (input !== null &&
typeof input === 'object' &&
typeof input === "object" &&
Object.getPrototypeOf(input).isPrototypeOf(Object));

@@ -109,0 +134,0 @@ }

@@ -10,4 +10,4 @@ import { Commitment, Connection } from "@solana/web3.js";

}
export declare const AccountContext: React.Context<AccountFetchCache>;
export declare const AccountContext: React.Context<AccountFetchCache | undefined>;
export declare const AccountProvider: FC<IAccountProviderProps>;
//# sourceMappingURL=accountContext.d.ts.map

@@ -9,7 +9,7 @@ {

"license": "Apache-2.0",
"version": "0.2.11",
"version": "0.2.14",
"description": "React hooks and context for account-fetch-cache",
"repository": {
"type": "git",
"url": "https://github.com/HeliumFoundation/helium-program-libary"
"url": "https://github.com/helium/helium-program-libary"
},

@@ -36,3 +36,3 @@ "main": "./lib/cjs/index.js",

"dependencies": {
"@helium/account-fetch-cache": "^0.2.5",
"@helium/account-fetch-cache": "^0.2.14",
"@solana/web3.js": "^1.66.2",

@@ -53,3 +53,3 @@ "react-async-hook": "^4.0.0"

"author": "",
"gitHead": "441156a08d754221a7e436618d8358b94e42c94c"
"gitHead": "009c7106505f4a0548c6de6ff6c7a7df3865b742"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc