Skip to content

Commit

Permalink
Merge pull request #661 from Adamant-im/fix/service-nodes-tab
Browse files Browse the repository at this point in the history
Fix: service nodes tab
  • Loading branch information
bludnic authored Aug 16, 2024
2 parents 43dd79f + 48d9f57 commit 3130cb7
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/components/SendFundsForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
<script>
import { adm } from '@/lib/nodes'
import klyIndexer from '@/lib/nodes/kly-indexer'
import { AllNodesOfflineError } from '@/lib/nodes/utils/errors'
import { AllNodesDisabledError, AllNodesOfflineError } from '@/lib/nodes/utils/errors'
import { PendingTransactionError } from '@/lib/pending-transactions'
import axios from 'axios'
import { nextTick } from 'vue'
Expand Down Expand Up @@ -755,6 +755,10 @@ export default {
message = this.$t('errors.all_nodes_offline', {
crypto: error.nodeLabel.toUpperCase()
})
} else if (error instanceof AllNodesDisabledError) {
message = this.$t('errors.all_nodes_disabled', {
crypto: error.nodeLabel.toUpperCase()
})
} else if (error instanceof PendingTransactionError) {
message = this.$t('transfer.error_pending_transaction', {
crypto: error.crypto
Expand Down
9 changes: 6 additions & 3 deletions src/components/nodes/hooks/useNodeStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ function getNodeStatusTitle(node: NodeStatusResult, t: VueI18nTranslation) {
sync: 'nodes.sync',
unsupported_version: 'nodes.unsupported'
}
const i18nKey = i18n[node.status]

return t(i18nKey)
if (node.status === 'online') {
return i18n[node.status]
} else {
const i18nKey = i18n[node.status]
return t(i18nKey)
}
}

function getNodeStatusDetail(
Expand Down
3 changes: 3 additions & 0 deletions src/components/nodes/services/ServiceNodesTableItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<NodeColumn>
<NodeUrl :node="node" />
<NodeVersion v-if="node.version && active" :node="node" />
</NodeColumn>

<NodeColumn ping :colspan="isUnsupported ? 2 : 1">
Expand All @@ -28,6 +29,7 @@ import NodeColumn from '@/components/nodes/components/NodeColumn.vue'
import NodeLabel from '@/components/nodes/components/NodeLabel.vue'
import NodeStatus from '@/components/nodes/components/NodeStatus.vue'
import NodeStatusCheckbox from '@/components/nodes/components/NodeStatusCheckbox.vue'
import NodeVersion from '@/components/nodes/components/NodeVersion.vue'
const className = 'nodes-table-item'
const classes = {
Expand All @@ -39,6 +41,7 @@ const classes = {
export default {
components: {
NodeVersion,
NodeColumn,
NodeStatus,
NodeLabel,
Expand Down
3 changes: 2 additions & 1 deletion src/lib/nodes/eth-indexer/EthIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ export class EthIndexer extends Node<AxiosInstance> {
}

private async fetchServiceInfo(): Promise<{ height: number }> {
const [{ max }] = await this.request('GET /max_block')
const [{ max, version }] = await this.request('GET /max_block')
this.height = max
this.version = version

return {
height: this.height
Expand Down
1 change: 1 addition & 0 deletions src/lib/nodes/eth-indexer/types/api/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type Endpoints = {
result: [
{
max: number
version: string
}
]
}
Expand Down
4 changes: 3 additions & 1 deletion src/lib/nodes/rate-info-service/RateInfoService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { NODE_LABELS } from '@/lib/nodes/constants'
import { RateInfoResponse } from '@/lib/nodes/rate-info-service/types/RateInfoResponse'
import { RateHistoryInfoResponse } from '@/lib/nodes/rate-info-service/types/RateHistoryInfoResponse'
import { GetHistoryParams } from '@/lib/nodes/rate-info-service/types/GetHistoryParams'
import { normalizeHeight } from './utils'

export class RateInfoService extends Node<AxiosInstance> {
constructor(url: string) {
Expand All @@ -31,9 +32,10 @@ export class RateInfoService extends Node<AxiosInstance> {
protected async checkHealth(): Promise<HealthcheckResult> {
const start = Date.now()
const response = await this.getAllRates()
this.height = normalizeHeight(response.date)
return {
ping: Date.now() - start,
height: response.date
height: this.height
}
}
}
14 changes: 14 additions & 0 deletions src/lib/nodes/rate-info-service/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Normalize the height to 8 digits.
* Rounds the timestamp to seconds and removes the first two digits.
* @param timestamp Timestamp in milliseconds
*/
export const normalizeHeight = (timestamp: number) => {
if (!timestamp) return 0

return Number(
Math.ceil(timestamp / 1000)
.toString()
.substring(2)
)
}
6 changes: 3 additions & 3 deletions src/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@
"service": "Сервис",
"socket": "Сокеты",
"tabs": {
"adm_nodes": "ADM ноды",
"coin_nodes": "Coin ноды",
"service_nodes": "Сервис ноды"
"adm_nodes": "Узлы ADM",
"coin_nodes": "Крипто-ноды",
"service_nodes": "Крипто-сервисы"
},
"unsupported": "Не поддерживается",
"unsupported_reason_protocol": "HTTP не поддерживается",
Expand Down
13 changes: 12 additions & 1 deletion src/views/Transactions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import AppToolbarCentered from '@/components/AppToolbarCentered.vue'
import InlineSpinner from '@/components/InlineSpinner.vue'
import TransactionListItem from '@/components/TransactionListItem.vue'
import { isStringEqualCI } from '@/lib/textHelpers'
import { AllNodesDisabledError, AllNodesOfflineError } from '@/lib/nodes/utils/errors'
export default {
components: {
Expand Down Expand Up @@ -183,8 +184,18 @@ export default {
})
.catch((err) => {
this.isRejected = true
let message = err.message
if (err instanceof AllNodesOfflineError) {
message = this.$t('errors.all_nodes_offline', {
crypto: err.nodeLabel.toUpperCase()
})
} else if (err instanceof AllNodesDisabledError) {
message = this.$t('errors.all_nodes_disabled', {
crypto: err.nodeLabel.toUpperCase()
})
}
this.$store.dispatch('snackbar/show', {
message: err.message
message: message
})
})
}
Expand Down

0 comments on commit 3130cb7

Please sign in to comment.