Skip to content

checks need to be checked #435

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 3 additions & 3 deletions components/Services/Amm/AMMCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Link from 'next/link'
import { multiply } from '../../../utils/calc'
import CheckBox from '../../UI/CheckBox'
import FormInput from '../../UI/FormInput'
import { nativeCurrency, typeNumberOnly } from '../../../utils'
import { nativeCurrency, typeNumberOnly, isNativeCurrency } from '../../../utils'
import TokenSelector from '../../UI/TokenSelector'
import { LinkAmm, LinkTx } from '../../../utils/links'
import CopyButton from '../../UI/CopyButton'
Expand Down Expand Up @@ -56,7 +56,7 @@ export default function AMMCreateForm({ setSignRequest }) {
}

// Asset 1 amount formatting
if (asset1.currency === nativeCurrency) {
if (isNativeCurrency(asset1)) {
ammCreate.Amount = multiply(asset1Amount, 1000000)
} else {
ammCreate.Amount = {
Expand All @@ -67,7 +67,7 @@ export default function AMMCreateForm({ setSignRequest }) {
}

// Asset 2 amount formatting
if (asset2.currency === nativeCurrency) {
if (isNativeCurrency(asset2)) {
ammCreate.Amount2 = multiply(asset2Amount, 1000000)
} else {
ammCreate.Amount2 = {
Expand Down
6 changes: 3 additions & 3 deletions components/Services/Amm/AMMVote.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react'
import FormInput from '../../UI/FormInput'
import { nativeCurrency, typeNumberOnly } from '../../../utils'
import { nativeCurrency, typeNumberOnly, isNativeCurrency } from '../../../utils'
import TokenSelector from '../../UI/TokenSelector'
import { LinkAmm, LinkTx } from '../../../utils/links'
import CopyButton from '../../UI/CopyButton'
Expand Down Expand Up @@ -35,7 +35,7 @@ export default function AMMVoteForm({ setSignRequest }) {
}

// Asset 1 amount formatting
if (asset1.currency === nativeCurrency) {
if (isNativeCurrency(asset1)) {
ammVote.Asset = {
currency: asset1.currency
}
Expand All @@ -47,7 +47,7 @@ export default function AMMVoteForm({ setSignRequest }) {
}

// Asset 2 amount formatting
if (asset2.currency === nativeCurrency) {
if (isNativeCurrency(asset2)) {
ammVote.Asset2 = {
currency: asset2.currency
}
Expand Down
4 changes: 2 additions & 2 deletions components/Services/NftMint/NFTokenMint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useEffect } from 'react'
import Link from 'next/link'
import { encode, server, addAndRemoveQueryParams, nativeCurrency } from '../../../utils'
import { encode, server, addAndRemoveQueryParams, nativeCurrency, isNativeCurrency } from '../../../utils'
import { isValidTaxon } from '../../../utils/nft'
import CheckBox from '../../UI/CheckBox'
import AddressInput from '../../UI/AddressInput'
Expand Down Expand Up @@ -197,7 +197,7 @@ export default function NFTokenMint({ setSignRequest, uriQuery, taxonQuery }) {
}

// Handle amount based on selected token
if (selectedToken.currency === nativeCurrency) {
if (isNativeCurrency(selectedToken)) {
// For XRP, convert to drops
request.Amount = String(Math.round(parseFloat(amount) * 1000000))
} else {
Expand Down
8 changes: 4 additions & 4 deletions components/SignForms/NFTokenCreateOffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState, useEffect } from 'react'
import { useTranslation } from 'next-i18next'
import ExpirationSelect from '../UI/ExpirationSelect'
import CheckBox from '../UI/CheckBox'
import { isAddressValid, typeNumberOnly, useWidth, nativeCurrency } from '../../utils'
import { isAddressValid, typeNumberOnly, useWidth, nativeCurrency, isNativeCurrency } from '../../utils'
import { multiply, divide } from '../../utils/calc'
import AddressInput from '../UI/AddressInput'
import { amountFormat } from '../../utils/format'
Expand All @@ -19,7 +19,7 @@ export default function NFTokenCreateOffer({ signRequest, setSignRequest, setSta
useEffect(() => {
if (signRequest.request.Amount && typeof signRequest.request.Amount === 'string') {
// If we have a string amount (Native currency drops) but selected a token, convert it
if (selectedToken.currency !== nativeCurrency) {
if (!isNativeCurrency(selectedToken)) {
const tokenAmount = divide(signRequest.request.Amount, 1000000)
let newRequest = signRequest
newRequest.request.Amount = {
Expand All @@ -31,7 +31,7 @@ export default function NFTokenCreateOffer({ signRequest, setSignRequest, setSta
}
} else if (signRequest.request.Amount && typeof signRequest.request.Amount === 'object') {
// If we have a token amount but selected a Native Currency, convert it
if (selectedToken.currency === nativeCurrency && !selectedToken.issuer) {
if (isNativeCurrency(selectedToken)) {
let newRequest = signRequest
newRequest.request.Amount = multiply(signRequest.request.Amount.value, 1000000)
setSignRequest(newRequest)
Expand Down Expand Up @@ -76,7 +76,7 @@ export default function NFTokenCreateOffer({ signRequest, setSignRequest, setSta
const value = e.target.value
// Only process if we have a valid number or empty string
if (value === '' || (!isNaN(parseFloat(value)) && parseFloat(value) >= 0)) {
if (selectedToken.currency === nativeCurrency && !selectedToken.issuer) {
if (isNativeCurrency(selectedToken)) {
// For Native currency, convert to drops
if (value === '') {
delete newRequest.request.Amount
Expand Down
5 changes: 2 additions & 3 deletions components/Transaction/TransactionPayment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '../../../utils/format'

import { TransactionCard } from '../TransactionCard'
import { nativeCurrency, xls14NftValue } from '../../../utils'
import { isNativeCurrency, xls14NftValue } from '../../../utils'
import CopyButton from '../../UI/CopyButton'
import { addressBalanceChanges, dappBySourceTag } from '../../../utils/transaction'
import DestinationTagProblemSolving from './DestinationTagProblemSolving'
Expand Down Expand Up @@ -139,8 +139,7 @@ export const TransactionPayment = ({ data, pageFiatRate, selectedCurrency }) =>
!isConvertion &&
(!outcome.deliveredAmount ||
outcome.deliveredAmount.issuer ||
(!outcome.deliveredAmount.issuer &&
outcome.deliveredAmount.currency === nativeCurrency &&
(!isNativeCurrency(outcome.deliveredAmount) &&
Number(outcome.deliveredAmount.value) < 100000)) && (
<DestinationTagProblemSolving specification={specification} pageFiatRate={pageFiatRate} />
)}
Expand Down
4 changes: 2 additions & 2 deletions components/UI/TokenSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IoSearch } from 'react-icons/io5'
import { IoMdClose } from 'react-icons/io'
import { IoChevronDown } from 'react-icons/io5'
import axios from 'axios'
import { avatarServer, nativeCurrency, nativeCurrenciesImages, useWidth } from '../../utils'
import { avatarServer, nativeCurrency, isNativeCurrency, nativeCurrenciesImages, useWidth } from '../../utils'
import { niceCurrency, shortAddress } from '../../utils/format'

const limit = 20
Expand Down Expand Up @@ -34,7 +34,7 @@ export default function TokenSelector({ value, onChange, excludeNative = false }
// when searched for native currency, we also add the native currency on top,
// so check that it's not that case before canceling the search
if (
searchResults[0]?.currency === nativeCurrency &&
isNativeCurrency(searchResults[0]) &&
!niceCurrency(searchResults[1]?.currency)?.toLowerCase().startsWith(nativeCurrency.toLowerCase())
)
return
Expand Down
7 changes: 4 additions & 3 deletions pages/amms.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
addAndRemoveQueryParams,
addQueryParams,
nativeCurrency,
isNativeCurrency,
removeQueryParams,
useWidth,
xahauNetwork
Expand Down Expand Up @@ -116,12 +117,12 @@ export default function Amms({
const [marker, setMarker] = useState(initialData?.marker)
const [filtersHide, setFiltersHide] = useState(false)
const [token, setToken] = useState(() => {
if (currencyQuery && currencyQuery !== nativeCurrency) {
if (currencyQuery && currencyIssuerQuery) {
return {
currency: currencyQuery,
issuer: currencyIssuerQuery
}
} else if (currencyQuery === nativeCurrency) {
} else if (currencyQuery === nativeCurrency && !currencyIssuerQuery) {
return {
currency: nativeCurrency
}
Expand All @@ -136,7 +137,7 @@ export default function Amms({

useEffect(() => {
if (token?.currency && order === 'currencyHigh') {
if (token.currency === nativeCurrency) {
if (isNativeCurrency(token)) {
addAndRemoveQueryParams(router, [{ name: 'currency', value: nativeCurrency }], ['currencyIssuer'])
} else if (token.issuer) {
const params = [
Expand Down
4 changes: 2 additions & 2 deletions pages/services/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import CopyButton from '../../components/UI/CopyButton'
import { LinkTx, LinkAccount } from '../../utils/links'
import { multiply } from '../../utils/calc'
import NetworkTabs from '../../components/Tabs/NetworkTabs'
import { typeNumberOnly, isAddressValid, isTagValid, isIdValid, nativeCurrency, encode, decode } from '../../utils'
import { typeNumberOnly, isAddressValid, isTagValid, isIdValid, nativeCurrency, isNativeCurrency, encode, decode } from '../../utils'
import { fullDateAndTime, timeFromNow, amountFormat, shortHash } from '../../utils/format'
import { useState, useEffect } from 'react'
import { useRouter } from 'next/router'
Expand Down Expand Up @@ -201,7 +201,7 @@ export default function Send({
Destination: address
}

if (selectedToken.currency === nativeCurrency) {
if (isNativeCurrency(selectedToken)) {
payment.Amount = multiply(amount, 1000000)
} else {
payment.Amount = {
Expand Down
13 changes: 13 additions & 0 deletions utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,19 @@ export const isAmountInNativeCurrency = (amount) => {
return !amount?.issuer && !amount?.mpt_issuance_id
}

export const isNativeCurrency = (currencyObj) => {
if (!currencyObj) return false
if (!currencyObj.currency) return false

// Check that currency matches the native currency for this network
if (currencyObj.currency !== nativeCurrency) return false

// Check that there's no issuer (native currency has no issuer)
if (currencyObj.issuer) return false

return true
}

export const xls14NftValue = (value) => {
if (!value) return value
value = value.toString()
Expand Down