Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/components/Send/SendToken.js
import React, { useState, useEffect } from 'react'; | import React, { useState, useEffect } from 'react'; | ||||
import PropTypes from 'prop-types'; | import PropTypes from 'prop-types'; | ||||
import { WalletContext } from '@utils/context'; | import { WalletContext } from '@utils/context'; | ||||
import { | import { Form, message, Row, Col, Alert, Descriptions } from 'antd'; | ||||
Form, | |||||
notification, | |||||
message, | |||||
Row, | |||||
Col, | |||||
Alert, | |||||
Descriptions, | |||||
} from 'antd'; | |||||
import Paragraph from 'antd/lib/typography/Paragraph'; | |||||
import PrimaryButton, { | import PrimaryButton, { | ||||
SecondaryButton, | SecondaryButton, | ||||
} from '@components/Common/PrimaryButton'; | } from '@components/Common/PrimaryButton'; | ||||
import { | import { | ||||
FormItemWithMaxAddon, | FormItemWithMaxAddon, | ||||
FormItemWithQRCodeAddon, | FormItemWithQRCodeAddon, | ||||
} from '@components/Common/EnhancedInputs'; | } from '@components/Common/EnhancedInputs'; | ||||
import useBCH from '@hooks/useBCH'; | import useBCH from '@hooks/useBCH'; | ||||
Show All 9 Lines | import { | ||||
parseAddress, | parseAddress, | ||||
isValidTokenPrefix, | isValidTokenPrefix, | ||||
} from '@components/Common/Ticker.js'; | } from '@components/Common/Ticker.js'; | ||||
import { Event } from '@utils/GoogleAnalytics'; | import { Event } from '@utils/GoogleAnalytics'; | ||||
import { | import { | ||||
getWalletState, | getWalletState, | ||||
convertEtokenToSimpleledger, | convertEtokenToSimpleledger, | ||||
} from '@utils/cashMethods'; | } from '@utils/cashMethods'; | ||||
import { TokenReceivedNotificationIcon } from '@components/Common/CustomIcons'; | |||||
import ApiError from '@components/Common/ApiError'; | import ApiError from '@components/Common/ApiError'; | ||||
import { | |||||
sendTokenNotification, | |||||
errorNotification, | |||||
} from '@components/Common/Notifications'; | |||||
const SendToken = ({ tokenId, jestBCH, passLoadingStatus }) => { | const SendToken = ({ tokenId, jestBCH, passLoadingStatus }) => { | ||||
const { wallet, apiError } = React.useContext(WalletContext); | const { wallet, apiError } = React.useContext(WalletContext); | ||||
const walletState = getWalletState(wallet); | const walletState = getWalletState(wallet); | ||||
const { tokens, slpBalancesAndUtxos } = walletState; | const { tokens, slpBalancesAndUtxos } = walletState; | ||||
const token = tokens.find(token => token.tokenId === tokenId); | const token = tokens.find(token => token.tokenId === tokenId); | ||||
const [tokenStats, setTokenStats] = useState(null); | const [tokenStats, setTokenStats] = useState(null); | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | async function submit() { | ||||
try { | try { | ||||
const link = await sendToken(BCH, wallet, slpBalancesAndUtxos, { | const link = await sendToken(BCH, wallet, slpBalancesAndUtxos, { | ||||
tokenId: tokenId, | tokenId: tokenId, | ||||
tokenReceiverAddress: cleanAddress, | tokenReceiverAddress: cleanAddress, | ||||
amount: value, | amount: value, | ||||
}); | }); | ||||
notification.success({ | sendTokenNotification(link); | ||||
message: 'Success', | |||||
description: ( | |||||
<a href={link} target="_blank" rel="noopener noreferrer"> | |||||
<Paragraph> | |||||
Transaction successful. Click to view in block | |||||
explorer. | |||||
</Paragraph> | |||||
</a> | |||||
), | |||||
duration: 3, | |||||
icon: <TokenReceivedNotificationIcon />, | |||||
style: { width: '100%' }, | |||||
}); | |||||
} catch (e) { | } catch (e) { | ||||
passLoadingStatus(false); | passLoadingStatus(false); | ||||
let message; | let message; | ||||
if (!e.error && !e.message) { | if (!e.error && !e.message) { | ||||
message = `Transaction failed: no response from ${getRestUrl()}.`; | message = `Transaction failed: no response from ${getRestUrl()}.`; | ||||
} else if ( | } else if ( | ||||
/Could not communicate with full node or other external service/.test( | /Could not communicate with full node or other external service/.test( | ||||
e.error, | e.error, | ||||
) | ) | ||||
) { | ) { | ||||
message = 'Could not communicate with API. Please try again.'; | message = 'Could not communicate with API. Please try again.'; | ||||
} else { | } else { | ||||
message = e.message || e.error || JSON.stringify(e); | message = e.message || e.error || JSON.stringify(e); | ||||
} | } | ||||
console.log(e); | errorNotification(e, message, 'Sending eToken'); | ||||
notification.error({ | |||||
message: 'Error', | |||||
description: message, | |||||
duration: 3, | |||||
}); | |||||
console.error(e); | |||||
} | } | ||||
} | } | ||||
const handleSlpAmountChange = e => { | const handleSlpAmountChange = e => { | ||||
let error = false; | let error = false; | ||||
const { value, name } = e.target; | const { value, name } = e.target; | ||||
// test if exceeds balance using BigNumber | // test if exceeds balance using BigNumber | ||||
▲ Show 20 Lines • Show All 297 Lines • Show Last 20 Lines |