Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: custom mana allotment should send to itself #8528

Merged
merged 11 commits into from
May 20, 2024
38 changes: 19 additions & 19 deletions packages/desktop/components/popups/AllotManaPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
getDefaultTransactionOptions,
AddressConverter,
hasWalletMainAccountNegativeBIC,
convertToRawAmount,
getUnitFromTokenMetadata,
} from '@core/wallet'
import { activeProfile, checkActiveProfileAuth, getNetworkHrp } from '@core/profile'
import { ITransactionInfoToCalculateManaCost } from '@core/network'
Expand All @@ -34,7 +36,7 @@
$selectedWallet?.hasConsolidatingOutputsTransactionInProgress || $selectedWallet?.isTransferring
$: asset = $visibleSelectedWalletAssets[$activeProfile?.network?.id].mana
$: validAmount = Big(rawAmount ?? 0)?.gt(0)
$: accountAddress, validAmount, void preparedOutput()
$: accountAddress, validAmount, amount, void preparedAllotMana()
begonaalvarezd marked this conversation as resolved.
Show resolved Hide resolved
$: accountAddress, void validateAddress()

$: sendAllowed =
Expand Down Expand Up @@ -75,24 +77,22 @@
}
}

async function preparedOutput() {
async function preparedAllotMana() {
if (!accountAddress || !rawAmount || !validAmount) {
transactionInfo.preparedTransaction = undefined
transactionInfo.preparedTransactionError = undefined
return
}
try {
const accountId = AddressConverter.parseBech32Address(accountAddress)
const prepareOutput = await $selectedWallet.prepareOutput(
{
recipientAddress: $selectedWallet.depositAddress,
amount: '0',
},
getDefaultTransactionOptions()
)
transactionInfo.preparedTransaction = await $selectedWallet.prepareSendOutputs([prepareOutput], {
const _amount = convertToRawAmount(
amount,
asset?.metadata,
getUnitFromTokenMetadata(asset?.metadata)
)?.toString()
transactionInfo.preparedTransaction = await $selectedWallet.prepareSendOutputs([], {
...getDefaultTransactionOptions(),
manaAllotments: { [accountId]: Number(rawAmount) },
manaAllotments: { [accountId]: Number(_amount) },
})
} catch (err) {
transactionInfo.preparedTransactionError = err
Expand All @@ -102,14 +102,14 @@
async function allotMana(): Promise<void> {
try {
const accountId = AddressConverter.parseBech32Address(accountAddress)
// Send 0 amount transaction to accountAddress with amount in the allotMana
const prepareOutput = await $selectedWallet.prepareOutput(
{ recipientAddress: accountAddress, amount: '0' },
getDefaultTransactionOptions()
)
await $selectedWallet.sendOutputs([prepareOutput], {
const _amount = convertToRawAmount(
amount,
asset?.metadata,
getUnitFromTokenMetadata(asset?.metadata)
)?.toString()
await $selectedWallet.sendOutputs([], {
...getDefaultTransactionOptions(),
manaAllotments: { [accountId]: Number(rawAmount) }, // if manaAllotments amount passed as bigint it is transformed to string in the sdk
manaAllotments: { [accountId]: Number(_amount) }, // if manaAllotments amount passed as bigint it is transformed to string in the sdk
})
closePopup()
} catch (err) {
Expand All @@ -124,7 +124,7 @@
onMount(async () => {
try {
await _onMount()
await preparedOutput()
await preparedAllotMana()
} catch (err) {
error = err.message
handleError(err.error)
Expand Down
Loading