From cd1f4d47cb434b5d4a5b2425b00e833352898712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Esp=C3=ADn?= Date: Thu, 29 Jun 2023 10:49:52 +0200 Subject: [PATCH] feat: only allow l1 -> l2 native tokens & nfts txs in developer profiles (#7045) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Only allow l1 -> l2 txs in developer profiles * fix * clean up * update comment * clean up * fix * fix * fix * fix: Enable NetworkInput dropdown in non-developer-profiles * fix: Revert changes * clean up * fix: Reset selected destination network when asset changes * fmt * fix: Also check for active tab * fix: Reset network when NFT Id changes * fix: Improve UX for developer profiles --------- Co-authored-by: Begoña Álvarez de la Cruz --- .../components/popups/send/SendFormPopup.svelte | 14 ++++++++++++-- .../shared/components/inputs/NetworkInput.svelte | 9 +++++++-- .../components/molecules/SelectorInput.svelte | 3 ++- .../wallet/types/new-transaction-details.type.ts | 4 ++-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/packages/desktop/components/popups/send/SendFormPopup.svelte b/packages/desktop/components/popups/send/SendFormPopup.svelte index 02fe2b0f0f6..84cd51d735a 100644 --- a/packages/desktop/components/popups/send/SendFormPopup.svelte +++ b/packages/desktop/components/popups/send/SendFormPopup.svelte @@ -10,6 +10,7 @@ newTransactionDetails, NewTransactionType, setNewTransactionDetails, + TokenStandard, } from '@core/wallet' import { selectedAccount } from '@core/account/stores' import { @@ -25,6 +26,7 @@ TextType, } from 'shared/components' import features from '@features/features' + import { activeProfile } from '@core/profile' enum SendForm { SendToken = 'general.sendToken', @@ -37,7 +39,8 @@ } const transactionDetails = get(newTransactionDetails) - let { metadata, recipient, tag, layer2Parameters, disableAssetSelection } = transactionDetails + let { metadata, recipient, tag, layer2Parameters } = transactionDetails + const { disableAssetSelection } = transactionDetails let assetAmountInput: AssetAmountInput let nftInput: NftInput @@ -68,6 +71,13 @@ $: hasSpendableNfts = $ownedNfts.some((nft) => nft.isSpendable) $: isLayer2 = !!iscpChainAddress $: isSendTokenTab = activeTab === SendForm.SendToken + $: isBaseToken = + activeTab === SendForm.SendToken && + transactionDetails.type === NewTransactionType.TokenTransfer && + asset?.metadata?.standard === TokenStandard.BaseToken + // Only allow L1 -> L2 transactions in developer profiles when transfering other than base tokens + $: showLayer2 = features?.network?.layer2?.enabled && ($activeProfile.isDeveloperProfile || isBaseToken) + $: asset, nftId, !showLayer2 && networkInput?.reset() function setTransactionDetails(): void { layer2Parameters = isLayer2 @@ -180,7 +190,7 @@ {:else} {/if} - + diff --git a/packages/shared/components/molecules/SelectorInput.svelte b/packages/shared/components/molecules/SelectorInput.svelte index 56ba7bf1751..4133ad318f6 100644 --- a/packages/shared/components/molecules/SelectorInput.svelte +++ b/packages/shared/components/molecules/SelectorInput.svelte @@ -53,7 +53,8 @@ setFilteredOptions() } - function resetValue(): void { + export function resetValue(newSelected?: IOption): void { + if (newSelected) selected = newSelected value = selected?.key ?? selected?.value } diff --git a/packages/shared/lib/core/wallet/types/new-transaction-details.type.ts b/packages/shared/lib/core/wallet/types/new-transaction-details.type.ts index 13eba03c4cf..41abf896aab 100644 --- a/packages/shared/lib/core/wallet/types/new-transaction-details.type.ts +++ b/packages/shared/lib/core/wallet/types/new-transaction-details.type.ts @@ -22,8 +22,8 @@ type NewBaseTransactionDetails = { export type NewTokenTransactionDetails = NewBaseTransactionDetails & { type: NewTransactionType.TokenTransfer rawAmount: string - asset: IAsset - unit: string + asset?: IAsset + unit?: string } export type NewNftTransactionDetails = NewBaseTransactionDetails & {