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); | ||||
// Set address of active wallet to default alias registration address | |||||
// Use formdata approach as we will later add a form field for aliasAddress | |||||
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 ( | ||||
Show All 38 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( | 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 232 Lines • Show Last 20 Lines |