Skip to content

Commit

Permalink
remove formatTokenAmountPrecise
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkNerdi committed May 6, 2024
1 parent 2ffa845 commit 9f66bad
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { processAndAddToActivities } from '@core/activity/actions'
import { handleError } from '@core/error/handlers/handleError'
import { localize } from '@core/i18n'
import { checkActiveProfileAuth, getBaseToken } from '@core/profile/actions'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { EMPTY_HEX_ID, sendPreparedTransaction } from '@core/wallet'
import {
AliasOutputBuilderParams,
Expand All @@ -14,12 +14,13 @@
} from '@iota/sdk/out/types'
import { closePopup } from '@desktop/auxiliary/popup'
import { api, getClient } from '@core/profile-manager'
import { formatTokenAmountPrecise } from '@core/token'
import { getActiveNetworkId } from '@core/network'
import { formatTokenAmount } from '@core/token'
import { getL1Network } from '@core/network'
import PopupTemplate from '../PopupTemplate.svelte'
let storageDeposit: string = '0'
const network = getL1Network()
const address = new Ed25519Address(api.bech32ToHex($selectedAccount.depositAddress))
const aliasOutputParams: AliasOutputBuilderParams = {
Expand All @@ -38,7 +39,7 @@
try {
const client = await getClient()
const resp = await client.buildAliasOutput(params)
storageDeposit = formatTokenAmountPrecise(Number(resp.amount), getBaseToken())
storageDeposit = formatTokenAmount(BigInt(resp.amount), network.baseToken)
} catch (err) {
handleError(err)
}
Expand All @@ -52,12 +53,10 @@
}
try {
const networkId = getActiveNetworkId()
updateSelectedAccount({ isTransferring: true })
const preparedTransaction = await $selectedAccount.prepareCreateAliasOutput()
const transaction = await sendPreparedTransaction(preparedTransaction)
await processAndAddToActivities(transaction, $selectedAccount, networkId)
await processAndAddToActivities(transaction, $selectedAccount, network.id)
closePopup()
} catch (err) {
handleError(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import { selectedAccount } from '@core/account/stores'
import { localize } from '@core/i18n'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { ITokenWithBalance, formatTokenAmountBestMatch } from '@core/token'
import { ITokenWithBalance, formatTokenAmount } from '@core/token'
import { burnToken } from '@core/wallet'
import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup'
import PopupTemplate from '../PopupTemplate.svelte'
export let token: ITokenWithBalance
export let rawAmount: bigint
$: formattedAmount = formatTokenAmountBestMatch(rawAmount, token?.metadata)
$: formattedAmount = formatTokenAmount(rawAmount, token?.metadata)
function onBackClick(): void {
openPopup({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import { selectedAccount } from '@core/account/stores'
import { handleError } from '@core/error/handlers/handleError'
import { localize } from '@core/i18n'
import { getBaseToken, checkActiveProfileAuth } from '@core/profile/actions'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { mintNativeToken, mintTokenDetails, buildFoundryOutputBuilderParams, IMintTokenDetails } from '@core/wallet'
import { closePopup, openPopup, PopupId } from '@desktop/auxiliary/popup'
import { IIrc30Metadata, TokenStandard, formatTokenAmountPrecise } from '@core/token'
import { IIrc30Metadata, TokenStandard, formatTokenAmount } from '@core/token'
import { getClient } from '@core/profile-manager'
import PopupTemplate from '../PopupTemplate.svelte'
import { getL1Network } from '@core/network'
const network = getL1Network()
let storageDeposit = '0'
Expand All @@ -28,7 +31,7 @@
)
const client = await getClient()
const preparedOutput = await client.buildFoundryOutput(foundryOutputParams)
storageDeposit = formatTokenAmountPrecise(Number(preparedOutput.amount) ?? 0, getBaseToken())
storageDeposit = formatTokenAmount(BigInt(preparedOutput.amount ?? 0), network.baseToken)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
import { localize } from '@core/i18n'
import { CURRENT_IRC27_VERSION, IIrc27Metadata } from '@core/nfts'
import { getClient } from '@core/profile-manager'
import { checkActiveProfileAuth, getBaseToken } from '@core/profile/actions'
import { formatTokenAmountPrecise } from '@core/token'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { formatTokenAmount } from '@core/token'
import { buildNftOutputBuilderParams, mintNftCollection, mintNftCollectionDetails } from '@core/wallet'
import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup'
import { MediaIcon, PopupTab, getTabItems } from '@ui'
import { onMount } from 'svelte'
import PopupTemplate from '../PopupTemplate.svelte'
import { getL1Network } from '@core/network'
const TABS = getTabItems([PopupTab.Transaction, PopupTab.Nft, PopupTab.NftMetadata])
const network = getL1Network()
let selectedTab = TABS[0]
Expand Down Expand Up @@ -103,7 +105,7 @@
items={[
{
key: localize('general.storageDeposit'),
value: formatTokenAmountPrecise(storageDeposit, getBaseToken()),
value: formatTokenAmount(BigInt(storageDeposit), network.baseToken),
},
{
key: localize('general.immutableIssuer'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
import { localize } from '@core/i18n'
import { CURRENT_IRC27_VERSION, IIrc27Metadata } from '@core/nfts'
import { getClient } from '@core/profile-manager'
import { checkActiveProfileAuth, getBaseToken } from '@core/profile/actions'
import { formatTokenAmountPrecise } from '@core/token'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { formatTokenAmount } from '@core/token'
import { buildNftOutputBuilderParams, mintNft, mintNftDetails } from '@core/wallet'
import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup'
import { MediaIcon, PopupTab, getTabItems } from '@ui'
import { onMount } from 'svelte'
import PopupTemplate from '../PopupTemplate.svelte'
import { getL1Network } from '@core/network'
const TABS = getTabItems([PopupTab.Transaction, PopupTab.Nft, PopupTab.NftMetadata])
const network = getL1Network()
let selectedTab = TABS[0]
let storageDeposit: number = 0
Expand Down Expand Up @@ -124,22 +127,19 @@
},
{
key: localize('general.storageDepositPerNft'),
value:
quantity > 1 ? formatTokenAmountPrecise(storageDeposit, getBaseToken()) : undefined,
value: quantity > 1 ? formatTokenAmount(storageDeposit, network.baseToken) : undefined,
},
{
key: localize('general.totalStorageDeposit'),
value:
quantity > 1
? formatTokenAmountPrecise(totalStorageDeposit, getBaseToken())
? formatTokenAmount(totalStorageDeposit, network.baseToken)
: undefined,
},
{
key: localize('general.storageDeposit'),
value:
quantity === 1
? formatTokenAmountPrecise(storageDeposit, getBaseToken())
: undefined,
quantity === 1 ? formatTokenAmount(storageDeposit, network.baseToken) : undefined,
},
{
key: localize('general.immutableIssuer'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { RecoverAccountsPayload, recoverAccounts } from '@core/profile-manager'
import { checkActiveProfileAuth, getBaseToken, loadAccounts } from '@core/profile/actions'
import { activeAccounts, activeProfile, getActiveProfileId, visibleActiveAccounts } from '@core/profile/stores'
import { formatTokenAmountBestMatch } from '@core/token'
import { formatTokenAmount } from '@core/token'
import { loadTokensForAllAccountBalances } from '@core/token/actions'
import { closePopup } from '@desktop/auxiliary/popup'
import { onDestroy } from 'svelte'
Expand Down Expand Up @@ -167,7 +167,7 @@
},
{
key: localize('popups.walletFinder.totalWalletBalance'),
value: formatTokenAmountBestMatch(totalBalance, getBaseToken()),
value: formatTokenAmount(totalBalance, getBaseToken()),
},
]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import { selectedAccount } from '@core/account/stores'
import { localize } from '@core/i18n'
import { checkActiveProfileAuth, getBaseToken } from '@core/profile/actions'
import { formatTokenAmountBestMatch } from '@core/token'
import { formatTokenAmount } from '@core/token'
import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup'
import PopupTemplate from '../PopupTemplate.svelte'
export let selectedAnswerValues: number[]
$: formattedVotingPower = formatTokenAmountBestMatch($selectedAccount?.votingPower, getBaseToken())
$: formattedVotingPower = formatTokenAmount($selectedAccount?.votingPower, getBaseToken())
$: hasVotingPower = $selectedAccount?.votingPower > 0
$: hasGovernanceTransactionInProgress =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<script lang="ts">
import { type IItem } from '@bloomwalletio/ui'
import { localize } from '@core/i18n'
import { ExplorerEndpoint, getActiveNetworkId, getDefaultExplorerUrl } from '@core/network'
import { ExplorerEndpoint, getDefaultExplorerUrl, getL1Network } from '@core/network'
import { IIrc27Nft } from '@core/nfts'
import { getBaseToken } from '@core/profile/actions'
import { formatTokenAmountPrecise } from '@core/token'
import { formatTokenAmount } from '@core/token'
import { getBech32AddressFromAddressTypes, getHexAddressFromAddressTypes } from '@core/wallet'
import { AddressType } from '@iota/sdk/out/types'
import { NetworkLabel } from '@ui'
Expand All @@ -13,6 +12,8 @@
export let nft: IIrc27Nft
const l1Network = getL1Network()
const { id, issuer, nftAddress, metadata, storageDeposit, mediaUrl } = nft ?? {}
const { standard, version, issuerName, collectionName } = nft?.metadata || {}
Expand Down Expand Up @@ -51,7 +52,7 @@
},
{
key: localize('general.storageDeposit'),
value: storageDeposit ? formatTokenAmountPrecise(storageDeposit, getBaseToken()) : undefined,
value: storageDeposit ? formatTokenAmount(storageDeposit, l1Network.baseToken) : undefined,
},
{
key: localize('general.standard'),
Expand Down Expand Up @@ -86,7 +87,7 @@
function getExplorerEndpoint(): string | undefined {
// We don't use `nft.networkId` on this one, as for IRC27 nfts we still want the L1 explorer
const { baseUrl, endpoint } = getDefaultExplorerUrl(getActiveNetworkId(), ExplorerEndpoint.Nft)
const { baseUrl, endpoint } = getDefaultExplorerUrl(l1Network.id, ExplorerEndpoint.Nft)
const url = buildUrl({
origin: baseUrl,
pathname: `${endpoint}/${id}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type FormatOptions = Partial<{
decimals: number
}>

export function formatTokenAmountBestMatch(
export function formatTokenAmount(
amount: bigint | undefined,
tokenMetadata?: TokenMetadata,
options?: FormatOptions
Expand Down

This file was deleted.

3 changes: 1 addition & 2 deletions packages/shared/src/lib/core/token/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from './buildPersistedTokenFromMetadata'
export * from './convertToRawAmount'
export * from './formatTokenAmountBestMatch'
export * from './formatTokenAmountPrecise'
export * from './formatTokenAmount'
export * from './getMaxDecimalsFromTokenMetadata'
export * from './getTokenInitials'
export * from './getUnitFromTokenMetadata'
Expand Down

0 comments on commit 9f66bad

Please sign in to comment.