Skip to content

Commit

Permalink
Merge branch 'develop-iota2.0' into feat/allow-to-allot-mana
Browse files Browse the repository at this point in the history
  • Loading branch information
cpl121 authored Mar 25, 2024
2 parents 8181735 + 130c597 commit dc45325
Show file tree
Hide file tree
Showing 29 changed files with 144 additions and 134 deletions.
14 changes: 7 additions & 7 deletions packages/desktop/components/popups/BalanceBreakdownPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@
}
function getManaBreakdown(): BalanceBreakdown {
const totalBalanceWithoutBic = getManaBalance(walletBalance?.mana?.total)
const availableBalance = getManaBalance(walletBalance?.mana?.available)
const totalBalance = totalBalanceWithoutBic + walletBalance.totalWalletBic
const totalPasiveMana = getManaBalance(walletBalance?.mana?.total)
const availablePasiveBalance = getManaBalance(walletBalance?.mana?.available)
const totalMana = totalPasiveMana + (walletBalance?.totalWalletBic ?? 0)
const subBreakdown = {
availableMana: { amount: availableBalance },
lockedMana: { amount: totalBalanceWithoutBic - availableBalance },
bicMana: { amount: walletBalance.totalWalletBic },
availableMana: { amount: availablePasiveBalance },
lockedMana: { amount: totalPasiveMana - availablePasiveBalance },
bicMana: { amount: walletBalance?.totalWalletBic },
}
return { amount: totalBalance, subBreakdown, isBaseToken: false }
return { amount: totalMana, subBreakdown, isBaseToken: false }
}
async function getPendingBreakdown(): Promise<BalanceBreakdown> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
async function prepareFoundryOutput(): Promise<void> {
if ($mintTokenDetails && $selectedWallet && metadata) {
const { totalSupply, circulatingSupply, accountId } = $mintTokenDetails
const { totalSupply, circulatingSupply, accountAddress } = $mintTokenDetails
const outputData = await buildFoundryOutputData(
Number(totalSupply),
Number(circulatingSupply),
metadata,
accountId
accountAddress
)
const client = await getClient()
const preparedOutput = await client.buildFoundryOutput(outputData)
Expand All @@ -61,10 +61,10 @@
details: IMintTokenDetails | undefined
): { [key: string]: { data: string; tooltipText?: string; isCopyable?: boolean } } | undefined {
if (details) {
const { name: tokenName, symbol, accountId, url, logoUrl, decimals, totalSupply } = details
const { name: tokenName, symbol, accountAddress, url, logoUrl, decimals, totalSupply } = details
return {
...(accountId && {
account: { data: accountId, isCopyable: true },
...(accountAddress && {
account: { data: accountAddress, isCopyable: true },
}),
...(storageDeposit && {
storageDeposit: { data: storageDeposit },
Expand Down
26 changes: 13 additions & 13 deletions packages/desktop/components/popups/MintNativeTokenFormPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { localize } from '@core/i18n'
import { setMintTokenDetails, mintTokenDetails, IMintTokenDetails } from '@core/wallet'
import { closePopup, openPopup, PopupId } from '@auxiliary/popup'
import { Button, Error, NumberInput, Text, TextInput, OptionalInput, FontWeight, AccountInput } from '@ui'
import { Button, Error, NumberInput, Text, TextInput, OptionalInput, FontWeight, AccountInput, TextType } from '@ui'
import { onMount } from 'svelte'
import { MAX_SUPPORTED_DECIMALS } from '@core/wallet/constants/max-supported-decimals.constants'
import { handleError } from '@core/error/handlers/handleError'
Expand All @@ -19,7 +19,7 @@
description: undefined,
url: undefined,
logoUrl: undefined,
accountId: undefined,
accountAddress: undefined,
}
let {
Expand All @@ -31,7 +31,7 @@
description,
url,
logoUrl,
accountId,
accountAddress,
} = $mintTokenDetails ?? DEFAULT
let nameError: string = ''
Expand All @@ -42,8 +42,8 @@
$: circulatingSupply, (circulatingSupplyError = '')
let symbolError: string
$: symbol, (symbolError = '')
let accountIdError: string
$: accountId, (accountIdError = '')
let accountAddressError: string
$: accountAddress, (accountAddressError = '')
let error: BaseError
let decimalsInput: OptionalInput
Expand All @@ -64,7 +64,7 @@
description,
url,
logoUrl,
accountId,
accountAddress,
}
if (valid && isEverythingDefined(tokenDetailsForm)) {
setMintTokenDetails(tokenDetailsForm)
Expand All @@ -82,7 +82,7 @@
form.circulatingSupply !== undefined &&
form.decimals !== undefined &&
form.symbol !== undefined &&
form.accountId !== undefined
form.accountAddress !== undefined
)
}
Expand Down Expand Up @@ -170,12 +170,12 @@
</script>

<div class="space-y-6">
<Text type="h4" fontSize="18" lineHeight="6" fontWeight={FontWeight.semibold}>
<Text type={TextType.h4} fontSize="18" lineHeight="6" fontWeight={FontWeight.semibold}>
{localize('popups.nativeToken.formTitle')}
</Text>

<div class="space-y-4 max-h-100 scrollable-y flex-1">
<AccountInput bind:this={accountInput} bind:account={accountId} bind:error={accountIdError} />
<AccountInput bind:this={accountInput} bind:account={accountAddress} bind:error={accountAddressError} />
<TextInput
bind:value={tokenName}
label={localize('popups.nativeToken.property.tokenName')}
Expand Down Expand Up @@ -212,25 +212,25 @@
maxlength={MAX_SUPPORTED_DECIMALS}
label={localize('popups.nativeToken.property.decimals')}
description={localize('tooltips.mintNativeToken.decimals')}
fontSize="14"
fontSize={14}
/>
<OptionalInput
bind:value={description}
label={localize('popups.nativeToken.property.description')}
description={localize('tooltips.mintNativeToken.description')}
fontSize="14"
fontSize={14}
/>
<OptionalInput
bind:value={url}
label={localize('popups.nativeToken.property.url')}
description={localize('tooltips.mintNativeToken.url')}
fontSize="14"
fontSize={14}
/>
<OptionalInput
bind:value={logoUrl}
label={localize('popups.nativeToken.property.logoUrl')}
description={localize('tooltips.mintNativeToken.logoUrl')}
fontSize="14"
fontSize={14}
/>
</optional-inputs>
{#if error}
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/features/developer-tools.features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const developerToolsFeatures: IDeveloperFeatures = {
enabled: true,
},
mintNativeTokens: {
enabled: false,
enabled: true,
},
account: {
enabled: false,
Expand Down
8 changes: 4 additions & 4 deletions packages/desktop/views/dashboard/Dashboard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import { onDestroy, onMount } from 'svelte'
import Sidebar from './Sidebar.svelte'
import TopNavigation from './TopNavigation.svelte'
import {
addNftsToDownloadQueue,
downloadingNftId,
Expand All @@ -28,12 +27,11 @@
resetNftDownloadQueue,
selectedWalletNfts,
} from '@core/nfts'
import { selectedWalletId } from '@core/wallet'
import { clearBalanceSyncPoll, selectedWalletId, syncBalancePoll } from '@core/wallet'
import { get } from 'svelte/store'
import features from '@features/features'
import { isAwareOfMetricSystemDrop } from '@contexts/dashboard/stores'
import { isAwareOfMetricSystemDrop, showBalanceOverviewPopup } from '@contexts/dashboard/stores'
import { openPopup, PopupId } from '@auxiliary/popup'
import { showBalanceOverviewPopup } from '@contexts/dashboard/stores'
const tabs = {
wallet: Wallet,
Expand Down Expand Up @@ -83,6 +81,7 @@
}
onMount(() => {
syncBalancePoll($selectedWalletId, true)
Platform.onEvent('menu-logout', () => {
void logout()
})
Expand Down Expand Up @@ -126,6 +125,7 @@
})
onDestroy(() => {
clearBalanceSyncPoll()
Platform.DeepLinkManager.clearDeepLinkRequest()
Platform.removeListenersForEvent('deep-link-params')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,31 @@
ITransactionInfoToCalculateManaCost,
getManaBalance,
getPassiveManaForOutput,
DEFAULT_SECONDS_PER_SLOT,
} from '@core/network'
import { activeProfile } from '@core/profile'
import { implicitAccountCreationRouter } from '@core/router'
import { MILLISECONDS_PER_SECOND, SECONDS_PER_MINUTE, getBestTimeDuration } from '@core/utils'
import { IWalletState, formatTokenAmountBestMatch, selectedWallet, selectedWalletAssets } from '@core/wallet'
import { OutputData } from '@iota/sdk/out/types'
import { Button, FontWeight, KeyValueBox, Text, TextType, TextHint, TextHintVariant, CopyableBox } from '@ui'
import { onDestroy, onMount } from 'svelte'
export let outputId: string | undefined
// TODO: update when mana generation is available
const isLowManaGeneration = false
const LOW_MANA_GENERATION_SECONDS = 10 * SECONDS_PER_MINUTE
let walletAddress: string = ''
const transactionInfo: ITransactionInfoToCalculateManaCost = {}
let hasEnoughMana = false
let isLowManaGeneration = false
$: baseCoin = $selectedWalletAssets?.[$activeProfile?.network?.id]?.baseCoin
$: selectedOutput = getSelectedOutput($selectedWallet, outputId)
let totalAvailableMana: number
$: $selectedWallet, seconds, (totalAvailableMana = getTotalAvailableMana())
$: $selectedWallet, (totalAvailableMana = getTotalAvailableMana()), prepareTransaction(selectedOutput?.outputId)
let formattedSelectedOutputBlance: string
$: selectedOutput,
Expand All @@ -53,14 +56,14 @@
function getTotalAvailableMana(): number {
return (
getManaBalance($selectedWallet?.balances?.mana?.available) +
$selectedWallet?.balances.totalWalletBic -
getImplicitAccountsMana($selectedWallet?.implicitAccountOutputs, [outputId])
($selectedWallet?.balances.totalWalletBic ?? 0) -
getImplicitAccountsMana($selectedWallet?.implicitAccountOutputs, outputId ? [outputId] : [])
)
}
function getImplicitAccountsMana(implicitAccountOutputs: OutputData[], excludeIds: string[] | undefined): number {
function getImplicitAccountsMana(implicitAccountOutputs: OutputData[], excludeIds: string[]): number {
return implicitAccountOutputs?.reduce((acc: number, outputData: OutputData) => {
if (excludeIds && excludeIds.includes(outputData.outputId)) {
if (excludeIds.length > 1 && !excludeIds.includes(outputData.outputId)) {
const totalMana = getPassiveManaForOutput(outputData)
return totalMana ? acc + totalMana : acc
} else {
Expand All @@ -69,28 +72,40 @@
}, 0)
}
// TODO: Replace this with proper time remaining
async function prepareTransaction(outputId: string): Promise<void> {
if (!outputId) return
try {
transactionInfo.preparedTransaction = await $selectedWallet?.prepareImplicitAccountTransition(outputId)
seconds = 0 // If we don't get an error, it's because we can follow on to the next step
} catch (error) {
console.error(error.message)
if (error.message?.includes('slots remaining until enough mana')) {
transactionInfo.preparedTransactionError = error.message
const slotsRemaining = Number(error.message?.split(' ').reverse()[0].replace('`', ''))
seconds = slotsRemaining * DEFAULT_SECONDS_PER_SLOT
isLowManaGeneration = seconds >= LOW_MANA_GENERATION_SECONDS
}
}
}
// ----------------------------------------------------------------
let seconds: number = 10
let countdownInterval: NodeJS.Timeout
let timeRemaining: string
$: timeRemaining = `${seconds}s remaining`
$: timeRemaining = `${getBestTimeDuration(seconds * MILLISECONDS_PER_SECOND)} remaining`
onMount(async () => {
walletAddress = await $selectedWallet?.address()
$selectedWallet
.prepareImplicitAccountTransition(selectedOutput.outputId)
.then((prepareTx) => (transactionInfo.preparedTransaction = prepareTx))
.catch((error) => (transactionInfo.preparedTransactionError = error))
$selectedWallet?.address().then((address) => (walletAddress = address))
await prepareTransaction(selectedOutput.outputId)
if (seconds === 0) onTimeout()
countdownInterval = setInterval(() => {
seconds -= 1
if (seconds <= 0) {
clearInterval(countdownInterval)
onTimeout()
}
}, 1000)
}, MILLISECONDS_PER_SECOND)
})
onDestroy(() => {
Expand All @@ -103,10 +118,10 @@
// ----------------------------------------------------------------
</script>

<step-content class="flex flex-col items-center justify-between h-full pt-20">
<div class="flex flex-col h-full justify-between space-y-8 items-center">
<step-content class={`flex flex-col items-center justify-between h-full ${isLowManaGeneration ? 'pt-8' : 'pt-20'}`}>
<div class="flex flex-col h-full justify-between space-y-4 items-center">
<div class="flex flex-col text-center space-y-4 max-w-md">
<div class="flex items-center justify-center mb-7">
<div class={`flex items-center justify-center ${isLowManaGeneration ? 'mb-2' : 'mb-7'}`}>
<img
src="assets/illustrations/implicit-account-creation/step2.svg"
alt={localize('views.implicit-account-creation.steps.step2.title')}
Expand Down Expand Up @@ -140,7 +155,7 @@
</div>
</div>
{#if isLowManaGeneration}
<div class="flex flex-col space-y-4 w-2/3">
<div class="flex flex-col space-y-2 w-2/3">
<TextHint
variant={TextHintVariant.Warning}
text={localize('views.implicit-account-creation.steps.step2.view.walletAddress.description')}
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/components/inputs/AccountInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
let modal: Modal = undefined
const accountOptions: IOption[] =
$selectedWallet.balances?.accounts.map((hexAccountId: string, index: number) => {
const accountId = AddressConverter.addressToBech32(new AccountAddress(hexAccountId))
return { key: 'Account' + (index + 1), value: accountId }
$selectedWallet?.balances?.accounts.map((hexAccountId: string, index: number) => {
const accountAddress = AddressConverter.addressToBech32(new AccountAddress(hexAccountId))
return { key: 'Account ' + (index + 1), value: accountAddress }
}) ?? []
let selected: IOption = accountOptions.find((option) => option.value === account)
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/components/inputs/OptionalInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
export let label: string = ''
export let description: string = ''
export let value: string | undefined = undefined
export let value: string | number | undefined = undefined
export let fontSize: number = 15
export let error: string = ''
export let classes: string = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
activity.direction === ActivityDirection.SelfTransaction
? localize('general.internalTransaction')
: localize(isIncoming ? 'general.fromAddress' : 'general.toAddress', {
values: { account: getSubjectLocaleFromActivity(activity) },
values: { address: getSubjectLocaleFromActivity(activity) },
})
$: amount = getFormattedAmountFromActivity(activity)
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion packages/shared/lib/core/nfts/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ export * from './default-max-nft-downloading-time-in-seconds.constant'
export * from './default-max-nft-size-in-megabytes.constant'
export * from './nft-id-byte-length.constant'
export * from './nft-media-file-name.constant'
export * from './default-nft-feature-entry-key.constant'
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { plainToInstance } from 'class-transformer'
import { IWrappedOutput } from '../../wallet/interfaces'
import { DEFAULT_METADATA_FEATURE_ENTRY_KEY } from '../../wallet/constants'
import { buildNftFromNftOutput } from '../utils/buildNftFromNftOutput'
import {
AddressUnlockCondition,
Expand All @@ -10,7 +11,6 @@ import {
TimelockUnlockCondition,
} from '@iota/sdk/out/types'
import { Address, AddressType, NftOutput } from '@iota/sdk/out/types'
import { DEFAULT_NFT_FEATURE_ENTRY_KEY } from '../constants'

const accountAddress = 'rms1qr47ee0fhahukrzec088v9lngv7w5k2sn3jjtwvkcpjfgxhhsazlsurxrx9'

Expand All @@ -22,7 +22,7 @@ function buildImmutableFeatures() {
return [
new IssuerFeature(new Ed25519Address('0x20dceb927cfdc2cea642fbf77aed81f42400145b5a4fd906f1aa40af1c31afb1')),
new MetadataFeature({
[DEFAULT_NFT_FEATURE_ENTRY_KEY]:
[DEFAULT_METADATA_FEATURE_ENTRY_KEY]:
'0x7b227374616e64617264223a224952433237222c2276657273696f6e223a2276312e30222c226e616d65223a227364617364222c2274797065223a22696d6167652f706e67222c22757269223a2268747470733a2f2f697066732e696f2f697066732f516d51717a4d546176516754346634543576365057427037584e4b746f506d43396a766e313257505433676b5345227d',
}),
]
Expand Down
Loading

0 comments on commit dc45325

Please sign in to comment.