Skip to content

Commit

Permalink
app: Fix registration flow forms
Browse files Browse the repository at this point in the history
The registration flow didn't take into account the case where an exchange
had not yet been added to user.Exchanges. It assumed the exchange would
already be view only.
  • Loading branch information
martonp committed Apr 27, 2024
1 parent 79c4689 commit 86e4ad6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
30 changes: 13 additions & 17 deletions client/webserver/site/src/js/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ export class ConfirmRegistrationForm {
form: HTMLElement
success: () => void
page: Record<string, PageElement>
host: string
xc: Exchange
certFile: string
bondAssetID: number
tier: number
Expand All @@ -820,7 +820,7 @@ export class ConfirmRegistrationForm {
}

setExchange (xc: Exchange, certFile: string) {
this.host = xc.host
this.xc = xc
this.certFile = certFile
const page = this.page
if (State.passwordIsCached() || (this.pwCache && this.pwCache.pw)) Doc.hide(page.passBox)
Expand All @@ -835,8 +835,7 @@ export class ConfirmRegistrationForm {
this.tier = tier
this.fees = fees
const page = this.page
const xc = app().exchanges[this.host]
const bondAsset = xc.bondAssets[asset.symbol]
const bondAsset = this.xc.bondAssets[asset.symbol]
const bondLock = bondAsset.amount * tier * bondReserveMultiplier
const bondLockConventional = bondLock / conversionFactor
page.tradingTier.textContent = String(tier)
Expand Down Expand Up @@ -873,23 +872,22 @@ export class ConfirmRegistrationForm {
* submitForm is called when the form is submitted.
*/
async submitForm () {
const { page, bondAssetID, host, certFile, pwCache, tier } = this
const { page, bondAssetID, xc, certFile, pwCache, tier } = this
const asset = app().assets[bondAssetID]
if (!asset) {
page.regErr.innerText = intl.prep(intl.ID_SELECT_WALLET_FOR_FEE_PAYMENT)
Doc.show(page.regErr)
return
}
Doc.hide(page.regErr)
const xc = app().exchanges[host]
const bondAsset = xc.bondAssets[asset.wallet.symbol]
const cert = await certFile
const dexAddr = xc.host
const pw = page.appPass.value || (pwCache ? pwCache.pw : '')
let form: any
let url: string

if (xc.viewOnly || !app().exchanges[xc.host]) {
if (!app().exchanges[xc.host] || app().exchanges[xc.host].viewOnly) {
form = {
addr: dexAddr,
cert: cert,
Expand Down Expand Up @@ -935,7 +933,7 @@ interface MarketLimitsRow {
export class FeeAssetSelectionForm {
form: HTMLElement
success: (assetID: number, tier: number) => Promise<void>
host: string
xc: Exchange
selectedAssetID: number
page: Record<string, PageElement>
assetRows: Record<string, RegAssetRow>
Expand Down Expand Up @@ -995,7 +993,7 @@ export class FeeAssetSelectionForm {
}

setExchange (xc: Exchange) {
this.host = xc.host
this.xc = xc
this.assetRows = {}
this.marketRows = []
const page = this.page
Expand Down Expand Up @@ -1092,7 +1090,7 @@ export class FeeAssetSelectionForm {
}

refresh () {
this.setExchange(app().exchanges[this.host])
this.setExchange(this.xc)
}

assetSelected (assetID: number) {
Expand All @@ -1104,11 +1102,10 @@ export class FeeAssetSelectionForm {
}

setTier () {
const { page, host, selectedAssetID: assetID } = this
const { page, selectedAssetID: assetID } = this
const { symbol, unitInfo: ui } = app().assets[assetID]
const { conventional: { conversionFactor, unit } } = ui
const { bondAssets } = app().exchanges[host]
const bondAsset = bondAssets[symbol]
const bondAsset = this.xc.bondAssets[symbol]
const raw = page.tradingTierInput.value ?? ''
if (!raw) return
const tier = parseInt(raw)
Expand Down Expand Up @@ -1220,7 +1217,7 @@ export class WalletWaitForm {
page: Record<string, PageElement>
assetID: number
parentID?: number
host: string
xc: Exchange
bondAsset: BondAsset
progressCache: ProgressPoint[]
progressed: boolean
Expand Down Expand Up @@ -1251,7 +1248,7 @@ export class WalletWaitForm {

/* setExchange sets the exchange for which the fee is being paid. */
setExchange (xc: Exchange) {
this.host = xc.host
this.xc = xc
}

/* setWallet must be called before showing the WalletWaitForm. */
Expand All @@ -1264,10 +1261,9 @@ export class WalletWaitForm {
this.parentAssetSynced = false
const page = this.page
const asset = app().assets[assetID]
const xc = app().exchanges[this.host]
const { symbol, unitInfo: ui, wallet: { balance: bal, address, synced, syncProgress }, token } = asset
this.parentID = token?.parentID
const bondAsset = this.bondAsset = xc.bondAssets[symbol]
const bondAsset = this.bondAsset = this.xc.bondAssets[symbol]

const symbolize = (el: PageElement, asset: SupportedAsset) => {
Doc.empty(el)
Expand Down
10 changes: 4 additions & 6 deletions client/webserver/site/src/js/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class RegistrationPage extends BasePage {
body: HTMLElement
data: RegistrationPageData
pwCache: PasswordCache
host: string
xc: Exchange
page: Record<string, PageElement>
loginForm: LoginForm
appPassResetForm: AppPassResetForm
Expand Down Expand Up @@ -103,10 +103,9 @@ export default class RegistrationPage extends BasePage {
// SELECT REG ASSET
this.regAssetForm = new FeeAssetSelectionForm(page.regAssetForm, async (assetID: number, tier: number) => {
const asset = app().assets[assetID]
const xc = app().exchanges[this.host]
const wallet = asset.wallet
if (wallet) {
const bondAsset = xc.bondAssets[asset.symbol]
const bondAsset = this.xc.bondAssets[asset.symbol]
const bondsFeeBuffer = await this.getBondsFeeBuffer(assetID, page.regAssetForm)
this.confirmRegisterForm.setAsset(assetID, tier, bondsFeeBuffer)
if (wallet.synced && wallet.balance.available >= 2 * bondAsset.amount + bondsFeeBuffer) {
Expand Down Expand Up @@ -167,7 +166,7 @@ export default class RegistrationPage extends BasePage {
}

async requestFeepayment (oldForm: HTMLElement, xc: Exchange, certFile: string) {
this.host = xc.host
this.xc = xc
this.confirmRegisterForm.setExchange(xc, certFile)
this.walletWaitForm.setExchange(xc)
this.regAssetForm.setExchange(xc)
Expand Down Expand Up @@ -221,9 +220,8 @@ export default class RegistrationPage extends BasePage {
if (!user) return
const page = this.page
const asset = user.assets[assetID]
const xc = app().exchanges[this.host]
const wallet = asset.wallet
const bondAmt = xc.bondAssets[asset.symbol].amount
const bondAmt = this.xc.bondAssets[asset.symbol].amount

const bondsFeeBuffer = await this.getBondsFeeBuffer(assetID, page.newWalletForm)
this.walletWaitForm.setWallet(assetID, bondsFeeBuffer, tier)
Expand Down

0 comments on commit 86e4ad6

Please sign in to comment.