Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/components/Tokens/CreateTokenForm.js
import React, { useState } from 'react'; | import React, { useState } from 'react'; | ||||
import PropTypes from 'prop-types'; | import PropTypes from 'prop-types'; | ||||
import { AntdFormWrapper } from '@components/Common/EnhancedInputs'; | import { AntdFormWrapper } from '@components/Common/EnhancedInputs'; | ||||
import { TokenCollapse } from '@components/Common/StyledCollapse'; | import { TokenCollapse } from '@components/Common/StyledCollapse'; | ||||
import { currency } from '@components/Common/Ticker.js'; | import { currency } from '@components/Common/Ticker.js'; | ||||
import { WalletContext } from '@utils/context'; | import { WalletContext } from '@utils/context'; | ||||
import { | import { | ||||
isValidTokenName, | isValidTokenName, | ||||
isValidTokenTicker, | isValidTokenTicker, | ||||
isValidTokenDecimals, | isValidTokenDecimals, | ||||
isValidTokenInitialQty, | isValidTokenInitialQty, | ||||
isValidTokenDocumentUrl, | isValidTokenDocumentUrl, | ||||
} from '@utils/validation'; | } from '@utils/validation'; | ||||
import { PlusSquareOutlined } from '@ant-design/icons'; | import { PlusSquareOutlined } from '@ant-design/icons'; | ||||
import { SmartButton } from '@components/Common/PrimaryButton'; | import { SmartButton } from '@components/Common/PrimaryButton'; | ||||
import { Collapse, Form, Input, Modal, notification } from 'antd'; | import { Collapse, Form, Input, Modal } from 'antd'; | ||||
const { Panel } = Collapse; | const { Panel } = Collapse; | ||||
import Paragraph from 'antd/lib/typography/Paragraph'; | |||||
import { TokenParamLabel } from '@components/Common/Atoms'; | import { TokenParamLabel } from '@components/Common/Atoms'; | ||||
import { TokenReceivedNotificationIcon } from '@components/Common/CustomIcons'; | import { | ||||
createTokenNotification, | |||||
errorNotification, | |||||
} from '@components/Common/Notifications'; | |||||
const CreateTokenForm = ({ | const CreateTokenForm = ({ | ||||
BCH, | BCH, | ||||
getRestUrl, | getRestUrl, | ||||
createToken, | createToken, | ||||
disabled, | disabled, | ||||
passLoadingStatus, | passLoadingStatus, | ||||
}) => { | }) => { | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | const createPreviewedToken = async () => { | ||||
// create token with data in state fields | // create token with data in state fields | ||||
try { | try { | ||||
const link = await createToken( | const link = await createToken( | ||||
BCH, | BCH, | ||||
wallet, | wallet, | ||||
currency.defaultFee, | currency.defaultFee, | ||||
configObj, | configObj, | ||||
); | ); | ||||
createTokenNotification(link); | |||||
notification.success({ | |||||
message: 'Success', | |||||
description: ( | |||||
<a href={link} target="_blank" rel="noopener noreferrer"> | |||||
<Paragraph> | |||||
Token created! Click to view in block explorer. | |||||
</Paragraph> | |||||
</a> | |||||
), | |||||
icon: <TokenReceivedNotificationIcon />, | |||||
style: { width: '100%' }, | |||||
}); | |||||
} catch (e) { | } catch (e) { | ||||
// Set loading to false here as well, as balance may not change depending on where error occured in try loop | // Set loading to false here as well, as balance may not change depending on where error occured in try loop | ||||
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 if ( | } else if ( | ||||
e.error && | e.error && | ||||
e.error.includes( | e.error.includes( | ||||
'too-long-mempool-chain, too many unconfirmed ancestors [limit: 50] (code 64)', | 'too-long-mempool-chain, too many unconfirmed ancestors [limit: 50] (code 64)', | ||||
) | ) | ||||
) { | ) { | ||||
message = `The ${currency.ticker} you are trying to send has too many unconfirmed ancestors to send (limit 50). Sending will be possible after a block confirmation. Try again in about 10 minutes.`; | message = `The ${currency.ticker} you are trying to send has too many unconfirmed ancestors to send (limit 50). Sending will be possible after a block confirmation. Try again in about 10 minutes.`; | ||||
} else { | } else { | ||||
message = e.message || e.error || JSON.stringify(e); | message = e.message || e.error || JSON.stringify(e); | ||||
} | } | ||||
errorNotification(e, message, 'Creating eToken'); | |||||
notification.error({ | |||||
message: 'Error', | |||||
description: message, | |||||
duration: 5, | |||||
}); | |||||
console.error(e); | |||||
} | } | ||||
// Hide the modal | // Hide the modal | ||||
setShowConfirmCreateToken(false); | setShowConfirmCreateToken(false); | ||||
// Stop spinner | // Stop spinner | ||||
passLoadingStatus(false); | passLoadingStatus(false); | ||||
}; | }; | ||||
return ( | return ( | ||||
<> | <> | ||||
▲ Show 20 Lines • Show All 196 Lines • Show Last 20 Lines |