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: claiming txs reminder strategy #8476

Merged
merged 23 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading