From 4bf8a07e8ece2fd338aa6143362d236f66bf2b86 Mon Sep 17 00:00:00 2001 From: Michael Absolon Date: Thu, 12 Dec 2024 01:33:39 +0100 Subject: [PATCH] =?UTF-8?q?feat(playground):=20Add=20support=20for=20multi?= =?UTF-8?q?-assets=20to=20playground=20=F0=9F=9B=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/CurrencySelection.tsx | 131 +++++---- .../src/components/RouterTransferForm.tsx | 63 ++-- .../src/components/TransferForm.tsx | 180 ------------ .../src/components/TransferInfoForm.tsx | 29 +- .../src/components/assets/AssetsForm.tsx | 82 +++--- .../eth-bridge/EthBridgeTransfer.tsx | 3 +- .../eth-bridge/EthBridgeTransferForm.tsx | 7 +- .../components/{ => transfer}/XcmTransfer.tsx | 65 +++-- .../components/transfer/XcmTransferForm.tsx | 270 ++++++++++++++++++ apps/playground/src/routes/XcmSdkSandbox.tsx | 2 +- .../x-transfer-eth/dto/x-transfer-eth.dto.ts | 11 +- .../x-transfer-eth.controller.test.ts | 3 +- .../x-transfer-eth.service.test.ts | 15 +- .../x-transfer-eth/x-transfer-eth.service.ts | 2 - .../src/x-transfer/dto/XTransferDto.ts | 6 + .../builder/evm-builder/EvmBuilder.test.ts | 25 +- .../sdk/src/builder/evm-builder/EvmBuilder.ts | 23 +- .../src/nodes/xTokens/XTokensTransferImpl.ts | 7 +- .../buildEthTransferOptions.test.ts | 15 +- .../ethTransfer/buildEthTransferOptions.ts | 5 +- .../xcmPallet/ethTransfer/ethTransfer.test.ts | 3 +- .../xcmPallet/ethTransfer/ethTransfer.ts | 4 +- .../transfer/resolveOverriddenAsset.test.ts | 2 +- .../transfer/resolveOverriddenAsset.ts | 4 +- packages/sdk/src/types/TBuilder.ts | 8 +- packages/sdk/src/types/TCurrency.ts | 2 + .../transfer/buildTransferExtrinsics.test.ts | 20 ++ .../src/transfer/buildTransferExtrinsics.ts | 18 +- .../src/transfer/transferFromEthereum.ts | 6 +- 29 files changed, 554 insertions(+), 457 deletions(-) delete mode 100644 apps/playground/src/components/TransferForm.tsx rename apps/playground/src/components/{ => transfer}/XcmTransfer.tsx (76%) create mode 100644 apps/playground/src/components/transfer/XcmTransferForm.tsx diff --git a/apps/playground/src/components/CurrencySelection.tsx b/apps/playground/src/components/CurrencySelection.tsx index 24bb5b41..9cda50cc 100644 --- a/apps/playground/src/components/CurrencySelection.tsx +++ b/apps/playground/src/components/CurrencySelection.tsx @@ -11,71 +11,88 @@ import { JsonInput, } from "@mantine/core"; import type { UseFormReturnType } from "@mantine/form"; -import type { FormValues } from "./TransferForm"; +import type { FormValues } from "./transfer/XcmTransferForm"; import { isRelayChain } from "@paraspell/sdk"; type Props = { form: UseFormReturnType; currencyOptions: ComboboxItem[]; + index: number; }; -const CurrencySelection: FC = ({ form, currencyOptions }) => { +const CurrencySelection: FC = ({ form, currencyOptions, index }) => { + const { from, to, currencies } = form.getValues(); + + const isCustomCurrency = currencies[index].isCustomCurrency; + const customCurrencyType = currencies[index].customCurrencyType; + useEffect(() => { - if (!form.values.customCurrencyType) return; - form.setFieldValue("customCurrency", ""); - }, [form.values.customCurrencyType]); + if (!customCurrencyType) return; + form.setFieldValue(`currencies.${index}.customCurrency`, ""); + }, [customCurrencyType]); - const isRelayToPara = isRelayChain(form.values.from); - const isParaToRelay = isRelayChain(form.values.to); + const isRelayToPara = isRelayChain(from); + const isParaToRelay = isRelayChain(to); const isNotParaToPara = isRelayToPara || isParaToRelay; + // If it's not para-to-para, we do not allow custom currencies useEffect(() => { if (isNotParaToPara) { - form.setFieldValue("isCustomCurrency", false); + form.setFieldValue(`currencies.${index}.isCustomCurrency`, false); } }, [isNotParaToPara]); + const options = [ + { label: "Asset ID", value: "id" }, + { label: "Symbol", value: "symbol" }, + { label: "Multi-location", value: "multilocation" }, + ...(currencies.length === 1 + ? [{ label: "Override Multi-location", value: "overridenMultilocation" }] + : []), + ]; + + const size = currencies.length > 1 ? "xs" : "sm"; + return ( - {form.values.isCustomCurrency && - (form.values.customCurrencyType === "id" || - form.values.customCurrencyType === "symbol") && ( + {isCustomCurrency && + (customCurrencyType === "id" || customCurrencyType === "symbol") && ( )} - {form.values.isCustomCurrency && - form.values.customCurrencyType === "multilocation" && ( - - )} + {isCustomCurrency && customCurrencyType === "multilocation" && ( + + )} - {form.values.isCustomCurrency && - form.values.customCurrencyType === "overridenMultilocation" && ( - - )} + {isCustomCurrency && customCurrencyType === "overridenMultilocation" && ( + + )} - {!form.values.isCustomCurrency && ( + {!isCustomCurrency && ( = ({ /> - - + +