From 6f45181a232e04aa78874904c248fbf3ed9cb806 Mon Sep 17 00:00:00 2001 From: Jaco Date: Fri, 4 Jun 2021 15:45:47 +0300 Subject: [PATCH] Ensure multi destinations for teleport are available (#5454) * Ensure multi destinations for teleport are available * One-way teleport warning * Statemine colors --- packages/apps-config/src/ui/colors.ts | 4 ++-- packages/page-parachains/src/Teleport.tsx | 7 ++++-- packages/react-hooks/src/useTeleport.ts | 26 +++++++++++++++++++---- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/packages/apps-config/src/ui/colors.ts b/packages/apps-config/src/ui/colors.ts index 48a1c55d67..e89f93e790 100644 --- a/packages/apps-config/src/ui/colors.ts +++ b/packages/apps-config/src/ui/colors.ts @@ -128,9 +128,9 @@ const nodeZenlink = 'linear-gradient(45deg, #F20082 0%, #FF4D4D 100%)'; // based on the spec name const specShell = '#2e86ab'; // '#0596FC'; -const specStatemine = '#363'; +const specStatemine = '#113911'; const specStatemint = '#86e62a'; -const specWestmint = '#7b7'; +const specWestmint = '#77bb77'; export { emptyColor }; diff --git a/packages/page-parachains/src/Teleport.tsx b/packages/page-parachains/src/Teleport.tsx index 72834b1775..01c917b5cc 100644 --- a/packages/page-parachains/src/Teleport.tsx +++ b/packages/page-parachains/src/Teleport.tsx @@ -7,7 +7,7 @@ import type { Option } from '@polkadot/apps-config/settings/types'; import React, { useMemo, useState } from 'react'; -import { ChainImg, Dropdown, InputAddress, InputBalance, Modal, TxButton } from '@polkadot/react-components'; +import { ChainImg, Dropdown, InputAddress, InputBalance, MarkWarning, Modal, TxButton } from '@polkadot/react-components'; import { useApi, useTeleport } from '@polkadot/react-hooks'; import { Available } from '@polkadot/react-query'; import { BN_ZERO } from '@polkadot/util'; @@ -47,7 +47,7 @@ function Teleport ({ onClose }: Props): React.ReactElement | null { const [recipientId, setRecipientId] = useState(null); const [senderId, setSenderId] = useState(null); const [recipientParaId, setParaId] = useState(INVALID_PARAID); - const { allowTeleport, destinations, isParaTeleport } = useTeleport(); + const { allowTeleport, destinations, isParaTeleport, oneWay } = useTeleport(); const chainOpts = useMemo( () => destinations.map(createOption), @@ -98,6 +98,9 @@ function Teleport ({ onClose }: Props): React.ReactElement | null { onChange={setParaId} options={chainOpts} /> + {oneWay.includes(recipientParaId) && ( + ('Currently this is a one-way transfer since the on-chain runtime functionality to send the funds from the destination chain back to this account not yet available.')} /> + )} )} ('The beneficiary will have access to the transferred amount when the transaction is included in a block.')}> diff --git a/packages/react-hooks/src/useTeleport.ts b/packages/react-hooks/src/useTeleport.ts index 0577ed6a0d..ab9152d476 100644 --- a/packages/react-hooks/src/useTeleport.ts +++ b/packages/react-hooks/src/useTeleport.ts @@ -16,6 +16,8 @@ interface Teleport { allowTeleport: boolean; destinations: LinkOption[]; isParaTeleport?: boolean; + isRelayTeleport?: boolean; + oneWay: number[] } interface ExtLinkOption extends LinkOption { @@ -24,7 +26,8 @@ interface ExtLinkOption extends LinkOption { const DEFAULT_STATE: Teleport = { allowTeleport: false, - destinations: [] + destinations: [], + oneWay: [] }; const endpoints = createWsEndpoints((k: string, v: string | undefined) => v || k).filter((v): v is ExtLinkOption => !!v.teleport); @@ -38,7 +41,12 @@ function extractRelayDestinations (relayGenesis: string, filter: (l: ExtLinkOpti ) && filter(l) ) .reduce((result: ExtLinkOption[], curr): ExtLinkOption[] => { - if (!result.some(({ genesisHash, paraId }) => paraId === curr.paraId || genesisHash === curr.genesisHash)) { + const isExisting = result.some(({ genesisHash, paraId }) => + paraId === curr.paraId || + (genesisHash && genesisHash === curr.genesisHash) + ); + + if (!isExisting) { result.push(curr); } @@ -68,10 +76,16 @@ export function useTeleport (): Teleport { isNumber(paraId) && endpoint.teleport.includes(paraId) ); + const oneWay = extractRelayDestinations(relayGenesis, ({ paraId, teleport }) => + isNumber(paraId) && + !teleport.includes(-1) + ).map(({ paraId }) => paraId || -1); setState({ allowTeleport: destinations.length !== 0, - destinations + destinations, + isRelayTeleport: true, + oneWay }); } } @@ -85,11 +99,15 @@ export function useTeleport (): Teleport { const destinations = extractRelayDestinations(endpoint.genesisHashRelay, ({ paraId }) => endpoint.teleport.includes(isNumber(paraId) ? paraId : -1) ); + const oneWay = extractRelayDestinations(endpoint.genesisHashRelay, ({ paraId, teleport }) => + !teleport.includes(isNumber(paraId) ? paraId : -1) + ).map(({ paraId }) => paraId || -1); setState({ allowTeleport: destinations.length !== 0, destinations, - isParaTeleport: true + isParaTeleport: true, + oneWay }); } }