Changeset View
Changeset View
Standalone View
Standalone View
cashtab/src/components/Alias/Alias.js
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | const { | ||||
fiatPrice, | fiatPrice, | ||||
cashtabSettings, | cashtabSettings, | ||||
chronik, | chronik, | ||||
changeCashtabSettings, | changeCashtabSettings, | ||||
cashtabCache, | cashtabCache, | ||||
isAliasServerOnline, | isAliasServerOnline, | ||||
} = ContextValue; | } = ContextValue; | ||||
const walletState = getWalletState(wallet); | const walletState = getWalletState(wallet); | ||||
const { balances, nonSlpUtxos } = walletState; | const { balances } = walletState; | ||||
const [formData, setFormData] = useState({ | const [formData, setFormData] = useState({ | ||||
aliasName: '', | aliasName: '', | ||||
aliasAddress: '', | |||||
}); | }); | ||||
const [isValidAliasInput, setIsValidAliasInput] = useState(false); // tracks whether to activate the registration button | const [isValidAliasInput, setIsValidAliasInput] = useState(false); // tracks whether to activate the registration button | ||||
const [aliasValidationError, setAliasValidationError] = useState(false); | const [aliasValidationError, setAliasValidationError] = useState(false); | ||||
const [activeWalletAliases, setActiveWalletAliases] = useState([]); // stores the list of aliases registered to this active wallet | const [activeWalletAliases, setActiveWalletAliases] = useState([]); // stores the list of aliases registered to this active wallet | ||||
const [aliasLength, setAliasLength] = useState(false); // real time tracking of alias char length | const [aliasLength, setAliasLength] = useState(false); // real time tracking of alias char length | ||||
const [aliasFee, setAliasFee] = useState(false); // real time tracking of alias registration fee | const [aliasFee, setAliasFee] = useState(false); // real time tracking of alias registration fee | ||||
// Show a confirmation modal on alias registrations | // Show a confirmation modal on alias registrations | ||||
Show All 10 Lines | useEffect(async () => { | ||||
typeof wallet === 'undefined' || | typeof wallet === 'undefined' || | ||||
!cashtabCache || | !cashtabCache || | ||||
typeof cashtabCache === 'undefined' | typeof cashtabCache === 'undefined' | ||||
) { | ) { | ||||
return; | return; | ||||
} | } | ||||
passLoadingStatus(true); | passLoadingStatus(true); | ||||
console.log(`wallet`, wallet); | |||||
// Set thisAddress to default alias registration address | |||||
setFormData(formData => ({ | |||||
...formData, | |||||
aliasAddress: wallet.Path1899.cashAddress, | |||||
})); | |||||
// check whether the address is attached to an onchain alias on page load | // check whether the address is attached to an onchain alias on page load | ||||
const walletHasAlias = isAddressRegistered( | const walletHasAlias = isAddressRegistered( | ||||
wallet, | wallet, | ||||
cashtabCache.aliasCache, | cashtabCache.aliasCache, | ||||
); | ); | ||||
// retrieve aliases for this active wallet from cache for rendering on the frontend | // retrieve aliases for this active wallet from cache for rendering on the frontend | ||||
if ( | if ( | ||||
walletHasAlias && | walletHasAlias && | ||||
cashtabCache.aliasCache && | cashtabCache.aliasCache && | ||||
cashtabCache.aliasCache.cachedAliasCount > 0 | cashtabCache.aliasCache.cachedAliasCount > 0 | ||||
) { | ) { | ||||
const thisAddress = convertToEcashPrefix( | const thisAddress = convertToEcashPrefix( | ||||
wallet.Path1899.cashAddress, | wallet.Path1899.cashAddress, | ||||
); | ); | ||||
// filter for aliases that matches this wallet's address | // filter for aliases that matches this wallet's address | ||||
const registeredAliasesToWallet = | const registeredAliasesToWallet = | ||||
cashtabCache.aliasCache.aliases.filter( | cashtabCache.aliasCache.aliases.filter( | ||||
alias => alias.address === thisAddress, | alias => alias.address === thisAddress, | ||||
); | ); | ||||
const appendedWithPendingAliases = await appendWithPendingAliases( | const appendedWithPendingAliases = await appendWithPendingAliases( | ||||
registeredAliasesToWallet, | registeredAliasesToWallet, | ||||
Show All 23 Lines | const registerAlias = async () => { | ||||
'Alias-server status check', | 'Alias-server status check', | ||||
); | ); | ||||
passLoadingStatus(false); | passLoadingStatus(false); | ||||
return; | return; | ||||
} | } | ||||
// note: input already validated via handleAliasNameInput() | // note: input already validated via handleAliasNameInput() | ||||
const aliasInput = formData.aliasName; | const aliasInput = formData.aliasName; | ||||
const aliasAddress = formData.aliasAddress; | |||||
// check if the user is trying to essentially register chicken.xec.xec | // check if the user is trying to essentially register chicken.xec.xec | ||||
const doubleExtensionInput = isAliasFormat(aliasInput); | const doubleExtensionInput = isAliasFormat(aliasInput); | ||||
if (doubleExtensionInput) { | if (doubleExtensionInput) { | ||||
errorNotification( | errorNotification( | ||||
null, | null, | ||||
'Please input an alias without the ".xec"', | 'Please input an alias without the ".xec"', | ||||
'Alias extension check', | 'Alias extension check', | ||||
Show All 17 Lines | const registerAlias = async () => { | ||||
' is ' + | ' is ' + | ||||
registrationFee + | registrationFee + | ||||
' sats.', | ' sats.', | ||||
); | ); | ||||
console.log( | console.log( | ||||
`Alias ${aliasInput} is available. Broadcasting registration transaction.`, | `Alias ${aliasInput} is available. Broadcasting registration transaction.`, | ||||
); | ); | ||||
try { | try { | ||||
const link = await registerNewAlias( | console.log(`Calling registerNewAlias with`); | ||||
console.log(`chronik`, chronik); | |||||
console.log(`wallet`, wallet); | |||||
console.log(`currency.defaultFee`, currency.defaultFee); | |||||
console.log(`aliasInput`, aliasInput); | |||||
console.log(`aliasAddress`, aliasAddress); | |||||
console.log(`registrationFee`, registrationFee); | |||||
const result = await registerNewAlias( | |||||
chronik, | chronik, | ||||
wallet, | wallet, | ||||
nonSlpUtxos, | |||||
currency.defaultFee, | currency.defaultFee, | ||||
aliasInput, | aliasInput, | ||||
fromSatoshisToXec(registrationFee), | aliasAddress, | ||||
registrationFee, | |||||
); | ); | ||||
registerAliasNotification(link, aliasInput); | registerAliasNotification(result.explorerLink, aliasInput); | ||||
// allow alias server to process the pending alias | // allow alias server to process the pending alias | ||||
const delay = ms => new Promise(res => setTimeout(res, ms)); | const delay = ms => new Promise(res => setTimeout(res, ms)); | ||||
await delay(1000); // 1 second | await delay(1000); // 1 second | ||||
const appendedWithPendingAliases = | const appendedWithPendingAliases = | ||||
await appendWithPendingAliases(activeWalletAliases); | await appendWithPendingAliases(activeWalletAliases); | ||||
setActiveWalletAliases([ | setActiveWalletAliases([ | ||||
...new Set(appendedWithPendingAliases), | ...new Set(appendedWithPendingAliases), | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | return ( | ||||
<> | <> | ||||
<Modal | <Modal | ||||
title="Confirm Alias Registration" | title="Confirm Alias Registration" | ||||
open={isModalVisible} | open={isModalVisible} | ||||
onOk={handleOk} | onOk={handleOk} | ||||
onCancel={handleCancel} | onCancel={handleCancel} | ||||
> | > | ||||
<p> | <p> | ||||
{`Are you sure you want to register the alias '${formData.aliasName}' for ${fromSatoshisToXec(aliasFee)} XECs?`} | {`Are you sure you want to register the alias '${ | ||||
formData.aliasName | |||||
}' for ${fromSatoshisToXec(aliasFee)} XECs?`} | |||||
</p> | </p> | ||||
</Modal> | </Modal> | ||||
<WalletInfoCtn> | <WalletInfoCtn> | ||||
<WalletLabel | <WalletLabel | ||||
name={wallet.name} | name={wallet.name} | ||||
cashtabSettings={cashtabSettings} | cashtabSettings={cashtabSettings} | ||||
changeCashtabSettings={changeCashtabSettings} | changeCashtabSettings={changeCashtabSettings} | ||||
></WalletLabel> | ></WalletLabel> | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | return ( | ||||
aliasFee && | aliasFee && | ||||
`Registration fee for this ${aliasLength} byte Alias is ${fromSatoshisToXec( | `Registration fee for this ${aliasLength} byte Alias is ${fromSatoshisToXec( | ||||
aliasFee, | aliasFee, | ||||
)} XEC`} | )} XEC`} | ||||
</Form.Item> | </Form.Item> | ||||
<Form.Item> | <Form.Item> | ||||
<SmartButton | <SmartButton | ||||
disabled={!isValidAliasInput} | disabled={!isValidAliasInput} | ||||
onClick={() => setIsModalVisible(true)} | onClick={() => | ||||
setIsModalVisible(true) | |||||
} | |||||
> | > | ||||
Register Alias | Register Alias | ||||
</SmartButton> | </SmartButton> | ||||
</Form.Item> | </Form.Item> | ||||
</Form> | </Form> | ||||
</AntdFormWrapper> | </AntdFormWrapper> | ||||
<StyledSpacer /> | <StyledSpacer /> | ||||
<NamespaceCtn> | <NamespaceCtn> | ||||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |