Skip to content

Commit

Permalink
feat: block and display negative BIC error when main account has nega…
Browse files Browse the repository at this point in the history
…tive BIC (#8320)

* feat: block and display negative BIC error when main account has negative BIC

* fix: add a function for hasMainAccountNegativeBIC
  • Loading branch information
cpl121 authored Apr 5, 2024
1 parent bea102c commit a66a0f6
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 9 deletions.
3 changes: 2 additions & 1 deletion packages/desktop/components/AccountManagementDetails.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
isImplicitAccountOutput,
selectedWallet,
selectedWalletMainAccountId,
hasWalletMainAccountNegativeBIC,
} from '@core/wallet'
import {
AccountAddress,
Expand Down Expand Up @@ -63,7 +64,7 @@
$: formattedStakedAmount = formatTokenAmountBestMatch(rawStakedAmount, getBaseToken())
$: primaryKey = $selectedWallet?.primaryKey
$: listBlockKeysFeature(selectedOutput)
$: hasMainAccountNegativeBIC = $selectedWallet?.balances?.blockIssuanceCredits?.[$selectedWallet?.mainAccountId] < 0
$: hasMainAccountNegativeBIC = hasWalletMainAccountNegativeBIC($selectedWallet)
$: hasAccountNegativeBIC =
$selectedWallet?.balances?.blockIssuanceCredits?.[(selectedOutput.output as AccountOutput)?.accountId] < 0
Expand Down
12 changes: 11 additions & 1 deletion packages/desktop/components/popups/ActivityDetailsPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ActivityDirection,
ActivityType,
claimActivity,
hasWalletMainAccountNegativeBIC,
ignoreActivity,
selectedWallet,
selectedWalletActivities,
Expand All @@ -31,6 +32,7 @@
import { TextHintVariant } from '@ui/enums'
import { onMount } from 'svelte'
import { ManaBox } from '@components'
import { showAppNotification } from '@auxiliary/notification'
export let activityId: string
export let _onMount: (..._: any[]) => Promise<void> = async () => {}
Expand All @@ -48,6 +50,14 @@
activity?.direction === ActivityDirection.SelfTransaction) &&
activity?.asyncData?.asyncStatus === ActivityAsyncStatus.Unclaimed
$: hasMainAccountNegativeBIC = hasWalletMainAccountNegativeBIC($selectedWallet)
$: if (hasMainAccountNegativeBIC) {
showAppNotification({
type: 'warning',
message: localize('views.accountManagement.hasMainAccountNegativeBIC'),
})
}
function onExplorerClick(): void {
let url: string
if (activity?.type === ActivityType.Vesting) {
Expand Down Expand Up @@ -168,7 +178,7 @@
</Button>
<Button
classes="w-full"
disabled={activity.asyncData?.isClaiming || !hasEnoughMana}
disabled={activity.asyncData?.isClaiming || !hasEnoughMana || hasMainAccountNegativeBIC}
onClick={onClaimClick}
isBusy={activity.asyncData?.isClaiming}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
formatTokenAmountPrecise,
IIrc30Metadata,
IMintTokenDetails,
hasWalletMainAccountNegativeBIC,
} from '@core/wallet'
import { closePopup, openPopup, PopupId } from '@auxiliary/popup'
import { Button, KeyValueBox, Text, FontWeight, TextType } from '@ui'
Expand All @@ -18,6 +19,7 @@
import { getClient, prepareCreateNativeToken } from '@core/wallet/actions'
import { ManaBox } from '@components'
import { ITransactionInfoToCalculateManaCost } from '@core/network'
import { showAppNotification } from '@auxiliary/notification'
export let _onMount: (..._: any[]) => Promise<void> = async () => {}
Expand All @@ -30,6 +32,14 @@
$: metadata = getMetadata($mintTokenDetails)
$: isTransferring = $selectedWallet?.isTransferring
$: hasMainAccountNegativeBIC = hasWalletMainAccountNegativeBIC($selectedWallet)
$: if (hasMainAccountNegativeBIC) {
showAppNotification({
type: 'warning',
message: localize('views.accountManagement.hasMainAccountNegativeBIC'),
})
}
async function prepareFoundryOutput(): Promise<void> {
if ($mintTokenDetails && $selectedWallet && metadata) {
const { totalSupply, circulatingSupply, accountAddress } = $mintTokenDetails
Expand Down Expand Up @@ -175,7 +185,7 @@
</Button>
<Button
classes="w-full"
disabled={isTransferring || !hasEnoughMana}
disabled={isTransferring || !hasEnoughMana || hasMainAccountNegativeBIC}
onClick={onConfirmClick}
isBusy={isTransferring}
>
Expand Down
13 changes: 11 additions & 2 deletions packages/desktop/components/popups/MintNftConfirmationPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import { Button, Text, FontWeight, NftImageOrIconBox, Tabs, KeyValueBox, NftSize, TextType } from '@ui'
import { localize } from '@core/i18n'
import { getClient, prepareMintNft } from '@core/wallet/actions'
import { selectedWallet } from '@core/wallet'
import { hasWalletMainAccountNegativeBIC, selectedWallet } from '@core/wallet'
import { buildNftOutputData, formatTokenAmountPrecise, mintNft, mintNftDetails } from '@core/wallet'
import { getBaseToken, checkActiveProfileAuth } from '@core/profile'
import { handleError } from '@core/error/handlers/handleError'
import { closePopup, openPopup, PopupId } from '@auxiliary/popup'
import { CURRENT_IRC27_VERSION } from '@core/nfts'
import { ManaBox } from '@components'
import { ITransactionInfoToCalculateManaCost } from '@core/network'
import { showAppNotification } from '@auxiliary/notification'
export let _onMount: (..._: any[]) => Promise<void> = async () => {}
Expand Down Expand Up @@ -54,6 +55,14 @@
}
}
$: hasMainAccountNegativeBIC = hasWalletMainAccountNegativeBIC($selectedWallet)
$: if (hasMainAccountNegativeBIC) {
showAppNotification({
type: 'warning',
message: localize('views.accountManagement.hasMainAccountNegativeBIC'),
})
}
async function prepareNftOutput(): Promise<void> {
const outputData = buildNftOutputData(irc27Metadata, $selectedWallet.depositAddress)
const client = await getClient()
Expand Down Expand Up @@ -153,7 +162,7 @@
</Button>
<Button
classes="w-full"
disabled={$selectedWallet?.isTransferring || !hasEnoughMana}
disabled={$selectedWallet?.isTransferring || !hasEnoughMana || hasMainAccountNegativeBIC}
onClick={onConfirmClick}
isBusy={$selectedWallet?.isTransferring}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
getDefaultTransactionOptions,
getOutputParameters,
getStorageDepositFromOutput,
hasWalletMainAccountNegativeBIC,
validateSendConfirmation,
} from '@core/wallet/utils'
import { getInitialExpirationDate, rebuildActivity } from '@core/wallet/utils/send/sendUtils'
Expand All @@ -35,6 +36,7 @@
import { onMount } from 'svelte'
import { get } from 'svelte/store'
import { ITransactionInfoToCalculateManaCost } from '@core/network'
import { showAppNotification } from '@auxiliary/notification'
export let _onMount: (..._: any[]) => Promise<void> = async () => {}
export let isSendAndClosePopup: boolean = false
Expand Down Expand Up @@ -228,7 +230,13 @@
closePopup()
}
$: hasMainAccountNegativeBIC = $selectedWallet?.balances?.blockIssuanceCredits?.[$selectedWallet?.mainAccountId] < 0
$: hasMainAccountNegativeBIC = hasWalletMainAccountNegativeBIC($selectedWallet)
$: if (hasMainAccountNegativeBIC) {
showAppNotification({
type: 'warning',
message: localize('views.accountManagement.hasMainAccountNegativeBIC'),
})
}
</script>

<send-confirmation-popup class="w-full h-full space-y-6 flex flex-auto flex-col shrink-0">
Expand Down
10 changes: 8 additions & 2 deletions packages/desktop/views/dashboard/Dashboard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
resetNftDownloadQueue,
selectedWalletNfts,
} from '@core/nfts'
import { selectedWallet, selectedWalletId, clearBalanceSyncPoll, syncBalancePoll } from '@core/wallet'
import {
selectedWallet,
selectedWalletId,
clearBalanceSyncPoll,
syncBalancePoll,
hasWalletMainAccountNegativeBIC,
} from '@core/wallet'
import { get } from 'svelte/store'
import features from '@features/features'
import { isAwareOfMetricSystemDrop, showBalanceOverviewPopup } from '@contexts/dashboard/stores'
Expand All @@ -51,7 +57,7 @@
$: $nftDownloadQueue, downloadNextNftInQueue()
$: $downloadingNftId && interruptNftDownloadAfterTimeout(get(selectedWalletId))
$: addselectedWalletNftsToDownloadQueue($selectedWalletId)
$: hasMainAccountNegativeBIC = $selectedWallet?.balances?.blockIssuanceCredits?.[$selectedWallet?.mainAccountId] < 0
$: hasMainAccountNegativeBIC = hasWalletMainAccountNegativeBIC($selectedWallet)
$: if (hasMainAccountNegativeBIC) {
showAppNotification({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
ignoreActivity,
getTimeDifference,
Activity,
selectedWallet,
hasWalletMainAccountNegativeBIC,
} from '@core/wallet'
import { ActivityAsyncStatusPill, TooltipIcon, Text, Button, TileFooter, FontWeight, ButtonSize } from '@ui'
import { time } from '@core/app'
Expand All @@ -26,6 +28,8 @@
$: timeDiff = getTimeDiff(activity)
$: hasExpirationTime = !!activity.asyncData?.expirationDate
$: hasMainAccountNegativeBIC = hasWalletMainAccountNegativeBIC($selectedWallet)
function onIgnoreClick(): void {
openPopup({
id: PopupId.Confirmation,
Expand Down Expand Up @@ -94,7 +98,7 @@
</Button>
<Button
onClick={onClaimClick}
disabled={activity.asyncData?.isClaiming}
disabled={activity.asyncData?.isClaiming || hasMainAccountNegativeBIC}
isBusy={activity.asyncData?.isClaiming}
inlineStyle="min-width: 4rem;"
size={ButtonSize.Small}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { IWalletState } from '..'

export function hasWalletMainAccountNegativeBIC(wallet: IWalletState | undefined): boolean {
if (!wallet || !wallet.mainAccountId) return false
return wallet.balances?.blockIssuanceCredits?.[wallet.mainAccountId] < 0
}
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 @@ -40,6 +40,7 @@ export * from './validateWalletName'
export * from './isVisibleAsset'
export * from './isVisibleActivity'
export * from './isOutputOfSelectedWalletAddress'
export * from './hasWalletMainAccountNegativeBIC'

// Folders
export * from './generateActivity'
Expand Down

0 comments on commit a66a0f6

Please sign in to comment.