Skip to content

Commit

Permalink
chore: remove metric prefix logic (#2446)
Browse files Browse the repository at this point in the history
* remove `formatTokenAmountPrecise`

* revert rename

* revert basetoken change

---------

Co-authored-by: Nicole O'Brien <[email protected]>
  • Loading branch information
MarkNerdi and nicole-obrien authored May 7, 2024
1 parent d6bfdd3 commit ffab62c
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
} from '@iota/sdk/out/types'
import { closePopup } from '@desktop/auxiliary/popup'
import { api, getClient } from '@core/profile-manager'
import { formatTokenAmountPrecise } from '@core/token'
import { formatTokenAmountBestMatch } from '@core/token'
import { getActiveNetworkId } from '@core/network'
import PopupTemplate from '../PopupTemplate.svelte'
Expand All @@ -38,7 +38,7 @@
try {
const client = await getClient()
const resp = await client.buildAliasOutput(params)
storageDeposit = formatTokenAmountPrecise(Number(resp.amount), getBaseToken())
storageDeposit = formatTokenAmountBestMatch(BigInt(resp.amount), getBaseToken())
} catch (err) {
handleError(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { getBaseToken, 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, formatTokenAmountBestMatch } from '@core/token'
import { getClient } from '@core/profile-manager'
import PopupTemplate from '../PopupTemplate.svelte'
Expand All @@ -28,7 +28,7 @@
)
const client = await getClient()
const preparedOutput = await client.buildFoundryOutput(foundryOutputParams)
storageDeposit = formatTokenAmountPrecise(Number(preparedOutput.amount) ?? 0, getBaseToken())
storageDeposit = formatTokenAmountBestMatch(BigInt(preparedOutput.amount ?? 0), getBaseToken())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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 { formatTokenAmountBestMatch } from '@core/token'
import { buildNftOutputBuilderParams, mintNftCollection, mintNftCollectionDetails } from '@core/wallet'
import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup'
import { MediaIcon, PopupTab, getTabItems } from '@ui'
Expand Down Expand Up @@ -103,7 +103,7 @@
items={[
{
key: localize('general.storageDeposit'),
value: formatTokenAmountPrecise(storageDeposit, getBaseToken()),
value: formatTokenAmountBestMatch(BigInt(storageDeposit), getBaseToken()),
},
{
key: localize('general.immutableIssuer'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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 { formatTokenAmountBestMatch } from '@core/token'
import { buildNftOutputBuilderParams, mintNft, mintNftDetails } from '@core/wallet'
import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup'
import { MediaIcon, PopupTab, getTabItems } from '@ui'
Expand Down Expand Up @@ -125,20 +125,22 @@
{
key: localize('general.storageDepositPerNft'),
value:
quantity > 1 ? formatTokenAmountPrecise(storageDeposit, getBaseToken()) : undefined,
quantity > 1
? formatTokenAmountBestMatch(storageDeposit, getBaseToken())
: undefined,
},
{
key: localize('general.totalStorageDeposit'),
value:
quantity > 1
? formatTokenAmountPrecise(totalStorageDeposit, getBaseToken())
? formatTokenAmountBestMatch(totalStorageDeposit, getBaseToken())
: undefined,
},
{
key: localize('general.storageDeposit'),
value:
quantity === 1
? formatTokenAmountPrecise(storageDeposit, getBaseToken())
? formatTokenAmountBestMatch(storageDeposit, getBaseToken())
: undefined,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { ExplorerEndpoint, getActiveNetworkId, getDefaultExplorerUrl } from '@core/network'
import { IIrc27Nft } from '@core/nfts'
import { getBaseToken } from '@core/profile/actions'
import { formatTokenAmountPrecise } from '@core/token'
import { formatTokenAmountBestMatch } from '@core/token'
import { getBech32AddressFromAddressTypes, getHexAddressFromAddressTypes } from '@core/wallet'
import { AddressType } from '@iota/sdk/out/types'
import { NetworkLabel } from '@ui'
Expand Down Expand Up @@ -51,7 +51,7 @@
},
{
key: localize('general.storageDeposit'),
value: storageDeposit ? formatTokenAmountPrecise(storageDeposit, getBaseToken()) : undefined,
value: storageDeposit ? formatTokenAmountBestMatch(storageDeposit, getBaseToken()) : undefined,
},
{
key: localize('general.standard'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const IOTA_BASE_TOKEN: IBaseToken = {
unit: 'IOTA',
decimals: 6,
subunit: 'micro',
useMetricPrefix: false,
}

export const SHIMMER_BASE_TOKEN: IBaseToken = {
Expand All @@ -20,7 +19,6 @@ export const SHIMMER_BASE_TOKEN: IBaseToken = {
unit: 'SMR',
decimals: 6,
subunit: 'glow',
useMetricPrefix: false,
}

export const EVM_BASE_TOKEN: IBaseToken = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ export interface IBaseToken {
unit: string
subunit?: string | null
decimals: number
useMetricPrefix?: boolean
}
41 changes: 19 additions & 22 deletions packages/shared/src/lib/core/token/tests/convertToRawAmount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const WEB3_TOKEN_METADATA: TokenMetadata = {
unit: 'RAWR',
decimals: 60,
subunit: 'MEOW',
useMetricPrefix: false,
standard: TokenStandard.BaseToken,
}

Expand All @@ -32,27 +31,25 @@ describe('File: convertToRawAmount.ts', () => {
})

describe('given the tokenMetadata standard is BaseToken', () => {
describe("given useMetricPrefix is false (currently Shimmer's case)", () => {
const networkId = SupportedNetworkId.Shimmer
it("should return amount * decimal property if selectedUnit is unit and baseToken's decimal is less than MAX_SUPPORTED_DECIMALS", () => {
let value = convertToRawAmount('1', DEFAULT_BASE_TOKEN[networkId], 'SMR')?.toString() ?? '0'
expect(value).toStrictEqual('1000000')
})
it("should return XXX if selectedUnit is unit and baseToken's decimals property is greater than MAX_SUPPORTED_DECIMALS", () => {
let value = convertToRawAmount('1', WEB3_TOKEN_METADATA, 'RAWR')?.toString() ?? '0'
expect(value).toStrictEqual('1000000000000000000000000000000000000000000000000000000000000')
})
it('should return same amount if selectedUnit is subunit', () => {
let value = convertToRawAmount('1', DEFAULT_BASE_TOKEN[networkId], 'glow')?.toString() ?? '0'
expect(value).toStrictEqual('1')
})
it('should return base tokens unit if no unit is provided', () => {
let value = convertToRawAmount('1', DEFAULT_BASE_TOKEN[networkId])?.toString() ?? '0'
expect(value).toStrictEqual('1000000')
})
it('should return undefined if provided unit does not match the tokenMetadata unit or subunit', () => {
expect(convertToRawAmount('1', DEFAULT_BASE_TOKEN[networkId], 'test')).toStrictEqual(undefined)
})
const networkId = SupportedNetworkId.Shimmer
it("should return amount * decimal property if selectedUnit is unit and baseToken's decimal is less than MAX_SUPPORTED_DECIMALS", () => {
let value = convertToRawAmount('1', DEFAULT_BASE_TOKEN[networkId], 'SMR')?.toString() ?? '0'
expect(value).toStrictEqual('1000000')
})
it("should return XXX if selectedUnit is unit and baseToken's decimals property is greater than MAX_SUPPORTED_DECIMALS", () => {
let value = convertToRawAmount('1', WEB3_TOKEN_METADATA, 'RAWR')?.toString() ?? '0'
expect(value).toStrictEqual('1000000000000000000000000000000000000000000000000000000000000')
})
it('should return same amount if selectedUnit is subunit', () => {
let value = convertToRawAmount('1', DEFAULT_BASE_TOKEN[networkId], 'glow')?.toString() ?? '0'
expect(value).toStrictEqual('1')
})
it('should return base tokens unit if no unit is provided', () => {
let value = convertToRawAmount('1', DEFAULT_BASE_TOKEN[networkId])?.toString() ?? '0'
expect(value).toStrictEqual('1000000')
})
it('should return undefined if provided unit does not match the tokenMetadata unit or subunit', () => {
expect(convertToRawAmount('1', DEFAULT_BASE_TOKEN[networkId], 'test')).toStrictEqual(undefined)
})
})
describe('given the tokenMetadata standard is Irc30', () => {
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion 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 './getMaxDecimalsFromTokenMetadata'
export * from './getTokenInitials'
export * from './getUnitFromTokenMetadata'
Expand Down
3 changes: 1 addition & 2 deletions packages/shared/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -980,8 +980,7 @@
"tickerSymbol": "Ticker",
"unit": "Unit",
"subunit": "Sub-unit",
"decimals": "Decimals",
"useMetricPrefix": "Use metric prefix"
"decimals": "Decimals"
}
},
"jwt": "JSON web token",
Expand Down
1 change: 0 additions & 1 deletion packages/shared/test/mocks/profile-manager.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export class ProfileManagerMock implements IProfileManager {
unit: 'SMR',
subunit: 'glow',
decimals: 6,
useMetricPrefix: false,
},
metrics: {
blocksPerSecond: 1.3,
Expand Down

0 comments on commit ffab62c

Please sign in to comment.