Skip to content
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
19 changes: 12 additions & 7 deletions components/SignForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -907,13 +907,18 @@ export default function SignForm({
const xls35Sell = signRequest?.request?.TransactionType === 'URITokenCreateSellOffer'

const checkBoxText = (screen, signRequest) => {
if (screen === 'nftTransfer')
return (
<Trans i18nKey="signin.confirm.nft-transfer">
I'm offering that NFT for FREE to the Destination account,{' '}
<span className="orange bold">the destination account would need to accept the NFT transfer</span>.
</Trans>
)
if (screen === 'nftTransfer') {
if (signRequest.request?.TransactionType === 'Remit') {
return "I'm sending this NFT for FREE."
} else {
return (
<Trans i18nKey="signin.confirm.nft-transfer">
I'm offering that NFT for FREE to the Destination account,{' '}
<span className="orange bold">the destination account would need to accept the NFT transfer</span>.
</Trans>
)
}
}

if (screen === 'NFTokenBurn') return t('signin.confirm.nft-burn')
if (screen === 'NFTokenModify') return 'I understand that URI will be updated for this NFT.'
Expand Down
95 changes: 90 additions & 5 deletions components/SignForms/NftTransfer.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,96 @@
import { useTranslation } from 'next-i18next'
import { isAddressValid } from '../../utils'
import { useState, useEffect } from 'react'
import { isAddressValid, xahauNetwork } from '../../utils'
import AddressInput from '../UI/AddressInput'
import CheckBox from '../UI/CheckBox'
import axios from 'axios'

export default function NftTransfer({ setSignRequest, signRequest, setStatus, setFormError }) {
const { t } = useTranslation()
const [useRemit, setUseRemit] = useState(false)
const [destinationRemitDisabled, setDestinationRemitDisabled] = useState(false)
const [touched, setTouched] = useState(false)

useEffect(() => {
// Check if destination allows incoming remit when address changes
const checkDestinationRemit = async () => {
if (!signRequest.request?.Destination) {
setDestinationRemitDisabled(false)
return
}

try {
const response = await axios(`/v2/address/${signRequest.request.Destination}?ledgerInfo=true`)
const accountData = response?.data

if (accountData?.ledgerInfo?.flags) {
const flags = accountData.ledgerInfo.flags
const disallowIncomingRemit = flags.disallowIncomingRemit
setDestinationRemitDisabled(disallowIncomingRemit)
} else {
setDestinationRemitDisabled(false)
}
} catch (error) {
console.error('Error checking destination remit status:', error)
setDestinationRemitDisabled(false)
}
}

if (xahauNetwork) {
// check only on xahau network
checkDestinationRemit()
}
//eslint-disable-next-line react-hooks/exhaustive-deps
}, [signRequest.request?.Destination])

useEffect(() => {
if (xahauNetwork) {
const newRequest = { ...signRequest.request }
if (useRemit) {
newRequest.TransactionType = 'Remit'
if (newRequest.URITokenID) {
newRequest.URITokenIDs = [newRequest.URITokenID]
delete newRequest.URITokenID
}
delete newRequest.Amount
} else {
newRequest.TransactionType = 'URITokenCreateSellOffer'
newRequest.Amount = '0'
if (newRequest.URITokenIDs?.[0]) {
newRequest.URITokenID = newRequest.URITokenIDs[0]
delete newRequest.URITokenIDs
}
}
setSignRequest({ ...signRequest, request: newRequest })
}
//eslint-disable-next-line react-hooks/exhaustive-deps
}, [useRemit])

const onAddressChange = (value) => {
let newRequest = signRequest
if (!touched && !value) return

setTouched(true)

const newRequest = { ...signRequest, request: { ...signRequest.request } }

if (!value) {
delete newRequest.request.Destination
setFormError(false)
setStatus('')
setSignRequest(newRequest)
return
}

if (isAddressValid(value)) {
newRequest.request.Destination = value
setFormError(false)
setStatus('')
} else {
if (newRequest.request.Destination) {
delete newRequest.request.Destination
}
delete newRequest.request.Destination
setStatus(t('form.error.address-invalid'))
setFormError(true)
}

setSignRequest(newRequest)
}

Expand All @@ -33,6 +106,18 @@ export default function NftTransfer({ setSignRequest, signRequest, setStatus, se
hideButton={true}
/>
</span>

{/* Remit option for Xahau network */}
{xahauNetwork && (
<div className="terms-checkbox">
<CheckBox checked={useRemit} setChecked={setUseRemit} name="use-remit" disabled={destinationRemitDisabled}>
Pay the NFT reserve for the destination (immediate NFT transfer).
{destinationRemitDisabled && (
<span className="red"> (Disabled - destination has incoming Remit disabled)</span>
)}
</CheckBox>
</div>
)}
</div>
)
}