Skip to content

Commit

Permalink
fix: claiming txs reminder strategy (#8476)
Browse files Browse the repository at this point in the history
* fix: displayed mana in tx details WIP

* fix: improvements

* fix: check type

* fixes and improvements

* fix

* fix: Consolidation activities

* fmt

* fix linter

* fix

* fix: Claim to account

* chore: alpha 9

* clean up

* fix: clean up

---------

Co-authored-by: cpl121 <cpeon@boxfish.studio>
Co-authored-by: cpl121 <100352899+cpl121@users.noreply.github.com>
Co-authored-by: evavirseda <evirseda@boxfish.studio>
Co-authored-by: Begoña Álvarez de la Cruz <balvarez@boxfish.studio>
  • Loading branch information
5 people authored May 6, 2024
1 parent 9f425e4 commit 868e151
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ActivityDirection,
ActivityType,
claimActivity,
getAccountTransactionOptions,
hasWalletMainAccountNegativeBIC,
ignoreActivity,
selectedWallet,
Expand Down Expand Up @@ -81,7 +82,10 @@
async function prepareClaimOutput(): Promise<void> {
try {
transactionInfo.preparedTransaction = await $selectedWallet?.prepareClaimOutputs([activity.outputId])
transactionInfo.preparedTransaction = await $selectedWallet?.prepareClaimOutputs(
[activity.outputId],
getAccountTransactionOptions()
)
} catch (error) {
transactionInfo.preparedTransactionError = error
}
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop/components/popups/AllotManaPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
getDefaultTransactionOptions()
)
transactionInfo.preparedTransaction = await $selectedWallet.prepareSendOutputs([prepareOutput], {
...getDefaultTransactionOptions(accountId),
...getDefaultTransactionOptions(),
manaAllotments: { [accountId]: Number(rawAmount) },
})
} catch (err) {
Expand All @@ -108,7 +108,7 @@
getDefaultTransactionOptions()
)
await $selectedWallet.sendOutputs([prepareOutput], {
...getDefaultTransactionOptions(accountId),
...getDefaultTransactionOptions(),
manaAllotments: { [accountId]: Number(rawAmount) }, // if manaAllotments amount passed as bigint it is transformed to string in the sdk
})
closePopup()
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/lib/core/wallet/actions/claimActivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
updateAsyncDataByActivityId,
} from '../stores'
import { Activity } from '../types'
import { getAccountTransactionOptions } from '../utils'

export async function claimActivity(activity: Activity): Promise<void> {
const wallet = getSelectedWallet()
Expand All @@ -17,7 +18,7 @@ export async function claimActivity(activity: Activity): Promise<void> {
}

updateAsyncDataByActivityId(wallet.id, activity.id, { isClaiming: true })
const result = await wallet.claimOutputs([activity.outputId])
const result = await wallet.claimOutputs([activity.outputId], getAccountTransactionOptions())
const transactionId = result.transactionId
updateAsyncDataByActivityId(wallet.id, activity.id, { claimingTransactionId: transactionId })
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,9 @@ export async function handleNewOutputEventInternal(walletId: string, payload: Ne
const isNftOutput = output.type === OutputType.Nft
const _isDelegationOutput = isDelegationOutput(outputData)

const address = outputData.address ? AddressConverter.addressToBech32(outputData.address) : undefined

// The basic outputs of the faucet dont have an address
const isBasicOutput = output.type === OutputType.Basic
if (
(address && wallet?.depositAddress === address && !outputData?.remainder) ||
isAccountOutput(outputData) ||
isDelegationOutput(outputData) ||
isBasicOutput
) {
if (!outputData?.remainder || isAccountOutput(outputData) || isDelegationOutput(outputData) || isBasicOutput) {
await syncBalance(wallet.id, true)
const walletOutputs = await wallet.outputs()
const walletUnspentOutputs = await wallet.unspentOutputs()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { AccountAddress, TransactionOptions } from '@iota/sdk/out/types'
import { getSelectedWallet } from '../stores'

export function getAccountTransactionOptions(
accountId: string | undefined = getSelectedWallet()?.mainAccountId
): TransactionOptions | undefined {
if (!accountId) return
return {
remainderValueStrategy: {
/** The name of the strategy. */
strategy: 'CustomAddress',
/** Only required for `CustomAddress`. */
value: new AccountAddress(accountId),
},
allowMicroAmount: true,
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { TransactionOptions } from '@iota/sdk/out/types'
import { getSelectedWallet } from '../stores'

export function getDefaultTransactionOptions(
accountId: string | undefined = getSelectedWallet()?.mainAccountId
): TransactionOptions | undefined {
if (!accountId) return
export function getDefaultTransactionOptions(): TransactionOptions {
return {
remainderValueStrategy: {
/** The name of the strategy. */
Expand Down
1 change: 1 addition & 0 deletions packages/shared/lib/core/wallet/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export * from './isVisibleActivity'
export * from './isOutputUnlockedByAddress'
export * from './hasWalletMainAccountNegativeBIC'
export * from './getInvolvedAddresses'
export * from './getAccountTransactionOptions'

// Folders
export * from './generateActivity'
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "Apache-2.0",
"dependencies": {
"@iota/crypto.js": "^1.8.6",
"@iota/sdk": "2.0.0-alpha.8",
"@iota/sdk": "2.0.0-alpha.9",
"@iota/unit-converter": "^1.0.0-beta.30",
"@iota/util.js": "^2.0.0-rc.1",
"@sveltejs/svelte-virtual-list": "^3.0.1",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -712,10 +712,10 @@
"@iota/util.js" "^1.8.6"
big-integer "^1.6.51"

"@iota/sdk@2.0.0-alpha.8":
version "2.0.0-alpha.8"
resolved "https://registry.yarnpkg.com/@iota/sdk/-/sdk-2.0.0-alpha.8.tgz#f93504179a170b6c13a1e188a73087514e3a4160"
integrity sha512-slvpu3l/r4SllE+c0EQOZwNEX4LkxKS/mihNtVVeV8vK8ppetAx0gOKjInrZoDBAQk4uZgHgD7+PhTnOBg1reQ==
"@iota/sdk@2.0.0-alpha.9":
version "2.0.0-alpha.9"
resolved "https://registry.yarnpkg.com/@iota/sdk/-/sdk-2.0.0-alpha.9.tgz#79d44f851b25d43fddf33fdffe634e8e434a8827"
integrity sha512-0ovOJ3q6EQ12ZhEVsNKng7bWCA66+qsat3Y+mH4RnoQYnHQQ65DsOvkgJkpiMxorsn9IjrQGCSrk0/tHRhFvEA==
dependencies:
class-transformer "^0.5.1"
prebuild-install "^7.1.1"
Expand Down

0 comments on commit 868e151

Please sign in to comment.