Skip to content

Commit

Permalink
fix: not visible surplus (#5968)
Browse files Browse the repository at this point in the history
* feat: adds surplus to base activity type

* feat: adds surplus to GenericActivityInformation

* fix: adds visible surplus

* fix: adds surplus not supported in base asset error

* fix: hide gift toggle if it is disabled and not active

* fix: adds gifted storage deposit calculation if sending base token

* fix

---------

Co-authored-by: Nicole O'Brien <nicole.obrien@iota.org>
Co-authored-by: Matthew Maxwell <44885822+maxwellmattryan@users.noreply.github.com>
  • Loading branch information
3 people committed Mar 8, 2023
1 parent 4a81abd commit 3eaecdb
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 5 deletions.
Expand Up @@ -63,6 +63,7 @@
} = get(newTransactionDetails)
let storageDeposit = 0
let visibleSurplus = 0
let preparedOutput: Output
let outputOptions: OutputOptions
let expirationTimePicker: ExpirationTimePicker
Expand All @@ -75,8 +76,9 @@
$: isInternal = recipient.type === 'account'
$: expirationTimePicker?.setNull(giftStorageDeposit)
$: hideGiftToggle =
transactionDetails.type === NewTransactionType.TokenTransfer &&
transactionDetails.assetId === $selectedAccountAssets?.baseCoin?.id
(transactionDetails.type === NewTransactionType.TokenTransfer &&
transactionDetails.assetId === $selectedAccountAssets?.baseCoin?.id) ||
(disableToggleGift && !giftStorageDeposit)
$: expirationDate, giftStorageDeposit, refreshSendConfirmationState()
$: isTransferring = $selectedAccount.isTransferring
Expand All @@ -86,6 +88,7 @@
subject: recipient,
isInternal,
giftedStorageDeposit: 0,
surplus: visibleSurplus,
type: ActivityType.Basic,
direction: ActivityDirection.Outgoing,
inclusionState: InclusionState.Pending,
Expand Down Expand Up @@ -145,8 +148,15 @@
}
function setStorageDeposit(preparedOutput: Output, surplus?: number): void {
const rawAmount =
transactionDetails.type === NewTransactionType.TokenTransfer ? transactionDetails.rawAmount : '0'
const { storageDeposit: _storageDeposit, giftedStorageDeposit: _giftedStorageDeposit } =
getStorageDepositFromOutput(preparedOutput)
getStorageDepositFromOutput(preparedOutput, rawAmount)
if (surplus > _storageDeposit) {
visibleSurplus = Number(surplus)
}
if (giftStorageDeposit) {
// Only giftedStorageDeposit needs adjusting, since that is derived
Expand Down
Expand Up @@ -24,6 +24,7 @@
$: baseToken = BASE_TOKEN[$activeProfile?.networkProtocol]
$: formattedStorageDeposit = formatTokenAmountPrecise(activity.storageDeposit ?? 0, baseToken)
$: formattedGiftedStorageDeposit = formatTokenAmountPrecise(activity.giftedStorageDeposit ?? 0, baseToken)
$: formattedSurplus = formatTokenAmountPrecise(activity.surplus ?? 0, baseToken)
$: formattedGasBudget = formatTokenAmountPrecise(Number(gasBudget ?? 0), baseToken)
let transactionDetailsList: IKeyValueBoxList
Expand All @@ -43,6 +44,9 @@
...(hasStorageDeposit && {
storageDeposit: { data: formattedStorageDeposit, isTooltipVisible: true },
}),
...(activity?.surplus && {
surplus: { data: formattedSurplus },
}),
...(activity?.giftedStorageDeposit && {
giftedStorageDeposit: { data: formattedGiftedStorageDeposit, isTooltipVisible: true },
}),
Expand Down
1 change: 1 addition & 0 deletions packages/shared/lib/auxiliary/deep-link/errors/index.ts
Expand Up @@ -5,4 +5,5 @@ export * from './metadata-length.error'
export * from './no-address-specified.error'
export * from './tag-length.error'
export * from './surplus-not-a-number.error'
export * from './surplus-not-supported.error'
export * from './unknown-asset.error'
@@ -0,0 +1,14 @@
import { BaseError } from '@core/error'
import { localize } from '@core/i18n'

export class SurplusNotSupportedError extends BaseError {
constructor() {
const message = localize('notifications.deepLinkingRequest.surplusNotSupported')
super({
message,
showNotification: true,
saveToErrorLog: true,
logToConsole: true,
})
}
}
Expand Up @@ -14,10 +14,11 @@ import { openPopup, PopupId } from '@auxiliary/popup'

import { SendOperationParameter } from '../../../enums'
import {
SurplusNotANumberError,
InvalidAddressError,
MetadataLengthError,
NoAddressSpecifiedError,
SurplusNotANumberError,
SurplusNotSupportedError,
TagLengthError,
UnknownAssetError,
} from '../../../errors'
Expand Down Expand Up @@ -72,6 +73,8 @@ function parseSendConfirmationOperation(searchParams: URLSearchParams): NewTrans
const surplus = searchParams.get(SendOperationParameter.Surplus)
if (surplus && parseInt(surplus).toString() !== surplus) {
throw new SurplusNotANumberError(surplus)
} else if (surplus && asset.id === baseAsset.id) {
throw new SurplusNotSupportedError()
}

const metadata = searchParams.get(SendOperationParameter.Metadata)
Expand Down
Expand Up @@ -16,6 +16,7 @@ export type BaseActivity = {
isInternal: boolean
storageDeposit: number
giftedStorageDeposit: number
surplus?: number
subject: Subject
metadata?: string
tag?: string
Expand Down
Expand Up @@ -2,7 +2,10 @@ import { Output } from '@core/wallet/types'
import { IStorageDepositReturnUnlockCondition } from '@iota/types'
import { OUTPUT_TYPE_NFT, UNLOCK_CONDITION_STORAGE_DEPOSIT_RETURN } from '../../../constants'

export function getStorageDepositFromOutput(output: Output): {
export function getStorageDepositFromOutput(
output: Output,
rawAmount?: string
): {
storageDeposit: number
giftedStorageDeposit: number
} {
Expand All @@ -15,6 +18,8 @@ export function getStorageDepositFromOutput(output: Output): {
return { storageDeposit: Number(storageDepositReturnUnlockCondition.amount), giftedStorageDeposit: 0 }
} else if (output.type === OUTPUT_TYPE_NFT || (output?.nativeTokens?.length > 0 && Number(output?.amount) > 0)) {
return { storageDeposit: 0, giftedStorageDeposit: Number(output?.amount) }
} else if (rawAmount && Number(rawAmount) > 0 && Number(output?.amount) > Number(rawAmount)) {
return { storageDeposit: 0, giftedStorageDeposit: Number(output?.amount) - Number(rawAmount) }
} else {
return { storageDeposit: 0, giftedStorageDeposit: 0 }
}
Expand Down
1 change: 1 addition & 0 deletions packages/shared/locales/en.json
Expand Up @@ -1717,6 +1717,7 @@
"invalidFormat": "The deep link you followed is invalid",
"invalidAmount": "The amount in deep link is not an integer number {amount}",
"invalidSurplus": "The surplus in deep link is not a number {surplus}",
"surplusNotSupported": "The surplus is only supported for native tokens",
"governance": {
"unrecognizedOperation": "Unrecognized Governance operation: {operation}"
},
Expand Down

0 comments on commit 3eaecdb

Please sign in to comment.