@helium/account-fetch-cache-hooks
Advanced tools
Comparing version
@@ -28,3 +28,2 @@ "use strict"; | ||
const cache = (0, useAccountFetchCache_1.useAccountFetchCache)(); | ||
const [accounts, setAccounts] = (0, react_1.useState)([]); | ||
const parsedAccountBaseParser = (0, react_1.useMemo)(() => { | ||
@@ -59,2 +58,28 @@ if (parser) { | ||
}, [parser]); | ||
const eagerResult = (0, react_1.useMemo)(() => { | ||
return keys === null || keys === void 0 ? void 0 : keys.map((key) => { | ||
const acc = cache.get(key); | ||
// 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, | ||
}; | ||
} | ||
}); | ||
}, [cache, keys, parsedAccountBaseParser]); | ||
const [accounts, setAccounts] = (0, react_1.useState)(eagerResult || []); | ||
const { result, loading, error } = (0, react_async_hook_1.useAsync)((keys, parsedAccountBaseParser) => __awaiter(this, void 0, void 0, function* () { | ||
@@ -61,0 +86,0 @@ return (keys && |
@@ -16,3 +16,2 @@ import { useEffect, useMemo, useState } from "react"; | ||
const cache = useAccountFetchCache(); | ||
const [accounts, setAccounts] = useState([]); | ||
const parsedAccountBaseParser = useMemo(() => { | ||
@@ -47,2 +46,28 @@ if (parser) { | ||
}, [parser]); | ||
const eagerResult = useMemo(() => { | ||
return keys?.map((key) => { | ||
const acc = cache.get(key); | ||
// 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, | ||
}; | ||
} | ||
}); | ||
}, [cache, keys, parsedAccountBaseParser]); | ||
const [accounts, setAccounts] = useState(eagerResult || []); | ||
const { result, loading, error } = useAsync(async (keys, parsedAccountBaseParser) => { | ||
@@ -49,0 +74,0 @@ return (keys && |
@@ -9,3 +9,3 @@ { | ||
"license": "Apache-2.0", | ||
"version": "0.2.15", | ||
"version": "0.2.16", | ||
"description": "React hooks and context for account-fetch-cache", | ||
@@ -36,3 +36,3 @@ "repository": { | ||
"dependencies": { | ||
"@helium/account-fetch-cache": "^0.2.15", | ||
"@helium/account-fetch-cache": "^0.2.16", | ||
"@solana/web3.js": "^1.66.2", | ||
@@ -53,3 +53,3 @@ "react-async-hook": "^4.0.0" | ||
"author": "", | ||
"gitHead": "b1663cbd0ed0e0f60bb2158abac5bf26a23635e3" | ||
"gitHead": "7421b7bd6a13c0981b5191113da714bb638c7533" | ||
} |
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
91143
3.98%639
8.49%