Skip to content

Commit

Permalink
feat: add debounce in allot mana popup
Browse files Browse the repository at this point in the history
  • Loading branch information
cpl121 committed May 20, 2024
1 parent 9626f42 commit ab55203
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions packages/desktop/components/popups/AllotManaPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import Big from 'big.js'
import { validateBech32Address } from '@core/utils'
import { AddressType } from '@iota/sdk/out/types'
import { debounce } from '@core/utils'
export let _onMount: (..._: any[]) => Promise<void> = async () => {}
export let rawAmount: string = '0'
Expand All @@ -29,6 +30,7 @@
let amount: string
let assetAmountInput: AssetAmountInput
const transactionUpdater = debounce(updateTransactionInfo, 500)
const transactionInfo: ITransactionInfoToCalculateManaCost = {}
let hasEnoughMana = false
Expand Down Expand Up @@ -77,12 +79,17 @@
}
}
async function preparedAllotMana() {
if (!accountAddress || !rawAmount || !validAmount) {
let updatingTransactionInfo = false
function preparedAllotMana(): void {
updatingTransactionInfo = true
if (!updatingTransactionInfo) {
transactionInfo.preparedTransaction = undefined
transactionInfo.preparedTransactionError = undefined
return
}
transactionUpdater()
}
async function updateTransactionInfo(): Promise<void> {
try {
const accountId = AddressConverter.parseBech32Address(accountAddress)
const _amount = convertToRawAmount(
Expand All @@ -94,8 +101,12 @@
...getDefaultTransactionOptions(),
manaAllotments: { [accountId]: Number(_amount) },
})
} catch (err) {
transactionInfo.preparedTransactionError = err
} catch (error) {
console.error(error)
transactionInfo.preparedTransaction = undefined
transactionInfo.preparedTransactionError = error
} finally {
updatingTransactionInfo = false
}
}
Expand Down Expand Up @@ -124,7 +135,6 @@
onMount(async () => {
try {
await _onMount()
await preparedAllotMana()
} catch (err) {
error = err.message
handleError(err.error)
Expand Down

0 comments on commit ab55203

Please sign in to comment.