Skip to content

Commit

Permalink
Merge branch 'develop-iota2.0' of github.com:iotaledger/firefly into …
Browse files Browse the repository at this point in the history
…feat/add-mana-cost-everywhere
  • Loading branch information
cpl121 committed Mar 21, 2024
2 parents e4000d1 + 3a9283a commit 2f4d16f
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 37 deletions.
53 changes: 30 additions & 23 deletions packages/desktop/components/popups/NodeInfoPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import { onMount } from 'svelte'
import { Button, Checkbox, CopyableBox, Spinner, Text } from '@ui'
import { formatNumber, localize } from '@core/i18n'
import { INode } from '@core/network'
import { INode, INodeInfoResponse } from '@core/network'
import { closePopup } from '@auxiliary/popup'
import { showAppNotification } from '@auxiliary/notification'
import { resolveObjectPath, setClipboard } from '@core/utils'
import { INodeInfo } from '@iota/sdk/out/types'
import { getNodeInfo } from '@core/wallet/actions'
import { NetworkMetricsResponse } from '@iota/sdk/out/types'
import { getNetworkMetrics, getNodeInfo } from '@core/wallet'
enum NodeInfoTab {
General = 'general',
Expand All @@ -31,17 +31,12 @@
// features: { localeKey: 'general.features', nodeInfoPath: 'features' },
},
[NodeInfoTab.Metrics]: {
blocksPerSecond: { localeKey: 'metrics.blocksPerSecond', nodeInfoPath: 'metrics.blocksPerSecond' },
blocksPerSecond: { localeKey: 'metrics.blocksPerSecond', nodeInfoPath: 'blocksPerSecond' },
confirmedBlocksPerSecond: {
localeKey: 'metrics.confirmedBlocksPerSecond',
nodeInfoPath: 'metrics.confirmedBlocksPerSecond',
nodeInfoPath: 'confirmedBlocksPerSecond',
},
confirmationRate: { localeKey: 'metrics.confirmationRate', nodeInfoPath: 'metrics.confirmationRate' },
// latestSlot: { localeKey: 'metrics.latestSlot', nodeInfoPath: 'status.latestSlot.index' },
// confirmedSlot: {
// localeKey: 'metrics.confirmedSlot',
// nodeInfoPath: 'status.confirmedSlot.index',
// },
confirmationRate: { localeKey: 'metrics.confirmationRate', nodeInfoPath: 'confirmationRate' },
},
[NodeInfoTab.Protocol]: {
network: { localeKey: 'protocol.network', nodeInfoPath: 'protocolParameters[0].parameters.networkName' },
Expand Down Expand Up @@ -69,7 +64,8 @@
},
}
let nodeInfo: INodeInfo
let nodeInfo: INodeInfoResponse
let networkMetrics: NetworkMetricsResponse
function processNodeInfoMapTab(
_nodeInfoTab: NodeInfoTab,
Expand All @@ -80,20 +76,20 @@
let nodeInfoValue = ''
if (key === 'url') {
nodeInfoValue = node.url
} else {
nodeInfoValue = resolveObjectPath(nodeInfo, nodeInfoTabObject[key]?.nodeInfoPath, null)
if (key === 'confirmationRate' || key === 'blocksPerSecond' || key === 'confirmedBlocksPerSecond') {
const numberValue = Number(nodeInfoValue)
if (numberValue >= 0) {
if (key === 'confirmationRate') {
nodeInfoValue = `${formatNumber(Math.min(numberValue, 100), 1, 1)}%`
} else {
nodeInfoValue = formatNumber(numberValue, 1, 1)
}
} else if (_nodeInfoTab === NodeInfoTab.Metrics) {
nodeInfoValue = resolveObjectPath(networkMetrics, nodeInfoTabObject[key]?.nodeInfoPath, null)
const numberValue = Number(nodeInfoValue)
if (numberValue >= 0) {
if (key === 'confirmationRate') {
nodeInfoValue = `${formatNumber(Math.min(numberValue, 100), 1, 1)}%`
} else {
nodeInfoValue = ''
nodeInfoValue = formatNumber(numberValue, 1, 1)
}
} else {
nodeInfoValue = ''
}
} else {
nodeInfoValue = resolveObjectPath(nodeInfo, nodeInfoTabObject[key]?.nodeInfoPath, null)
}
return {
Expand Down Expand Up @@ -124,6 +120,17 @@
message: localize(err.error),
})
})
getNetworkMetrics()
.then((networkMetricsResponse) => {
networkMetrics = networkMetricsResponse
})
.catch((err) => {
closePopup()
showAppNotification({
type: 'error',
message: localize(err.error),
})
})
})
</script>

Expand Down
33 changes: 27 additions & 6 deletions packages/desktop/views/dashboard/delegation/Delegation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ButtonSize,
CopyableBox,
BoxedIconWithText,
PingingBadge,
TextHintVariant,
} from '@ui'
import { activeProfile, checkActiveProfileAuth } from '@core/profile'
Expand All @@ -35,6 +36,7 @@
let delegationData: IDelegationTable[] = []
let currentEpoch = 0
let committeeAddresses: string[] = []
enum Header {
DelegationId = 'delegationId',
Expand All @@ -56,7 +58,7 @@
$: delegationOutputs =
$selectedWallet?.walletUnspentOutputs?.filter((output) => output?.output?.type === OutputType.Delegation) || []
$: delegationOutputs?.length > 0 && setCurrentEpoch()
$: delegationOutputs?.length > 0 && setCurrentEpochAndCommittee()
$: delegationOutputs?.length > 0 && currentEpoch && buildMappedDelegationData(delegationOutputs)
$: ({ baseCoin } = $selectedWalletAssets[$activeProfile?.network.id])
Expand Down Expand Up @@ -92,9 +94,10 @@
delegationData = await Promise.all(result)
}
async function setCurrentEpoch(): Promise<void> {
const committee = await getCommitteeInfo()
currentEpoch = committee.epoch
async function setCurrentEpochAndCommittee(): Promise<void> {
const committeeResponse = await getCommitteeInfo()
currentEpoch = committeeResponse?.epoch
committeeAddresses = committeeResponse?.committee?.map((committee) => committee.address) || []
}
function handleDelegate(): void {
Expand Down Expand Up @@ -126,7 +129,7 @@
})
}
function renderCellValue(value: any, header: string): { component: any; props: any; text?: string } {
function renderCellValue(value: any, header: string): { component: any; props: any; text?: string; slot?: any } {
switch (header as Header) {
case Header.DelegationId:
return {
Expand Down Expand Up @@ -180,7 +183,19 @@
isCopyable: true,
clearBoxPadding: true,
clearBackground: true,
classes: 'text-gray-600 dark:text-white text-xs font-medium',
classes: 'flex flex-row items-center text-gray-600 dark:text-white text-xs font-medium gap-2',
},
slot: {
component: PingingBadge,
props: {
classes: 'relative',
innerColor: committeeAddresses?.some((address) => address === value)
? 'green-600'
: 'red-500',
outerColor: committeeAddresses?.some((address) => address === value)
? 'green-400'
: 'red-300',
},
},
text: truncateString(value, 5, 5, 3),
}
Expand Down Expand Up @@ -262,6 +277,12 @@
<td class="text-start flex-1">
{#if renderCell.text}
<svelte:component this={renderCell.component} {...renderCell.props}>
{#if renderCell.slot}
<svelte:component
this={renderCell.slot.component}
{...renderCell.slot.props}
/>
{/if}
{renderCell.text}
</svelte:component>
{:else}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { getNetworkMetrics } from '@core/wallet/actions'
import { NetworkMetricsResponse } from '@iota/sdk'
import { setNetworkMetrics } from '../stores'

export async function getAndUpdateNetworkMetrics(forwardErrors = false): Promise<NetworkMetricsResponse | undefined> {
let networkMetricsResponse: NetworkMetricsResponse
try {
networkMetricsResponse = await getNetworkMetrics()
setNetworkMetrics(networkMetricsResponse)
return networkMetricsResponse
} catch (err) {
setNetworkMetrics(undefined)
if (forwardErrors) {
return Promise.reject(err)
} else {
console.error(err)
}
}
}
1 change: 1 addition & 0 deletions packages/shared/lib/core/network/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './showNetworkIssueNotification'
export * from './toggleDisabledNodeInClientOptions'
export * from './togglePrimaryNodeInClientOptions'
export * from './updateClientOptions'
export * from './getAndUpdateNetworkMetrics'
7 changes: 6 additions & 1 deletion packages/shared/lib/core/network/actions/network-polling.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NETWORK_STATUS_POLL_INTERVAL } from '../constants'
import { getAndUpdateNetworkMetrics } from './getAndUpdateNetworkMetrics'
import { getAndUpdateNodeInfo } from './getAndUpdateNodeInfo'

let pollInterval: number
Expand All @@ -8,7 +9,11 @@ let pollInterval: number
*/
export async function pollNetworkStatus(): Promise<void> {
await getAndUpdateNodeInfo()
pollInterval = window.setInterval(() => void getAndUpdateNodeInfo(), NETWORK_STATUS_POLL_INTERVAL)
await getAndUpdateNetworkMetrics()
pollInterval = window.setInterval(() => {
getAndUpdateNodeInfo()
getAndUpdateNetworkMetrics()
}, NETWORK_STATUS_POLL_INTERVAL)
}

export function clearNetworkPoll(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MILLISECONDS_PER_SECOND, SECONDS_PER_MINUTE } from '@core/utils'
import { NetworkHealth } from '../enums'
import { INetworkStatus } from '../interfaces'
import { INodeInfo } from '@iota/sdk/out/types'
import { INodeInfo, NetworkMetricsResponse } from '@iota/sdk/out/types'
import { getUnixTimestampFromNodeInfoAndSlotIndex } from './getSlotInfoFromNodeProtocolParameters'

/**
Expand All @@ -11,7 +11,10 @@ import { getUnixTimestampFromNodeInfoAndSlotIndex } from './getSlotInfoFromNodeP
* @param {IStardustNodeInfo} nodeInfo
* @returns {INetworkStatus}
*/
export function getNetworkStatusFromNodeInfo(nodeInfo: INodeInfo): INetworkStatus {
export function getNetworkStatusFromNodeInfo(
nodeInfo: INodeInfo,
networkMetrics: NetworkMetricsResponse
): INetworkStatus {
let health = NetworkHealth.Down
const unixTimestamp = getUnixTimestampFromNodeInfoAndSlotIndex(
nodeInfo.protocolParameters[0].parameters,
Expand All @@ -31,8 +34,8 @@ export function getNetworkStatusFromNodeInfo(nodeInfo: INodeInfo): INetworkStatu
}

return {
messagesPerSecond: nodeInfo.metrics.blocksPerSecond,
confirmationRate: nodeInfo.metrics.confirmationRate,
messagesPerSecond: networkMetrics.blocksPerSecond,
confirmationRate: networkMetrics.confirmationRate,
health,
currentSlot: nodeInfo.status.latestConfirmedBlockSlot,
}
Expand Down
1 change: 1 addition & 0 deletions packages/shared/lib/core/network/stores/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './network-status.store'
export * from './node-info.store'
export * from './network-metrics.store'
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NetworkMetricsResponse } from '@iota/sdk/out/types'
import { writable } from 'svelte/store'

export const networkMetrics = writable<NetworkMetricsResponse | undefined>(undefined)

export function setNetworkMetrics(newNetworkMetrics: NetworkMetricsResponse | undefined): void {
return networkMetrics.set(newNetworkMetrics)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { SLOT_NOT_FOUND } from '../constants'
import { NetworkHealth } from '../enums/network-health.enum'
import { getNetworkStatusFromNodeInfo } from '../helpers'
import { nodeInfo } from './node-info.store'
import { networkMetrics } from './network-metrics.store'

export const networkStatus = derived([nodeInfo], ([$nodeInfo]) => {
if ($nodeInfo) {
return getNetworkStatusFromNodeInfo($nodeInfo)
export const networkStatus = derived([nodeInfo, networkMetrics], ([$nodeInfo, $networkMetrics]) => {
if ($nodeInfo && $networkMetrics) {
return getNetworkStatusFromNodeInfo($nodeInfo, $networkMetrics)
} else {
return {
messagesPerSecond: 0,
Expand Down
7 changes: 7 additions & 0 deletions packages/shared/lib/core/wallet/actions/getNetworkMetrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NetworkMetricsResponse } from '@iota/sdk/out/types'
import { getClient } from './getClient'

export async function getNetworkMetrics(): Promise<NetworkMetricsResponse> {
const client = await getClient()
return client.getNetworkMetrics()
}
1 change: 1 addition & 0 deletions packages/shared/lib/core/wallet/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ export * from './getOutputRewards'
export * from './getCommitteInfo'
export * from './prepareMintNft'
export * from './prepareCreateNativeToken'
export * from './getNetworkMetrics'
export * from './getTotalWalletBalance'

0 comments on commit 2f4d16f

Please sign in to comment.