Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Evm Can't transfer or burn your own NFT #11220

Merged
merged 5 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions components/buy/SuccessfulBuyModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const isModalActive = useVModel(props, 'modelValue')

const { $i18n } = useNuxtApp()
const { urlPrefix } = usePrefix()
const { accountId } = useAuth()
const { accountId, isCurrentAccount } = useAuth()
const { listNftByShoppingCartItem, openListingCartModal } = useListingCartModal(
{
clearItemsOnBeforeUnmount: true,
Expand Down Expand Up @@ -122,9 +122,7 @@ const watchCurrentOwners = () => {
}`,
onChange: ({ data: { nftEntities } }) => {
const currentOwners: string[] = nftEntities.map(nft => nft.currentOwner)
canListItems.value = currentOwners.every(
currentOwner => currentOwner === accountId.value,
)
canListItems.value = currentOwners.every(isCurrentAccount)
},
})
}
Expand Down
6 changes: 3 additions & 3 deletions components/collection/CollectionGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const props = defineProps<{

const slots = useSlots()
const route = useRoute()
const { accountId } = useAuth()
const { isCurrentAccount } = useAuth()
const { urlPrefix, client } = usePrefix()
const preferencesStore = usePreferencesStore()

Expand Down Expand Up @@ -118,8 +118,8 @@ const getQueryVariables = (page: number) => {
? { currentOwner_eq: props.id, burned_eq: false }
: { issuer_eq: props.id }

if (isProfilePage && accountId.value !== props.id) {
Object.assign(searchParams, { nftCount_not_eq: 0 })
if (isProfilePage && !isCurrentAccount(props.id)) {
Object.assign(searchParams, { supply_not_eq: 0 })
}

return props.id
Expand Down
4 changes: 2 additions & 2 deletions components/collection/HeroButtons.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ import { useCollectionMinimal } from '@/components/collection/utils/useCollectio
import { hasOperationsDisabled } from '@/utils/prefix'

const route = useRoute()
const { isCurrentOwner } = useAuth()
const { isCurrentAccount } = useAuth()
const { urlPrefix } = usePrefix()
const { $i18n } = useNuxtApp()
const { toast } = useToast()
Expand Down Expand Up @@ -182,7 +182,7 @@ const openUrl = (url: string) => {
}

const displaySeperator = computed(() => twitter.value)
const isOwner = computed(() => isCurrentOwner(collection.value?.currentOwner))
const isOwner = computed(() => isCurrentAccount(collection.value?.currentOwner))

const QRModalActive = ref(false)
</script>
Expand Down
4 changes: 2 additions & 2 deletions components/common/ItemTransferModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import { type UserCartModalExpose } from '@/components/common/userCart/UserCartM

const { $i18n } = useNuxtApp()
const { urlPrefix } = usePrefix()
const { accountId } = useAuth()
const { isCurrentAccount } = useAuth()

const userCartModal = ref<UserCartModalExpose>()
const address = ref('')
Expand All @@ -76,7 +76,7 @@ const label = computed(() => {
return $i18n.t('transaction.transferNft')
})

const isYourAddress = computed(() => getChainAddress(accountId.value) === getChainAddress(address.value))
const isYourAddress = computed(() => isCurrentAccount(getChainAddress(address.value) || ''))
const loading = computed(() => (isEvm(urlPrefix.value) ? !abi.value : false))

const disabled = computed(
Expand Down
4 changes: 2 additions & 2 deletions components/gallery/GalleryItemAction/GalleryItemAction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ const props = defineProps<{
}>()

const { urlPrefix } = usePrefix()
const { isCurrentOwner } = useAuth()
const isOwner = computed(() => isCurrentOwner(props.nft?.currentOwner))
const { isCurrentAccount } = useAuth()
const isOwner = computed(() => isCurrentAccount(props.nft?.currentOwner))
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ const props = defineProps<{
}>()
const preferencesStore = usePreferencesStore()
const makeOfferStore = useMakingOfferStore()
const { doAfterLogin } = useDoAfterlogin()
const { isCurrentOwner, isLogIn } = useAuth()
const isOwner = computed(() => isCurrentOwner(props.nft?.currentOwner))
const swapStore = useAtomicSwapStore()
const { doAfterLogin } = useDoAfterlogin()
const { isCurrentAccount, isLogIn } = useAuth()
const isOwner = computed(() => isCurrentAccount(props.nft?.currentOwner))

const highestOfferPrice = computed(() => props.highestOffer?.price || '')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import type { Abi } from '@/composables/transaction/types'

const { $i18n, $consola } = useNuxtApp()
const { toast } = useToast()
const { accountId } = useAuth()
const { isCurrentAccount } = useAuth()
const { transaction, isLoading, status } = useTransaction()
const { listNftByNftWithMetadata } = useListingCartModal()
const preferencesStore = usePreferencesStore()
Expand All @@ -96,8 +96,8 @@ const props = defineProps<{
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 isOwner = computed(() => isCurrentAccount(props.nft?.currentOwner))
const isCollectionOwner = computed(() => isCurrentAccount(props.nft?.collection?.currentOwner))
const nftId = computed(() => props.nft?.id || '')

const { data } = useQuery({
Expand Down
4 changes: 2 additions & 2 deletions components/gallery/UnlockableTag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ const props = defineProps<{
link: string | undefined
}>()

const { isCurrentOwner } = useAuth()
const { isCurrentAccount } = useAuth()
const { isMobile } = useViewport()
const { unlockableIcon } = useIcon()

const isOwner = computed(() => isCurrentOwner(props.nft?.currentOwner))
const isOwner = computed(() => isCurrentAccount(props.nft?.currentOwner))
</script>

<style lang="scss" scoped>
Expand Down
4 changes: 2 additions & 2 deletions components/items/ItemsGrid/ItemsGridImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ import { usePreferencesStore } from '@/stores/preferences'
import { nftToShoppingCartItem } from '@/components/common/shoppingCart/utils'

const { placeholder } = useTheme()
const { isLogIn, isCurrentOwner } = useAuth()
const { isLogIn, isCurrentAccount } = useAuth()
const { urlPrefix } = usePrefix()
const { doAfterLogin } = useDoAfterlogin()
const shoppingCartStore = useShoppingCartStore()
Expand Down Expand Up @@ -128,7 +128,7 @@ const buyLabel = computed(function () {
)
})

const isOwner = computed(() => isCurrentOwner(props.nft?.currentOwner))
const isOwner = computed(() => isCurrentAccount(props.nft?.currentOwner))

const openCompletePurcahseModal = () => {
preferencesStore.setCompletePurchaseModal({
Expand Down
4 changes: 2 additions & 2 deletions components/items/ItemsGrid/useItemsGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ export const updatePotentialNftsForListingCart = async (
nfts: (NFT & TokenId)[],
) => {
const listingCartStore = useListingCartStore()
const { isCurrentOwner } = useAuth()
const { isCurrentAccount } = useAuth()
const potentialNfts = nfts
.filter(nft => !Number(nft.price) && isCurrentOwner(nft.currentOwner))
.filter(nft => !Number(nft.price) && isCurrentAccount(nft.currentOwner))
.map((nft) => {
const floorPrice = nft.collection.floorPrice[0]?.price || '0'
return nftToListingCartItem(nft, floorPrice)
Expand Down
4 changes: 2 additions & 2 deletions components/items/ItemsGrid/useNftActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export const checkIfAnythingToList = async (entities: TokenEntity[]) => {
}

export function useNftActions(entity: TokenEntity) {
const { isCurrentOwner } = useAuth()
const { isCurrentAccount } = useAuth()

const cheapestNFT = ref<NFTWithMetadata>()

Expand All @@ -142,7 +142,7 @@ export function useNftActions(entity: TokenEntity) {

const isThereAnythingToList = ref<boolean>()
const isStackComputed = computed(() => isStack(entity))
const isOwner = computed(() => isCurrentOwner(entity.cheapest.currentOwner))
const isOwner = computed(() => isCurrentAccount(entity.cheapest.currentOwner))
const isAvailableToBuyComputed = computed(() => isAvailableToBuy(entity))
const nftForShoppingCart = computed(() =>
isTokenEntity(entity) ? entity.cheapest : entity,
Expand Down
8 changes: 4 additions & 4 deletions components/profile/ProfileDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ const route = useRoute()
const { $i18n } = useNuxtApp()
const { toast } = useToast()
const { replaceUrl } = useReplaceUrl()
const { accountId, isCurrentOwner } = useAuth()
const { isCurrentAccount } = useAuth()
const { urlPrefix, client } = usePrefix()
const { shareOnX, shareOnFarcaster } = useSocialShare()
const profileOnboardingStore = useProfileOnboardingStore()
Expand Down Expand Up @@ -621,7 +621,7 @@ const socialDropdownItems = computed(() => {
.sort((a, b) => a?.order - b?.order)
})

const isOwner = computed(() => isCurrentOwner(id.value))
const isOwner = computed(() => isCurrentAccount(id.value))

const buttonConfig = computed<ButtonConfig>(() =>
hasProfile.value ? editProfileConfig : createProfileConfig,
Expand Down Expand Up @@ -726,8 +726,8 @@ useAsyncData('tabs-count', async () => {
currentOwner_eq: address,
}

if (accountId.value !== address) {
Object.assign(searchParams, { nftCount_not_eq: 0 })
if (!isCurrentAccount(address)) {
Object.assign(searchParams, { supply_not_eq: 0 })
}

searchParams['burned_eq'] = false
Expand Down
5 changes: 2 additions & 3 deletions composables/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ export default function () {
const isLogIn = computed(() => Boolean(identityStore.getAuthAddress))
const balance = computed(() => identityStore.getAuthBalance)

const isCurrentOwner = (address?: string) =>
accountsAreSame(accountId.value, address)
const isCurrentAccount = (address?: string) => accountsAreSame(accountId.value, address)

return {
accountId,
isLogIn,
balance,
isCurrentOwner,
isCurrentAccount,
}
}
13 changes: 12 additions & 1 deletion utils/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,24 @@ export const formatAccount = (
return encodeAddress(decodeAddress(address), <any>ss58Format)
}

const isSameAddressSubstrate = (address1: string, address2: string): boolean => {
return addressEq(address1, address2)
}

const isSameAddressEvm = (address1: string, address2: string): boolean => {
return address1.toLowerCase() === address2.toLowerCase()
}

export const isSameAccount = (
account1: KeyringAccount | string,
account2: KeyringAccount | string,
): boolean => {
const address1 = accountToAddress(account1)
const address2 = accountToAddress(account2)
return addressEq(address1, address2)

return isEthereumAddress(address1)
? isSameAddressEvm(address1, address2)
: isSameAddressSubstrate(address1, address2)
}
vikiival marked this conversation as resolved.
Show resolved Hide resolved

export const accountsAreSame = (
Expand Down
Loading