Skip to content

Commit

Permalink
Merge pull request #99 from availproject/ghali/new-lc-endpoint
Browse files Browse the repository at this point in the history
use v2 api endpoint for lc confidence
  • Loading branch information
Leouarz authored Feb 5, 2025
2 parents 82e6218 + 1f7911f commit 4750d83
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/apps-config/src/variables/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// eslint-disable-next-line
const config: { [network: string]: { url: `wss://${string}`, lcUrl: string } } = {
mainnet: {
lcUrl: process.env.MAINNET_LC || 'https://api.lightclient.mainnet.avail.so/v1',
lcUrl: process.env.MAINNET_LC || 'https://api.lightclient.mainnet.avail.so/v2',
url: process.env.MAINNET_URL as `wss://${string}` || 'wss://mainnet-rpc.avail.so/ws'
},
turing: {
lcUrl: process.env.TURING_LC || 'https://api.lightclient.turing.avail.so/v1',
lcUrl: process.env.TURING_LC || 'https://api.lightclient.turing.avail.so/v2',
url: process.env.TURING_URL as `wss://${string}` || 'wss://turing-rpc.avail.so/ws'
}
};
Expand Down
31 changes: 19 additions & 12 deletions packages/page-explorer/src/BlockInfo/ByHash.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright 2017-2025 @polkadot/app-explorer authors & contributors
// SPDX-License-Identifier: Apache-2.0

/* eslint-disable @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment */

import type { AxiosError } from 'axios';
import type { HeaderExtended } from '@polkadot/api-derive/types';
import type { KeyedEvent } from '@polkadot/react-hooks/ctx/types';
import type { V2Weight } from '@polkadot/react-hooks/useWeight';
Expand Down Expand Up @@ -118,27 +121,31 @@ function BlockByHash ({ className = '', error, value }: Props): React.ReactEleme
console.log('Using Light Client at ', LightClientURI);

axios.get(
`confidence/${number}`,
`blocks/${number}`,
{
baseURL: LightClientURI,
headers: {
'Content-Type': 'application/json'
}
}
).then((v) => {
console.log(v);

if (v.status !== 200) {
if (v.data.confidence !== null) {
setConfidence((v.data.confidence as number).toFixed(4) + '%');
} else if (v.data.status === 'incomplete') {
setConfidence('No Blobs');
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
} else if (v.data.status?.includes('verifying')) {
setConfidence(v.data.status);
} else {
setConfidence('ℹ️ Make sure Light Client runs on ' + LightClientURI);

return;
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
setConfidence(v.data.confidence);
}).catch((_) => {
setConfidence('ℹ️ Make sure Light Client runs on ' + LightClientURI);
console.log('Light client: Called, but failed');
}).catch((e: AxiosError) => {
if (e.status === 404) {
setConfidence('None');
} else {
setConfidence('ℹ️ Make sure Light Client runs on ' + LightClientURI);
console.log('Light client: Called, but failed');
}
});
})
.catch((error: Error): void => {
Expand Down

0 comments on commit 4750d83

Please sign in to comment.