Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/service tab #630

Merged
merged 25 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
89a11b2
feat: info-service tab
RealGoodProgrammer May 29, 2024
833e831
fix: toggle active
RealGoodProgrammer May 29, 2024
167a3c3
Merge branch 'refs/heads/dev' into feat/service-tab
RealGoodProgrammer Jul 12, 2024
d532716
fix(RateInfoService.ts): incorrect label
RealGoodProgrammer Jul 12, 2024
c6eaf6e
fix: useFastest checkbox, refactoring (node kind)
RealGoodProgrammer Jul 12, 2024
b86f8a4
fix(NodesTableHead): label as a property
RealGoodProgrammer Jul 12, 2024
34f1ca6
fix(rate-actions): removed Promise wrapper
RealGoodProgrammer Jul 12, 2024
7bb6218
fix(rate-mutations): rename loadRates -> setLoaded
RealGoodProgrammer Jul 12, 2024
b1522d9
fix: rename 'rates-info' -> ratesInfo
RealGoodProgrammer Jul 13, 2024
70503a2
fix(nodes/storage): access of undefined value when switching from an …
bludnic Jul 13, 2024
8c9bf26
refactor(nodes/storage): reuse code
bludnic Jul 13, 2024
f7f3e61
fix(nodes/storage): modify only `useFastest` option
bludnic Jul 13, 2024
21e6312
refactor(NodesTable): move Service Nodes tab to the end
bludnic Jul 13, 2024
a6d15f2
refactor(NodesTable): shorter import
bludnic Jul 13, 2024
ec9c962
refactor(NodesTable): move npm packages imports at the top
bludnic Jul 13, 2024
3016de6
refactor(NodesTableHead.vue): remove unused `hideLabel` prop
bludnic Jul 13, 2024
c630080
fix: use relative import and extract RateInfoService types
PaulDremanovich Jul 14, 2024
6930f95
fix: refactor requests
PaulDremanovich Jul 14, 2024
0a61070
fix: active checkbox
PaulDremanovich Jul 14, 2024
f9f39ce
fix: relative imports
PaulDremanovich Jul 14, 2024
0731a50
feat: healthcheck for BtcNode. DogeNode doesn`t supported yet
PaulDremanovich Jul 15, 2024
1990e2d
fix: healthcheck for DogeNode. Refactoring
PaulDremanovich Jul 16, 2024
da7faba
feat: added btcIndexer, dogeIndexer, ethIndexer, klyIndexer in settin…
PaulDremanovich Jul 16, 2024
8a13693
Merge branch 'refs/heads/dev' into feat/service-tab
bludnic Aug 1, 2024
f9614c0
chore(nodes): move methods to indexers and add TS types
bludnic Aug 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions src/components/nodes/NodesTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
<v-tabs v-model="tab" bg-color="transparent">
<v-tab value="adm">{{ $t('nodes.tabs.adm_nodes') }}</v-tab>
<v-tab value="coins">{{ $t('nodes.tabs.coin_nodes') }}</v-tab>
<v-tab value="services">{{ $t('nodes.tabs.service_nodes') }}</v-tab>
</v-tabs>

<v-window v-model="tab">
<v-window-item value="adm">
<AdmNodesTable />
</v-window-item>

<v-window-item value="coins">
<CoinNodesTable />
</v-window-item>
<v-window-item value="services">
<ServiceNodesTable />
</v-window-item>
</v-window>
<div class="ml-6">
<div v-if="tab === 'coins'">
Expand All @@ -29,6 +32,20 @@
</div>
<div>&nbsp;<br />&nbsp;</div>
</div>
<div v-else-if="tab === 'services'">
<v-checkbox
v-model="preferFasterServiceNodeOption"
:label="$t('nodes.fastest_title')"
:class="classes.checkbox"
class="mt-4"
color="grey darken-1"
hide-details
/>
<div class="a-text-explanation-enlarged">
{{ $t('nodes.fastest_tooltip') }}
</div>
<div>&nbsp;<br />&nbsp;</div>
</div>
<div v-else-if="tab === 'adm'">
<v-checkbox
v-model="preferFastestAdmNodeOption"
Expand Down Expand Up @@ -69,9 +86,11 @@

<script lang="ts">
import { defineComponent, ref, computed } from 'vue'
import { useStore } from 'vuex'

import { AdmNodesTable } from './adm'
import { CoinNodesTable } from './coins'
import { useStore } from 'vuex'
import { ServiceNodesTable } from './services'

const className = 'nodes-table'
const classes = {
Expand All @@ -80,10 +99,11 @@ const classes = {
checkbox: `${className}__checkbox`
}

type Tab = 'adm' | 'coins'
type Tab = 'adm' | 'coins' | 'services'

export default defineComponent({
components: {
ServiceNodesTable,
AdmNodesTable,
CoinNodesTable
},
Expand Down Expand Up @@ -120,12 +140,22 @@ export default defineComponent({
}
})

const preferFasterServiceNodeOption = computed<boolean>({
get() {
return store.state.services.useFastestService
},
set(value) {
store.dispatch('services/useFastestService', value)
}
})

return {
tab,
classes,
useSocketConnection,
preferFastestAdmNodeOption,
preferFastestCoinNodeOption
preferFastestCoinNodeOption,
preferFasterServiceNodeOption
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/components/nodes/adm/AdmNodesTable.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<NodesTableContainer>
<NodesTableHead hide-label />
<NodesTableHead />

<tbody>
<AdmNodesTableItem v-for="node in admNodes" :key="node.url" blockchain="adm" :node="node" />
Expand Down
2 changes: 1 addition & 1 deletion src/components/nodes/coins/CoinNodesTable.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<NodesTableContainer>
<NodesTableHead hide-socket />
<NodesTableHead hide-socket :label="$t('nodes.coin')" />

<tbody>
<CoinNodesTableItem v-for="node in nodes" :key="node.url" :label="node.label" :node="node" />
Expand Down
10 changes: 6 additions & 4 deletions src/components/nodes/components/NodesTableHead.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<thead :class="classes.root">
<tr>
<th :class="classes.checkbox" v-if="!hideCheckbox" />
<th :class="classes.label" class="pl-0 pr-2" v-if="!hideLabel">{{ t('nodes.coin') }}</th>
<th :class="classes.label" class="pl-0 pr-2" v-if="label">
{{ label }}
</th>
<th :class="classes.th" class="pl-0 pr-2" v-if="!hideHost">
{{ t('nodes.host') }}
</th>
Expand All @@ -24,9 +26,6 @@ export default {
hideCheckbox: {
type: Boolean
},
hideLabel: {
type: Boolean
},
hideHost: {
type: Boolean
},
Expand All @@ -35,6 +34,9 @@ export default {
},
hideSocket: {
type: Boolean
},
label: {
type: String
}
},
setup() {
Expand Down
53 changes: 53 additions & 0 deletions src/components/nodes/services/ServiceNodesTable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<template>
<NodesTableContainer>
<NodesTableHead hide-socket :label="$t('nodes.service')" />

<tbody>
<ServiceNodesTableItem
v-for="node in nodes"
:key="node.url"
:label="node.label"
:node="node"
/>
</tbody>
</NodesTableContainer>
</template>

<script lang="ts">
import { computed, defineComponent } from 'vue'
import { useStore } from 'vuex'
import NodesTableContainer from '@/components/nodes/components/NodesTableContainer.vue'
import NodesTableHead from '@/components/nodes/components/NodesTableHead.vue'
import ServiceNodesTableItem from './ServiceNodesTableItem.vue'
import { type NodeStatusResult } from '@/lib/nodes/abstract.node'
import { sortNodesFn } from '@/components/nodes/utils/sortNodesFn'

const className = 'nodes-table'
const classes = {
root: className
}

export default defineComponent({
components: {
NodesTableContainer,
NodesTableHead,
ServiceNodesTableItem
},
setup() {
const store = useStore()

const nodes = computed<NodeStatusResult[]>(() => {
const arr = store.getters['services/services']

return [...arr].sort(sortNodesFn)
})

return {
nodes,
classes
}
}
})
</script>

<style lang="scss" scoped></style>
92 changes: 92 additions & 0 deletions src/components/nodes/services/ServiceNodesTableItem.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<template>
<tr :class="classes.root">
<NodeColumn checkbox>
<NodeStatusCheckbox :value="active" @change="toggleActiveStatus" />
</NodeColumn>

<NodeColumn align="left">
<NodeLabel :label="label" />
</NodeColumn>

<NodeColumn>
<NodeUrl :node="node" />
</NodeColumn>

<NodeColumn ping :colspan="isUnsupported ? 2 : 1">
<NodeStatus :node="node" />
</NodeColumn>
</tr>
</template>

<script lang="ts">
import { computed, PropType } from 'vue'
import { useStore } from 'vuex'
import type { NodeStatusResult } from '@/lib/nodes/abstract.node'
import type { TNodeLabel } from '@/lib/nodes/constants'
import NodeUrl from '@/components/nodes/components/NodeUrl.vue'
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'

const className = 'nodes-table-item'
const classes = {
root: className,
column: `${className}__column`,
columnCheckbox: `${className}__column--checkbox`,
checkbox: `${className}__checkbox`
}

export default {
components: {
NodeColumn,
NodeStatus,
NodeLabel,
NodeUrl,
NodeStatusCheckbox
},
props: {
node: {
type: Object as PropType<NodeStatusResult>,
required: true
},
label: {
type: String as PropType<TNodeLabel>,
required: true
}
},
setup(props) {
const store = useStore()

const url = computed(() => props.node.url)
const active = computed(() => props.node.active)
const isUnsupported = computed(() => props.node.status === 'unsupported_version')
const type = computed(() => props.node.label)

const toggleActiveStatus = () => {
store.dispatch('services/toggle', {
type: type.value,
url: url.value,
active: !active.value
})
store.dispatch('services/updateStatus')
}

return {
classes,
url,
active,
isUnsupported,
toggleActiveStatus
}
}
}
</script>

<style lang="scss">
.nodes-table-item {
}

.nodeName {
}
</style>
1 change: 1 addition & 0 deletions src/components/nodes/services/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as ServiceNodesTable } from './ServiceNodesTable.vue'
4 changes: 2 additions & 2 deletions src/hooks/queries/transaction/useBtcTransactionQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MaybeRef, unref } from 'vue'
import { useStore } from 'vuex'
import { useQuery } from '@tanstack/vue-query'
import { Cryptos } from '@/lib/constants'
import { btc } from '@/lib/nodes'
import { btcIndexer } from '@/lib/nodes'
import { BtcTransaction } from '@/lib/nodes/types/transaction'
import { PendingTransaction, PendingTxStore } from '@/lib/pending-transactions'
import { refetchIntervalFactory, refetchOnMountFn, retryDelayFactory, retryFactory } from './utils'
Expand All @@ -20,7 +20,7 @@ export function useBtcTransactionQuery(

return useQuery<BtcTransaction | PendingTransaction>({
queryKey: ['transaction', Cryptos.BTC, transactionId],
queryFn: () => btc.getTransaction(unref(transactionId), store.state.btc.address),
queryFn: () => btcIndexer.getTransaction(unref(transactionId), store.state.btc.address),
initialData: () => {
const pendingTransaction = PendingTxStore.get(Cryptos.BTC)
if (pendingTransaction?.id === unref(transactionId)) {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/queries/transaction/useDogeTransactionQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MaybeRef, unref } from 'vue'
import { useStore } from 'vuex'
import { useQuery } from '@tanstack/vue-query'
import { Cryptos } from '@/lib/constants'
import { doge } from '@/lib/nodes'
import { dogeIndexer } from '@/lib/nodes'
import { DogeTransaction } from '@/lib/nodes/types/transaction'
import { PendingTransaction, PendingTxStore } from '@/lib/pending-transactions'
import { refetchIntervalFactory, refetchOnMountFn, retryDelayFactory, retryFactory } from './utils'
Expand All @@ -20,7 +20,7 @@ export function useDogeTransactionQuery(

return useQuery<DogeTransaction | PendingTransaction>({
queryKey: ['transaction', Cryptos.DOGE, transactionId],
queryFn: () => doge.getTransaction(unref(transactionId), store.state.doge.address),
queryFn: () => dogeIndexer.getTransaction(unref(transactionId), store.state.doge.address),
initialData: () => {
const pendingTransaction = PendingTxStore.get(Cryptos.DOGE)
if (pendingTransaction?.id === unref(transactionId)) {
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/queries/useBlockHeight.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { computed, MaybeRef, unref } from 'vue'
import { useQuery } from '@tanstack/vue-query'
import { getTxFetchInfo } from '@/lib/transactionsFetching'
import { adm, btc, dash, doge, eth, kly } from '@/lib/nodes'
import { adm, btcIndexer, dash, dogeIndexer, eth, kly } from '@/lib/nodes'

type Chain = 'ADM' | 'BTC' | 'DOGE' | 'DASH' | 'ETH' | 'KLY'

Expand All @@ -10,9 +10,9 @@ const fetchBlockHeight = async (chain: Chain): Promise<number> => {
case 'ADM':
return adm.getHeight()
case 'BTC':
return btc.getHeight()
return btcIndexer.getHeight()
case 'DOGE':
return doge.getHeight()
return dogeIndexer.getHeight()
case 'DASH':
return dash.getHeight()
case 'ETH':
Expand Down
10 changes: 7 additions & 3 deletions src/lib/bitcoin/bitcoin-api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BtcBaseApi from './btc-base-api'
import { Cryptos } from '../constants'
import { btc } from '@/lib/nodes/btc'
import { btcIndexer } from '../../lib/nodes'

export default class BitcoinApi extends BtcBaseApi {
constructor(passphrase) {
Expand Down Expand Up @@ -28,7 +28,9 @@ export default class BitcoinApi extends BtcBaseApi {

/** @override */
sendTransaction(txHex) {
return btc.useClient((client) => client.post('/tx', txHex)).then((response) => response.data)
return btcIndexer
.useClient((client) => client.post('/tx', txHex))
.then((response) => response.data)
}

/** @override */
Expand Down Expand Up @@ -84,6 +86,8 @@ export default class BitcoinApi extends BtcBaseApi {

/** Executes a GET request to the API */
_get(url, params) {
return btc.useClient((client) => client.get(url, { params })).then((response) => response.data)
return btcIndexer
.useClient((client) => client.get(url, { params }))
.then((response) => response.data)
}
}
8 changes: 5 additions & 3 deletions src/lib/bitcoin/doge-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { isPositiveNumber } from '../numericHelpers'
import { ECPairFactory } from 'ecpair'
import * as tinysecp from 'tiny-secp256k1'
import { convertToSmallestUnit } from './bitcoin-utils'
import { doge } from '@/lib/nodes/doge'
import { dogeIndexer } from '../../lib/nodes'

const ECPairAPI = ECPairFactory(tinysecp)

Expand Down Expand Up @@ -150,12 +150,14 @@ export default class DogeApi extends BtcBaseApi {

/** Executes a GET request to the DOGE API */
_get(url, params) {
return doge.useClient((client) => client.get(url, { params })).then((response) => response.data)
return dogeIndexer
.useClient((client) => client.get(url, { params }))
.then((response) => response.data)
}

/** Executes a POST request to the DOGE API */
_post(url, data) {
return doge
return dogeIndexer
.useClient((client) => client.post(url, qs.stringify(data), POST_CONFIG))
.then((response) => response.data)
}
Expand Down
Loading