Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fetch BOS indexerdata from near RPC call and conditionally render metadata if available in databricks #873

Merged
merged 5 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions frontend/widgets/src/QueryApi.IndexerCard.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
const { accountId, indexerName, lastDeploymentDate, numDeployements, numQueries, originalDeploymentDate } = props;
const { accountId, indexerName, indexerMetadata } = props;
const sanitizedAccountID = accountId.replace(/\./g, '_');
const key = `${sanitizedAccountID}/${indexerName}`;

const indexer = {
accountId,
indexerName,
...(indexerMetadata.has(key) && indexerMetadata.get(key))
};

const editUrl = `https://dev.near.org/${REPL_ACCOUNT_ID}/widget/QueryApi.App?selectedIndexerPath=${accountId}/${indexerName}`;
const statusUrl = `https://dev.near.org/${REPL_ACCOUNT_ID}/widget/QueryApi.App?selectedIndexerPath=${accountId}/${indexerName}&view=indexer&activeIndexerView=status`;
const playgroundLink = `https://cloud.hasura.io/public/graphiql?endpoint=${REPL_GRAPHQL_ENDPOINT}/v1/graphql&header=x-hasura-role%3A${accountId.replace(/\./g, '_')}`;
const formatNumberWithCommas = (number) => number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

Expand Down Expand Up @@ -164,7 +172,13 @@ return (
<TextLink as="a" ellipsis>
@{accountId}
</TextLink>
<Text>{formatNumberWithCommas(numQueries)} Queries in the past 7 days</Text>
{indexer.numQueries >= 0 && (
<Text>
{indexer.numQueries > 999
? `${formatNumberWithCommas(indexer.numQueries)} Queries in the past 7 days`
: `${indexer.numQueries} Queries in the past 7 days`}
</Text>
)}
</div>
</CardBody>

Expand All @@ -175,11 +189,6 @@ return (
<ButtonLink
primary
href={editUrl}
onClick={() =>
State.update({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not necessary anymore? I think we use active tab in various places?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the state did not exist on the page. I assumed maybe it was a hidden property passed from a parent but i didnt see anything of the sort. Removing it I did not see any differences.

activeTab: "editor",
})
}
>
View Indexer
</ButtonLink>
Expand Down
41 changes: 27 additions & 14 deletions frontend/widgets/src/QueryApi.IndexerExplorer.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
const accountId = context.accountId;
const santizedAccountId = accountId.replaceAll(".", "_");
const myAccountId = context.accountId;

const [selectedTab, setSelectedTab] = useState(props.tab && props.tab !== "all" ? props.tab : "all");
const [myIndexers, setMyIndexers] = useState([]);
const [allIndexers, setAllIndexers] = useState([]);
const [error, setError] = useState(null);
const [indexerMetadata, setIndexerMetaData] = useState(new Map());

const fetchIndexerData = () => {
Near.asyncView(`${REPL_REGISTRY_CONTRACT_ID}`, "list_all").then((data) => {
const allIndexers = [];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be replaced with indexer

const myIndexers = [];
Object.keys(data).forEach((accId) => {
Object.keys(data[accId]).forEach((functionName) => {
const indexer = {
accountId: accId,
indexerName: functionName,
};
if (accId === myAccountId) myIndexers.push(indexer);
allIndexers.push(indexer);
});
});
setMyIndexers(myIndexers);
setAllIndexers(allIndexers);
});
}

const storeIndexerMetaData = () => {
const url = `${REPL_QUERY_API_USAGE_URL}`;

asyncFetch(url)
Expand All @@ -16,12 +35,10 @@ const fetchIndexerData = () => {
throw new Error(`HTTP error! status: ${response.status}`);
}
const { data } = JSON.parse(response.body);
const allIndexers = [];
const myIndexers = [];
const map = new Map();

data.forEach(entry => {
const { indexer_account_id, indexers } = entry;

indexers.forEach(({ indexer_name, last_deployment_date, num_deployements, num_queries, original_deployment_date }) => {
const indexer = {
accountId: indexer_account_id,
Expand All @@ -31,21 +48,17 @@ const fetchIndexerData = () => {
numQueries: num_queries,
originalDeploymentDate: original_deployment_date
};

if (indexer_account_id === santizedAccountId) myIndexers.push(indexer);
allIndexers.push(indexer);
map.set(`${indexer_account_id}/${indexer_name}`, indexer);
});
});

setMyIndexers([myIndexers]);
setAllIndexers(allIndexers);
setIndexerMetaData(map);
setError(null);
})
}


useEffect(() => {
fetchIndexerData();
storeIndexerMetaData();
}, []);

const Wrapper = styled.div`
Expand Down Expand Up @@ -243,7 +256,7 @@ return (
<Item key={i}>
<Widget
src={`${REPL_ACCOUNT_ID}/widget/QueryApi.IndexerCard`}
props={{ ...indexer }}
props={{ ...indexer, indexerMetadata }}
/>
</Item>
))}
Expand Down Expand Up @@ -271,7 +284,7 @@ return (
<Item key={i}>
<Widget
src={`${REPL_ACCOUNT_ID}/widget/QueryApi.IndexerCard`}
props={{ ...indexer }}
props={{ ...indexer, indexerMetadata }}
/>
</Item>
))}
Expand Down
Loading