Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/components/Tokens/CreateTokenForm.js
Show All 9 Lines | import { | ||||
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, notification } 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, | |||||
createETokenErrorNotification, | |||||
} from '@components/Common/Notifications'; | |||||
const CreateTokenForm = ({ | const CreateTokenForm = ({ | ||||
BCH, | BCH, | ||||
getRestUrl, | getRestUrl, | ||||
createToken, | createToken, | ||||
disabled, | disabled, | ||||
passLoadingStatus, | passLoadingStatus, | ||||
}) => { | }) => { | ||||
Show All 16 Lines | const handleNewTokenTickerInput = e => { | ||||
const { value } = e.target; | const { value } = e.target; | ||||
// validation | // validation | ||||
setNewTokenTickerIsValid(isValidTokenTicker(value)); | setNewTokenTickerIsValid(isValidTokenTicker(value)); | ||||
setNewTokenTicker(value); | setNewTokenTicker(value); | ||||
}; | }; | ||||
// New Token Decimals | // New Token Decimals | ||||
const [newTokenDecimals, setNewTokenDecimals] = useState(0); | const [newTokenDecimals, setNewTokenDecimals] = useState(0); | ||||
const [newTokenDecimalsIsValid, setNewTokenDecimalsIsValid] = useState( | const [newTokenDecimalsIsValid, setNewTokenDecimalsIsValid] = | ||||
true, | useState(true); | ||||
); | |||||
const handleNewTokenDecimalsInput = e => { | const handleNewTokenDecimalsInput = e => { | ||||
const { value } = e.target; | const { value } = e.target; | ||||
// validation | // validation | ||||
setNewTokenDecimalsIsValid(isValidTokenDecimals(value)); | setNewTokenDecimalsIsValid(isValidTokenDecimals(value)); | ||||
// Also validate the supply here if it has not yet been set | // Also validate the supply here if it has not yet been set | ||||
if (newTokenInitialQtyIsValid !== null) { | if (newTokenInitialQtyIsValid !== null) { | ||||
setNewTokenInitialQtyIsValid( | setNewTokenInitialQtyIsValid( | ||||
isValidTokenInitialQty(value, newTokenDecimals), | isValidTokenInitialQty(value, newTokenDecimals), | ||||
); | ); | ||||
} | } | ||||
setNewTokenDecimals(value); | setNewTokenDecimals(value); | ||||
}; | }; | ||||
// New Token Initial Quantity | // New Token Initial Quantity | ||||
const [newTokenInitialQty, setNewTokenInitialQty] = useState(''); | const [newTokenInitialQty, setNewTokenInitialQty] = useState(''); | ||||
const [newTokenInitialQtyIsValid, setNewTokenInitialQtyIsValid] = useState( | const [newTokenInitialQtyIsValid, setNewTokenInitialQtyIsValid] = | ||||
null, | useState(null); | ||||
); | |||||
const handleNewTokenInitialQtyInput = e => { | const handleNewTokenInitialQtyInput = e => { | ||||
const { value } = e.target; | const { value } = e.target; | ||||
// validation | // validation | ||||
setNewTokenInitialQtyIsValid( | setNewTokenInitialQtyIsValid( | ||||
isValidTokenInitialQty(value, newTokenDecimals), | isValidTokenInitialQty(value, newTokenDecimals), | ||||
); | ); | ||||
setNewTokenInitialQty(value); | setNewTokenInitialQty(value); | ||||
}; | }; | ||||
// New Token document URL | // New Token document URL | ||||
const [newTokenDocumentUrl, setNewTokenDocumentUrl] = useState(''); | const [newTokenDocumentUrl, setNewTokenDocumentUrl] = useState(''); | ||||
// Start with this as true, field is not required | // Start with this as true, field is not required | ||||
const [ | const [newTokenDocumentUrlIsValid, setNewTokenDocumentUrlIsValid] = | ||||
newTokenDocumentUrlIsValid, | useState(true); | ||||
setNewTokenDocumentUrlIsValid, | |||||
] = useState(true); | |||||
const handleNewTokenDocumentUrlInput = e => { | const handleNewTokenDocumentUrlInput = e => { | ||||
const { value } = e.target; | const { value } = e.target; | ||||
// validation | // validation | ||||
setNewTokenDocumentUrlIsValid(isValidTokenDocumentUrl(value)); | setNewTokenDocumentUrlIsValid(isValidTokenDocumentUrl(value)); | ||||
setNewTokenDocumentUrl(value); | setNewTokenDocumentUrl(value); | ||||
}; | }; | ||||
Show All 37 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({ | createETokenErrorNotification(message); | ||||
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); | ||||
} | } | ||||
// createETokenErrorNotification(message) | |||||
bytesofman: Uncomment this + make sure it's the generic error notification as discussed in above comments | |||||
notification.error({ | |||||
message: 'Error', | |||||
description: message, | |||||
duration: 5, | |||||
}); | |||||
console.error(e); | 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 197 Lines • Show Last 20 Lines |
Uncomment this + make sure it's the generic error notification as discussed in above comments