From e1c2281a3d1d7ecb8622e3bd3c3eced8854ae8a6 Mon Sep 17 00:00:00 2001 From: hassnian <44554284+hassnian@users.noreply.github.com> Date: Tue, 3 Dec 2024 07:06:46 +0500 Subject: [PATCH 01/17] ref: init `UserCartModal` component --- components/common/ItemTransferModal.vue | 121 +++++++++++++++ .../UserCartModal.vue} | 146 ++++-------------- .../UserCartMultipleItems.vue} | 0 .../UserCartSingleItem.vue} | 0 .../GalleryItemMoreActionBtn.vue | 1 - 5 files changed, 149 insertions(+), 119 deletions(-) create mode 100644 components/common/ItemTransferModal.vue rename components/common/{itemTransfer/ItemTransferModal.vue => userCart/UserCartModal.vue} (60%) rename components/common/{itemTransfer/ItemTransferMultipleItems.vue => userCart/UserCartMultipleItems.vue} (100%) rename components/common/{itemTransfer/ItemTransferSingleItem.vue => userCart/UserCartSingleItem.vue} (100%) diff --git a/components/common/ItemTransferModal.vue b/components/common/ItemTransferModal.vue new file mode 100644 index 0000000000..58e80d34ff --- /dev/null +++ b/components/common/ItemTransferModal.vue @@ -0,0 +1,121 @@ + + + diff --git a/components/common/itemTransfer/ItemTransferModal.vue b/components/common/userCart/UserCartModal.vue similarity index 60% rename from components/common/itemTransfer/ItemTransferModal.vue rename to components/common/userCart/UserCartModal.vue index ff3fdbad16..2617d0e047 100644 --- a/components/common/itemTransfer/ItemTransferModal.vue +++ b/components/common/userCart/UserCartModal.vue @@ -6,7 +6,7 @@ :is-loading="isLoading" :status="status" close-at-signed - @try-again="itemTransfer" + @try-again="exectTransaction" />
- -
-
- -

- {{ $t('transaction.transferTo') }} -

- - +
@@ -68,7 +54,7 @@ :fees="{ forceActionAutoFees: true }" :actions="actions" :disabled="isDisabled" - :label="transferItemLabel" + :label="label" variant="primary" no-shadow with-shortcut @@ -78,17 +64,7 @@ @confirm="handleTransfer" /> -
- - -

- {{ $t('transaction.wrongAddressCannotRecoveredWarning') }} -

-
+
@@ -96,53 +72,41 @@ diff --git a/components/common/itemTransfer/ItemTransferMultipleItems.vue b/components/common/userCart/UserCartMultipleItems.vue similarity index 100% rename from components/common/itemTransfer/ItemTransferMultipleItems.vue rename to components/common/userCart/UserCartMultipleItems.vue diff --git a/components/common/itemTransfer/ItemTransferSingleItem.vue b/components/common/userCart/UserCartSingleItem.vue similarity index 100% rename from components/common/itemTransfer/ItemTransferSingleItem.vue rename to components/common/userCart/UserCartSingleItem.vue diff --git a/components/gallery/GalleryItemButton/GalleryItemMoreActionBtn.vue b/components/gallery/GalleryItemButton/GalleryItemMoreActionBtn.vue index 99f39ddb53..e4ef4dc958 100644 --- a/components/gallery/GalleryItemButton/GalleryItemMoreActionBtn.vue +++ b/components/gallery/GalleryItemButton/GalleryItemMoreActionBtn.vue @@ -73,7 +73,6 @@ import { sanitizeIpfsUrl, toOriginalContentUrl } from '@/utils/ipfs' import { isMobileDevice } from '@/utils/extension' import { hasOperationsDisabled } from '@/utils/prefix' import { refreshOdaTokenMetadata } from '@/services/oda' -import ItemTransferModal from '@/components/common/itemTransfer/ItemTransferModal.vue' import type { NFT } from '@/types' import type { Abi } from '@/composables/transaction/types' From 2004e2a814f25320b62f68fb8abe05cd466d868f Mon Sep 17 00:00:00 2001 From: hassnian <44554284+hassnian@users.noreply.github.com> Date: Tue, 3 Dec 2024 19:41:40 +0500 Subject: [PATCH 02/17] fix(UserCartModal.vue): missing `exectTransaction` function --- components/common/userCart/UserCartModal.vue | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/components/common/userCart/UserCartModal.vue b/components/common/userCart/UserCartModal.vue index 2617d0e047..8cf029e42c 100644 --- a/components/common/userCart/UserCartModal.vue +++ b/components/common/userCart/UserCartModal.vue @@ -6,7 +6,7 @@ :is-loading="isLoading" :status="status" close-at-signed - @try-again="exectTransaction" + @try-again="execTransaction" /> { closeModal() } +const execTransaction = async () => { + try { + await transaction(action.value) + } + catch (error) { + warningMessage(error) + } +} + const handleTransfer = async ({ autoteleport }: AutoTeleportActionButtonConfirmEvent) => { try { clearTransaction() @@ -144,7 +153,7 @@ const handleTransfer = async ({ autoteleport }: AutoTeleportActionButtonConfirmE autoTeleport.value = autoteleport if (!autoteleport) { - await transaction(action.value) + await execTransaction() } closeModal() From 894f666b9e8fc458443d3e0fbaa5f1127956ba58 Mon Sep 17 00:00:00 2001 From: hassnian <44554284+hassnian@users.noreply.github.com> Date: Tue, 3 Dec 2024 19:42:20 +0500 Subject: [PATCH 03/17] fix(ItemTransferModal.vue): `isYourAddress` invalid not working --- components/common/ItemTransferModal.vue | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/components/common/ItemTransferModal.vue b/components/common/ItemTransferModal.vue index 58e80d34ff..57d779e279 100644 --- a/components/common/ItemTransferModal.vue +++ b/components/common/ItemTransferModal.vue @@ -22,7 +22,7 @@ class="flex-1" placeholder="Enter wallet address" with-address-check - @check="handleAddressCheck" + @check="isValid => isAddressValid = isValid" /> @@ -77,7 +77,7 @@ const transferItemLabel = computed(() => { return $i18n.t('transaction.transferNft') }) -const isYourAddress = computed(() => accountId.value === getChainAddress(address.value)) +const isYourAddress = computed(() => getChainAddress(accountId.value) === getChainAddress(address.value)) const loading = computed(() => (isEvm(urlPrefix.value) ? !abi.value : false)) const disabled = computed( @@ -106,10 +106,6 @@ const reset = () => { isAddressValid.value = false } -const handleAddressCheck = (isValid: boolean) => { - isAddressValid.value = isValid -} - const getChainAddress = (value: string) => { try { return toSubstrateAddress(value) From d902547d58b4c19f45a4a7aabcd838f5fa2bc4fd Mon Sep 17 00:00:00 2001 From: hassnian <44554284+hassnian@users.noreply.github.com> Date: Tue, 3 Dec 2024 19:53:18 +0500 Subject: [PATCH 04/17] ref(UserCartModal.vue): `submit` function --- components/common/userCart/UserCartModal.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/common/userCart/UserCartModal.vue b/components/common/userCart/UserCartModal.vue index 8cf029e42c..ba46a0b30d 100644 --- a/components/common/userCart/UserCartModal.vue +++ b/components/common/userCart/UserCartModal.vue @@ -61,7 +61,7 @@ early-success auto-close-modal :auto-close-modal-delay-modal="0" - @confirm="handleTransfer" + @confirm="submit" /> @@ -146,7 +146,7 @@ const execTransaction = async () => { } } -const handleTransfer = async ({ autoteleport }: AutoTeleportActionButtonConfirmEvent) => { +const submit = async ({ autoteleport }: AutoTeleportActionButtonConfirmEvent) => { try { clearTransaction() From f8790a46ba7c23f52bb5b786c1d9fed7eed4f630 Mon Sep 17 00:00:00 2001 From: hassnian <44554284+hassnian@users.noreply.github.com> Date: Tue, 3 Dec 2024 20:02:16 +0500 Subject: [PATCH 05/17] ref(UserCartModal.vue): add `title` and `signingTitle` props --- components/common/ItemTransferModal.vue | 6 ++++-- components/common/userCart/UserCartModal.vue | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/components/common/ItemTransferModal.vue b/components/common/ItemTransferModal.vue index 57d779e279..062145a404 100644 --- a/components/common/ItemTransferModal.vue +++ b/components/common/ItemTransferModal.vue @@ -2,8 +2,10 @@ userCartModal.value?.items || [] as ListCartItem[]) const nft = computed(() => items.value[0]) const abi = useCollectionAbi(computed(() => nft.value?.collection.id)) -const transferItemLabel = computed(() => { +const label = computed(() => { if (!address.value) { return $i18n.t('transaction.inputAddressFirst') } diff --git a/components/common/userCart/UserCartModal.vue b/components/common/userCart/UserCartModal.vue index ba46a0b30d..164ab99c31 100644 --- a/components/common/userCart/UserCartModal.vue +++ b/components/common/userCart/UserCartModal.vue @@ -2,7 +2,7 @@
() const isModalActive = defineModel({ type: Boolean, required: true }) @@ -172,7 +174,7 @@ useTransactionNotification({ init: () => { return notification(({ isSessionState, notify, session }) => { return notify({ - title: ref($i18n.t('transaction.transferingNft', items.value.length)), + title: ref(props.signingTitle), state: computed(() => session?.value.state as LoadingNotificationState), action: computed(() => { return isSessionState('succeeded') From c5d5839e5812f88f3a7e0d2a0fe9c008a9c8abe8 Mon Sep 17 00:00:00 2001 From: hassnian <44554284+hassnian@users.noreply.github.com> Date: Tue, 3 Dec 2024 20:19:19 +0500 Subject: [PATCH 06/17] ref(UserCartModal.vue): add `mode` prop` --- components/common/ItemTransferModal.vue | 5 +---- .../common/listingCart/ListingCartMini.vue | 18 +++++++++++++++++- components/common/userCart/UserCartModal.vue | 6 +++--- stores/preferences.ts | 6 ++++-- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/components/common/ItemTransferModal.vue b/components/common/ItemTransferModal.vue index 062145a404..0e03e5c4f1 100644 --- a/components/common/ItemTransferModal.vue +++ b/components/common/ItemTransferModal.vue @@ -1,7 +1,7 @@ diff --git a/components/gallery/GalleryItemButton/GalleryItemMoreActionBtn.vue b/components/gallery/GalleryItemButton/GalleryItemMoreActionBtn.vue index e4ef4dc958..6273b793df 100644 --- a/components/gallery/GalleryItemButton/GalleryItemMoreActionBtn.vue +++ b/components/gallery/GalleryItemButton/GalleryItemMoreActionBtn.vue @@ -4,10 +4,10 @@ :title="signingModalTitle" :is-loading="isLoading" :status="status" - @try-again="burn" + @try-again="tryAgain" /> - + Transfer NFT @@ -93,8 +93,9 @@ const props = defineProps<{ abi?: Abi | null }>() -const action = ref('') +const action = ref<'unlist' | ''>('') +const id = computed(() => route.params.id.toString()) const isOwner = computed(() => accountId.value === props.nft?.currentOwner) const isCollectionOwner = computed(() => accountId.value === props.nft?.collection?.currentOwner) const nftId = computed(() => props.nft?.id || '') @@ -102,7 +103,7 @@ const nftId = computed(() => props.nft?.id || '') const { data } = useQuery({ queryKey: ['nft-with-metadata', nftId], queryFn: async () => - nftId.value && canTransfer.value + nftId.value && canDoActions.value ? (await useAsyncGraphql({ query: 'nftEntitiesByIDs', variables: { ids: [nftId.value] }, @@ -111,12 +112,11 @@ const { data } = useQuery({ }) const nftWithMetadata = computed(() => data.value?.nftEntities?.[0]) -const canTransfer = computed(() => props.nft && isOwner.value) +const canDoActions = computed(() => props.nft && isOwner.value) const signingModalTitle = computed(() => { return ( { - burn: $i18n.t('mint.nft.burning'), unlist: $i18n.t('mint.nft.delisting'), }[action.value] || '' ) @@ -164,17 +164,12 @@ const downloadMedia = async () => { } const burn = () => { - action.value = 'burn' - transaction({ - interaction: Interaction.CONSUME, - urlPrefix: urlPrefix.value, - nftId: route.params.id as string, - nftSn: props.nft?.sn as string, - collectionId: props.nft?.collection?.id as string, - abi: props.abi, - successMessage: $i18n.t('transaction.consume.success') as string, - errorMessage: $i18n.t('transaction.consume.error') as string, - }) + openUserCartModal('burn') +} + +const tryAgain = () => { + const map = { unlist } + map[action.value]?.() } const unlist = () => { @@ -183,7 +178,7 @@ const unlist = () => { interaction: Interaction.LIST, urlPrefix: urlPrefix.value, token: { - nftId: route.params.id as string, + nftId: id.value, price: '0', }, successMessage: $i18n.t('transaction.unlist.success') as string, @@ -198,10 +193,12 @@ const refreshMetadata = async () => { } } -const transfer = () => { +const openUserCartModal = (mode: UserCartMode) => { if (nftWithMetadata.value) { listNftByNftWithMetadata(nftWithMetadata.value) - preferencesStore.itemTransferCartModalOpen = true + preferencesStore.setOpenedUserCartModal(mode) } } + +const transfer = () => openUserCartModal('transfer') diff --git a/components/migrate/steps/SignLoader3.vue b/components/migrate/steps/SignLoader3.vue index e704859fee..ddc182f8eb 100644 --- a/components/migrate/steps/SignLoader3.vue +++ b/components/migrate/steps/SignLoader3.vue @@ -82,8 +82,10 @@ diff --git a/composables/useCollectionAbi.ts b/composables/useCollectionAbi.ts index 8142da1b62..1932adad54 100644 --- a/composables/useCollectionAbi.ts +++ b/composables/useCollectionAbi.ts @@ -1,12 +1,16 @@ import { useQuery } from '@tanstack/vue-query' import type { Prefix } from '@kodadot1/static' +import type { MaybeComputedRef } from '@vueuse/core' import { fetchOdaCollectionAbi } from '@/services/oda' -export default (collectionId: Ref, prefix: Ref = usePrefix().urlPrefix) => { +export default (collectionId: Ref, { + prefix = usePrefix().urlPrefix, + disabled = false, +}: { prefix?: Ref, disabled?: MaybeComputedRef } = {}) => { const { data: abi } = useQuery({ queryKey: ['collection-abi', collectionId], queryFn: () => isEvm(prefix.value) ? fetchOdaCollectionAbi(prefix.value, collectionId.value as string) : Promise.resolve(null), - enabled: computed(() => Boolean(collectionId.value)), + enabled: computed(() => Boolean(collectionId.value) && !unref(disabled)), }) return abi From 63f898e225d45ec3e9dd8b05a383d21fc23c5870 Mon Sep 17 00:00:00 2001 From: hassnian <44554284+hassnian@users.noreply.github.com> Date: Fri, 6 Dec 2024 06:49:40 +0500 Subject: [PATCH 13/17] fix: deepscan local variable not used. --- components/common/ItemTransferModal.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/common/ItemTransferModal.vue b/components/common/ItemTransferModal.vue index c818c8aca3..d6821220c0 100644 --- a/components/common/ItemTransferModal.vue +++ b/components/common/ItemTransferModal.vue @@ -6,8 +6,8 @@ :signing-title="$t('transaction.transferingNft', items.length)" :get-action="getAction" :label="label" - :disabled - :loading + :disabled="disabled" + :loading="loading" @reset="reset" > From f30179d6a46163c8160a640d2eb786b799c53971 Mon Sep 17 00:00:00 2001 From: hassnian <44554284+hassnian@users.noreply.github.com> Date: Sat, 7 Dec 2024 07:31:24 +0500 Subject: [PATCH 17/17] fix(AddressInput.vue): `strict` prop as `optional` --- components/shared/AddressInput.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/shared/AddressInput.vue b/components/shared/AddressInput.vue index 0a5a0122fa..0b2d17f682 100644 --- a/components/shared/AddressInput.vue +++ b/components/shared/AddressInput.vue @@ -37,7 +37,7 @@ const props = withDefaults( modelValue: string label?: string emptyOnError?: boolean - strict: boolean + strict?: boolean icon?: string placeholder?: string disableError?: boolean