Changeset View
Changeset View
Standalone View
Standalone View
cashtab/src/components/Alias/Alias.js
Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | const { | ||||
chronik, | chronik, | ||||
cashtabCache, | cashtabCache, | ||||
refreshAliases, | refreshAliases, | ||||
aliases, | aliases, | ||||
setAliases, | setAliases, | ||||
aliasServerError, | aliasServerError, | ||||
aliasPrices, | aliasPrices, | ||||
setAliasPrices, | setAliasPrices, | ||||
aliasPriceError, | |||||
setAliasPriceError, | |||||
} = ContextValue; | } = ContextValue; | ||||
const walletState = getWalletState(wallet); | const walletState = getWalletState(wallet); | ||||
const { balances } = walletState; | const { balances } = walletState; | ||||
const [formData, setFormData] = useState({ | const [formData, setFormData] = useState({ | ||||
aliasName: '', | aliasName: '', | ||||
aliasAddress: '', | aliasAddress: '', | ||||
}); | }); | ||||
const [useThisAddressChecked, setUseThisAddressChecked] = useState(false); | const [useThisAddressChecked, setUseThisAddressChecked] = useState(false); | ||||
Show All 18 Lines | const handleAliasWalletChange = async () => { | ||||
await refreshAliases(wallet.Path1899.cashAddress); | await refreshAliases(wallet.Path1899.cashAddress); | ||||
} | } | ||||
// Refresh alias prices if none exist yet | // Refresh alias prices if none exist yet | ||||
if (aliasPrices === null) { | if (aliasPrices === null) { | ||||
try { | try { | ||||
setAliasPrices(await queryAliasServer('prices')); | setAliasPrices(await queryAliasServer('prices')); | ||||
} catch (err) { | } catch (err) { | ||||
setAliasValidationError( | setAliasPriceError( | ||||
`Failed to fetch alias price information from server. Alias registration disabled. Refresh page to try again.`, | `Failed to fetch alias price information from server. Alias registration disabled. Refresh page to try again.`, | ||||
); | ); | ||||
passLoadingStatus(false); | passLoadingStatus(false); | ||||
} | } | ||||
} | } | ||||
// Track when the user stops typing into the aliasName input field for at least | // Track when the user stops typing into the aliasName input field for at least | ||||
// 'aliasSettings.aliasKeyUpTimeoutMs' and make an API call to check the alias status | // 'aliasSettings.aliasKeyUpTimeoutMs' and make an API call to check the alias status | ||||
▲ Show 20 Lines • Show All 364 Lines • ▼ Show 20 Lines | return ( | ||||
<Form | <Form | ||||
style={{ | style={{ | ||||
width: 'auto', | width: 'auto', | ||||
}} | }} | ||||
> | > | ||||
<Form.Item> | <Form.Item> | ||||
<AliasInput | <AliasInput | ||||
validateStatus={ | validateStatus={ | ||||
isValidAliasInput ? '' : 'error' | isValidAliasInput && | ||||
aliasPriceError === false | |||||
? '' | |||||
: 'error' | |||||
} | } | ||||
help={ | help={ | ||||
aliasValidationError | aliasPriceError ? ( | ||||
aliasPriceError | |||||
) : ( | |||||
<> | |||||
{aliasValidationError | |||||
? aliasValidationError | ? aliasValidationError | ||||
: '' | : ''} | ||||
</> | |||||
) | |||||
} | } | ||||
inputProps={{ | inputProps={{ | ||||
addonAfter: ' . xec', | addonAfter: ' . xec', | ||||
placeholder: | placeholder: | ||||
'Enter a desired alias', | 'Enter a desired alias', | ||||
value: formData.aliasName, | value: formData.aliasName, | ||||
name: 'aliasName', | name: 'aliasName', | ||||
onChange: e => | onChange: e => | ||||
Show All 10 Lines | return ( | ||||
isValidAliasInput && | isValidAliasInput && | ||||
aliasPrices !== null | aliasPrices !== null | ||||
) { | ) { | ||||
// Disable alias registration if the array is not exactly one entry | // Disable alias registration if the array is not exactly one entry | ||||
if ( | if ( | ||||
aliasPrices.prices | aliasPrices.prices | ||||
.length !== 1 | .length !== 1 | ||||
) { | ) { | ||||
setAliasValidationError( | setAliasPriceError( | ||||
`Alias registration is temporarily unavailable, please check again later.`, | `Alias pricing error, registration is temporarily unavailable. Please check again later.`, | ||||
); | ); | ||||
setIsValidAliasInput(false); | setIsValidAliasInput(false); | ||||
return; | |||||
} | } | ||||
// TODO Once chronik-client has been upgraded for in-node chronik, update | // TODO Once chronik-client has been upgraded for in-node chronik, update | ||||
// this price parsing logic to use the new ws for blockheight comparisons. | // this price parsing logic to use the new ws for blockheight comparisons. | ||||
// Intention is to reverse loop through `aliasPrices.prices` and parse for | // Intention is to reverse loop through `aliasPrices.prices` and parse for | ||||
// the latest array entry that has a startHeight within the chain's tipHeight. | // the latest array entry that has a startHeight within the chain's tipHeight. | ||||
let aliasPriceXec = toXec( | let aliasPriceXec = toXec( | ||||
aliasPrices.prices[0].fees[ | aliasPrices.prices[0].fees[ | ||||
aliasLength | aliasLength | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | return ( | ||||
/> | /> | ||||
)} | )} | ||||
<SmartButton | <SmartButton | ||||
disabled={ | disabled={ | ||||
!isValidAliasInput || | !isValidAliasInput || | ||||
!isValidAliasAddressInput || | !isValidAliasAddressInput || | ||||
aliasValidationError !== | aliasValidationError !== | ||||
false || | false || | ||||
aliasServerError !== false | aliasServerError !== false || | ||||
aliasPriceError !== false | |||||
} | } | ||||
onClick={() => | onClick={() => | ||||
preparePreviewModal() | preparePreviewModal() | ||||
} | } | ||||
> | > | ||||
<AliasRegisterIcon /> Register Alias | <AliasRegisterIcon /> Register Alias | ||||
</SmartButton> | </SmartButton> | ||||
</Form.Item> | </Form.Item> | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | return ( | ||||
) | ) | ||||
: !aliasServerError && ( | : !aliasServerError && ( | ||||
<h3> | <h3> | ||||
{'No registered aliases'} | {'No registered aliases'} | ||||
</h3> | </h3> | ||||
)} | )} | ||||
</Space> | </Space> | ||||
<AlertMsg> | <AlertMsg> | ||||
{aliasServerError && | {aliasPriceError | ||||
aliasValidationError === false && | ? aliasPriceError | ||||
: aliasValidationError | |||||
? aliasValidationError | |||||
: aliasServerError && | |||||
aliasServerError} | aliasServerError} | ||||
</AlertMsg> | </AlertMsg> | ||||
</CustomCollapseCtn> | </CustomCollapseCtn> | ||||
<CustomCollapseCtn | <CustomCollapseCtn | ||||
panelHeader="Pending Aliases" | panelHeader="Pending Aliases" | ||||
optionalDefaultActiveKey={['1']} | optionalDefaultActiveKey={['1']} | ||||
optionalKey="1" | optionalKey="1" | ||||
> | > | ||||
<Space | <Space | ||||
Show All 31 Lines | return ( | ||||
) | ) | ||||
: !aliasServerError && ( | : !aliasServerError && ( | ||||
<h3> | <h3> | ||||
{'No pending aliases'} | {'No pending aliases'} | ||||
</h3> | </h3> | ||||
)} | )} | ||||
</Space> | </Space> | ||||
<AlertMsg> | <AlertMsg> | ||||
{aliasServerError && | {aliasPriceError | ||||
aliasValidationError === false && | ? aliasPriceError | ||||
: aliasValidationError | |||||
? aliasValidationError | |||||
: aliasServerError && | |||||
aliasServerError} | aliasServerError} | ||||
</AlertMsg> | </AlertMsg> | ||||
</CustomCollapseCtn> | </CustomCollapseCtn> | ||||
</NamespaceCtn> | </NamespaceCtn> | ||||
</SidePaddingCtn> | </SidePaddingCtn> | ||||
</Col> | </Col> | ||||
</Row> | </Row> | ||||
</SidePaddingCtn> | </SidePaddingCtn> | ||||
</> | </> | ||||
Show All 21 Lines |