Skip to content

Commit

Permalink
Merge pull request #62 from TalismanSociety/refactor/handle-pruned-bl…
Browse files Browse the repository at this point in the history
…ocks

Refactor/handle pruned blocks
  • Loading branch information
chrisling-dev authored Jul 26, 2024
2 parents 65c6ec5 + 17c8a4c commit 7ca9702
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
3 changes: 2 additions & 1 deletion apps/multisig/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ REACT_APP_APPLICATION_NAME=Signet
REACT_APP_HASURA_ENDPOINT=https://signet-metadata.talisman.xyz
REACT_APP_SIWS_ENDPOINT=https://signet-metadata.talisman.xyz/siws
REACT_APP_CONTACT_EMAIL=[email protected]
REACT_APP_SIGNET_LANDING_PAGE=https://talisman.xyz/signet
REACT_APP_SIGNET_LANDING_PAGE=https://talisman.xyz/signet
REACT_APP_ON_FINALITY_API_KEY=
8 changes: 6 additions & 2 deletions apps/multisig/scripts/chaingen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ const subscanUrlsOverride: Record<string, string> = {
'bittensor': 'https://bittensor.com/scan',
}

const rpcUrlsOverride: Record<string, Rpc[]> = {
bittensor: [{ url: `wss://bittensor-finney.api.onfinality.io/ws?apikey=` }],
}

const networkLogoOverride: Record<string, string> = {
'avail-turing-testnet': 'https://www.availproject.org/_next/static/media/logo_large.80d5666f.png',
}
Expand Down Expand Up @@ -108,7 +112,7 @@ const generateSupportedChains = async () => {
nativeToken: {
id: chain.nativeToken?.id,
},
rpcs: chain.rpcs,
rpcs: rpcUrlsOverride[chain.id] ?? chain.rpcs,
squidIds: { chainData: chain.id },
ss58Prefix: chain.prefix,
subscanUrl: subscanUrlsOverride[chain.id] ?? chain.subscanUrl,
Expand All @@ -126,7 +130,7 @@ const generateSupportedChains = async () => {
// DO NOT MODIFY THIS FILE MANUALLY
// This file is auto-generated by scripts/chaingen.ts
export type SupportedChainIds = ${supportedChainIds.map(id => `'${id}'`).join(' | ')}
export const supportedChains: Chain<SupportedChainIds>[] = ${JSON.stringify(supportedChains, null, 2)} as const
export const supportedChains: Chain<SupportedChainIds>[] = ${JSON.stringify(supportedChains, null, 2)}
`
)
}
Expand Down
3 changes: 1 addition & 2 deletions apps/multisig/src/domains/chains/generated-chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export type SupportedChainIds =
| 'rococo-neuro-web-testnet'
| 'polimec'
| 'bittensor'

export const supportedChains: Chain<SupportedChainIds>[] = [
{
chainName: 'Polkadot',
Expand Down Expand Up @@ -702,7 +701,7 @@ export const supportedChains: Chain<SupportedChainIds>[] = [
},
rpcs: [
{
url: 'wss://entrypoint-finney.opentensor.ai:443',
url: 'wss://bittensor-finney.api.onfinality.io/ws?apikey=',
},
],
squidIds: {
Expand Down
6 changes: 5 additions & 1 deletion apps/multisig/src/domains/chains/pjs-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import persistAtom from '@domains/persist'
import { types, rpc, signedExtensions } from 'avail-js-sdk'
import { ApiOptions } from '@polkadot/api/types'

const RPC_PROVIDER = 'onfinality'

export const customRpcsAtom = atom<Record<string, string | undefined>>({
key: 'customRpcs',
default: {},
Expand All @@ -32,7 +34,9 @@ const defaultPjsApiSelector = selectorFamily({
if (rpcs.length === 0) return ApiPromise.create({ provider: new WsProvider([]) })

let opt: ApiOptions = {
provider: new WsProvider(rpcs.map(({ url }) => url)),
provider: new WsProvider(
rpcs.map(({ url }) => (url.includes(RPC_PROVIDER) ? `${url}${process.env.REACT_APP_ON_FINALITY_API_KEY}` : url))
),
}

const customExtension = squidIds ? customExtensions[squidIds.chainData] : undefined
Expand Down
14 changes: 10 additions & 4 deletions apps/multisig/src/domains/chains/storage-getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,26 @@ export const blockHashSelector = selectorFamily({
})

/** Give a {blockHash}-{chainGenesisHash}, get the block on chain */
export const blockSelector = selectorFamily<SignedBlock, string>({
export const blockSelector = selectorFamily<SignedBlock | null, string>({
key: 'blockSelector',
get:
blockAndChainHash =>
async ({ get }) => {
const [blockHash, chainHash] = blockAndChainHash.split('-') as [string, string]

const api = get(pjsApiSelector(chainHash))
const block = await api.rpc.chain.getBlock(blockHash)
return block
try {
const block = await api.rpc.chain.getBlock(blockHash)
return block
} catch (error) {
console.error({ error })
return null
}
},
dangerouslyAllowMutability: true,
})

export const blocksSelector = selectorFamily<SignedBlock[], string>({
export const blocksSelector = selectorFamily<(SignedBlock | null)[], string>({
key: 'blocksSelector',
get:
blockAndChainHashes =>
Expand Down
2 changes: 1 addition & 1 deletion apps/multisig/src/domains/tx-history/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export const useConfirmedTransactions = (teams: Team[]) => {

paginatedTransactions.forEach(tx => {
try {
const block = blocks.find(b => b.block.header.hash.toString() === tx.block.hash)
const block = blocks.find(b => b?.block.header.hash.toString() === tx.block.hash)
const chain = teams.find(t => t.chain.genesisHash === tx.block.chainGenesisHash)?.chain
const chainTokens = chain ? allActiveChainTokens.contents.get(chain.squidIds.chainData) : undefined
const api = apis.contents[tx.block.chainGenesisHash]
Expand Down

0 comments on commit 7ca9702

Please sign in to comment.