+ {waiting &&
}
+ {waiting && details &&
{details}
}
- {minAmount &&
- {tt('uia_register_jsx.req_amount')} {minAmount.floatString}
}
+ {!waiting && minAmount &&
+ {tt('uia_register_jsx.min_amount')} {minAmount.floatString}.
}
;
}
_renderApi = () => {
- const { sym, apiLoaded } = this.state
+ const { sym, apiLoaded, waiting } = this.state
if (!apiLoaded) {
return (
@@ -334,14 +339,14 @@ class UIARegister extends React.Component {
}
const { address } = apiLoaded
return (
- {this._renderTo(address, null)}
+ {waiting && this._renderTo(address, null)}
{this._renderParams(false)}
- {this._renderWaiter()}
+ {waiting ? this._renderWaiter() : this._renderForm()}
)
}
_renderWaiter = () => {
- const { minAmount, registrar, onTransfer } = this.state
+ const { waitAmount, registrar, onTransfer } = this.state
if (!onTransfer) {
onTransfer = async (deposited) => {
this.setState({
@@ -372,9 +377,85 @@ class UIARegister extends React.Component {
})
}
}
- return
+ return
+
+ {tt('uia_register_jsx.enter_amount')}{waitAmount.floatString}.
+
+
+
+ }
+
+ amountValidate = (values) => {
+ const errors = {}
+ const { minAmount } = this.state
+ if (values.amount.asset.lt(minAmount)) {
+ errors.amount = tt('uia_register_jsx.min_amount') + minAmount.floatString
+ }
+ this.setState({
+ amountSubmitError: ''
+ })
+ return errors
+ }
+
+ _onAmountSubmit = async (values) => {
+ const waitAmount = values.amount.asset
+ try {
+ let fp = await callApi('/api/reg/get_free_poller/' + waitAmount.toString())
+ fp = await fp.json()
+ if (fp.status !== 'ok') {
+ throw new Error(fp.error || 'Unknown error')
+ }
+ if (fp.amount !== waitAmount.toString()) {
+ throw new Error('Slot is used')
+ }
+ } catch (err) {
+ this.setState({
+ amountSubmitError: err.message === 'Slot is used' ? tt('uia_register_jsx.slot_is_used') : err.message
+ })
+ return
+ }
+ this.setState({
+ waiting: true,
+ waitAmount
+ })
+ }
+
+ _renderForm = () => {
+ const { initialForm, amountSubmitError } = this.state
+ return
+ {({
+ handleSubmit, isSubmitting, isValid, dirty, errors, touched, values, handleChange, setFieldValue,
+ }) => (
+
+ )}
+
}
render() {
@@ -385,7 +466,7 @@ class UIARegister extends React.Component {
if (loading) {
content =
} else {
- const { assets, sym } = this.state
+ const { assets, sym, waiting } = this.state
const path = this.getPath()[0]
@@ -431,8 +512,8 @@ class UIARegister extends React.Component {
memo_fixed = memo_fixed.split('
').join(username)
}
form =
- {this._renderTo(to, to_fixed)}
- {memo_fixed ?
+ {waiting && this._renderTo(to, to_fixed)}
+ {(waiting && memo_fixed) ?
{tt('uia_register_jsx.memo_fixed')}:
{memo_fixed}
@@ -445,7 +526,7 @@ class UIARegister extends React.Component {
: null}
{this._renderParams()}
- {this._renderWaiter()}
+ {waiting ? this._renderWaiter() : this._renderForm()}
}
}
diff --git a/src/modules/register/UIARegister.scss b/src/modules/register/UIARegister.scss
index cd625ba..c9fdbe7 100644
--- a/src/modules/register/UIARegister.scss
+++ b/src/modules/register/UIARegister.scss
@@ -24,4 +24,8 @@
background-color: rgba(208,208,208,0.45);
border: 1px solid rgba(128,128,128,0.45);
}
+
+ .error {
+ margin-bottom: 0.75rem;
+ }
}