Allow empty teleport array (#5434)

* Allow empty teleport array

* Enable para -> relay

* Set Rococo genesis

* No Rococo teleport (yet)
This commit is contained in:
Jaco 2021-06-03 15:19:41 +03:00 committed by GitHub
parent 5df5c4447f
commit 094c3a84e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 30 deletions

View File

@ -21,6 +21,6 @@ export const KUSAMA_GENESIS = getGenesis('kusama');
export const POLKADOT_GENESIS = getGenesis('polkadot');
export const POLKADOT_DENOM_BLOCK = new BN(1248328);
export const ROCOCO_GENESIS = '0x1611e1dbf0405379b861e2e27daa90f480b2e6d3682414a80835a52e8cb8a215';
export const ROCOCO_GENESIS = '0xe7c3d5edde7db964317cd9b51a3a059d7cd99f81bdbce14990047354334c9779';
export const WESTEND_GENESIS = '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e';

View File

@ -55,7 +55,6 @@ export function createRococo (t: TFunction): EndpointOption {
},
{
info: 'rococoStatemint',
isDisabled: true, // Rococo reset
paraId: 1000,
text: t('rpc.rococo.statemint', 'Statemint', { ns: 'apps-config' }),
providers: {

View File

@ -39,7 +39,7 @@ export function createWestend (t: TFunction): EndpointOption {
providers: {
Parity: 'wss://westmint-rpc.polkadot.io'
},
teleport: [-1] // relay only
teleport: [-1] // should be [-1], relay only
},
// (3) parachains with id, see Rococo (info here maps to the actual "named icon")
//

View File

@ -29,10 +29,7 @@ const DEFAULT_STATE: Teleport = {
isParachain: false
};
const endpoints = createWsEndpoints((k: string, v: string | undefined) => v || k).filter((v): v is ExtLinkOption =>
!!v.teleport &&
!!v.teleport.length
);
const endpoints = createWsEndpoints((k: string, v: string | undefined) => v || k).filter((v): v is ExtLinkOption => !!v.teleport);
function extractRelayDestinations (relayGenesis: string, filter: (l: ExtLinkOption) => boolean): ExtLinkOption[] {
return endpoints
@ -60,18 +57,15 @@ function extractRelayDestinations (relayGenesis: string, filter: (l: ExtLinkOpti
export function useTeleport (): Teleport {
const { api, apiUrl, isApiReady } = useApi();
const chainParaId = useCall<ParaId>(isApiReady && api.query.parachainInfo?.parachainId);
const paraId = useCall<ParaId>(isApiReady && api.query.parachainInfo?.parachainId);
const [state, setState] = useState<Teleport>(() => ({ ...DEFAULT_STATE }));
useEffect((): void => {
if (isApiReady) {
const relayGenesis = api.genesisHash.toHex();
const endpoint = endpoints.find(({ value }) =>
value === apiUrl
);
const endpoint = endpoints.find(({ value }) => value === apiUrl);
if (endpoint) {
const destinations = extractRelayDestinations(relayGenesis, ({ paraId }) =>
const destinations = extractRelayDestinations(api.genesisHash.toHex(), ({ paraId }) =>
isNumber(paraId) &&
endpoint.teleport.includes(paraId)
);
@ -86,25 +80,24 @@ export function useTeleport (): Teleport {
}, [api, apiUrl, isApiReady]);
useEffect((): void => {
if (chainParaId) {
const endpoint = endpoints.find(({ paraId, value }) =>
chainParaId.eq(paraId) &&
value === apiUrl
);
if (paraId) {
const endpoint = endpoints.find(({ value }) => value === apiUrl);
setState((prev) => ({
...prev,
allowTeleport: !!endpoint,
destinations: endpoint && endpoint.genesisHashRelay
? extractRelayDestinations(endpoint.genesisHashRelay, ({ paraId }) =>
endpoint.teleport.includes(isNumber(paraId) ? paraId : -1)
)
: [],
isParachain: true,
paraId: chainParaId
}));
if (endpoint && endpoint.genesisHashRelay) {
const destinations = extractRelayDestinations(endpoint.genesisHashRelay, ({ paraId }) =>
endpoint.teleport.includes(isNumber(paraId) ? paraId : -1)
);
setState((prev) => ({
...prev,
allowTeleport: destinations.length !== 0,
destinations,
isParachain: true,
paraId
}));
}
}
}, [apiUrl, chainParaId]);
}, [apiUrl, paraId]);
return state;
}