Skip to content

Commit

Permalink
Merge branch 'refs/heads/dev' into feat/animate-all-incoming-reactions
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/store/modules/chat/index.js
  • Loading branch information
bludnic committed Aug 29, 2024
2 parents e0a8fdb + 80ba3d8 commit 997e749
Show file tree
Hide file tree
Showing 25 changed files with 148 additions and 118 deletions.
12 changes: 7 additions & 5 deletions src/components/LoginForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<script>
import { validateMnemonic } from 'bip39'
import { computed, ref, defineComponent } from 'vue'
import { useI18n } from 'vue-i18n'
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
import { isAxiosError } from 'axios'
Expand All @@ -70,6 +71,7 @@ export default defineComponent({
setup(props, { emit }) {
const router = useRouter()
const store = useStore()
const { t } = useI18n()
const showSpinner = ref(false)
const showPassphrase = ref(false)
Expand All @@ -88,7 +90,7 @@ export default defineComponent({
const submit = () => {
if (!validateMnemonic(passphrase.value)) {
return emit('error', 'login.invalid_passphrase')
return emit('error', t('login.invalid_passphrase'))
}
freeze()
Expand All @@ -103,14 +105,14 @@ export default defineComponent({
})
.catch((err) => {
if (isAxiosError(err)) {
emit('error', 'login.invalid_passphrase')
emit('error', t('login.invalid_passphrase'))
} else if (isAllNodesOfflineError(err)) {
emit('error', 'errors.all_nodes_offline')
emit('error', t('errors.all_nodes_offline', { crypto: err.nodeLabel.toUpperCase() }))
} else if (isAllNodesDisabledError(err)) {
emit('error', 'errors.all_nodes_disabled')
emit('error', t('errors.all_nodes_disabled', { crypto: err.nodeLabel.toUpperCase() }))
router.push({ name: 'Nodes' })
} else {
emit('error', 'errors.something_went_wrong')
emit('error', t('errors.something_went_wrong'))
}
console.log(err)
})
Expand Down
48 changes: 11 additions & 37 deletions src/components/NodesOfflineDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<v-dialog v-model="showDialog" width="500" :class="className">
<v-card>
<v-card-title class="a-text-header">
{{ t('chats.nodes_offline_dialog.title') }}
{{ t('chats.nodes_offline_dialog.title', { coin: nodeType.toUpperCase() }) }}
</v-card-title>

<v-divider class="a-divider" />
Expand All @@ -16,6 +16,7 @@

<v-col cols="12" :class="[`${className}__btn-block`, 'text-center']">
<v-btn
@click="showDialog = false"
:class="[`${className}__btn-free-tokens`, 'a-btn-primary']"
to="/options/nodes"
variant="text"
Expand All @@ -31,11 +32,10 @@
</template>

<script lang="ts">
import { NodeStatusResult } from '@/lib/nodes/abstract.node'
import { computed, PropType, ref, watch } from 'vue'
import { NodeType } from '@/lib/nodes/types'
import { computed, PropType } from 'vue'
import { useI18n } from 'vue-i18n'
import { useStore } from 'vuex'
import { NodeType } from '@/lib/nodes/types'
const className = 'all-nodes-disabled-dialog'
const classes = {
Expand All @@ -54,44 +54,18 @@ export default {
const { t } = useI18n()
const store = useStore()
const showDialog = ref(false)
const nodes = computed<NodeStatusResult[]>(() => store.getters['nodes/adm'])
const isOnline = computed<boolean>(() => store.getters['isOnline'])
const className = 'nodes-offline-dialog'
const offlineNodesStatus = computed(() => {
return {
allOffline: nodes.value.every(
(node) =>
!(
node.online &&
node.active &&
!node.outOfSync &&
node.hasMinNodeVersion &&
node.hasSupportedProtocol
)
),
hasDisabled: nodes.value.some((node) => !node.active)
}
})
watch(
offlineNodesStatus,
(value) => {
showDialog.value = value.allOffline && value.hasDisabled && isOnline.value
const showDialog = computed({
get() {
return store.state.chat.noActiveNodesDialog
},
{
deep: true,
immediate: true
set() {
store.commit('chat/setNoActiveNodesDialog', false)
}
)
})
return {
t,
nodes,
classes,
offlineNodesStatus,
showDialog,
className
}
Expand All @@ -117,7 +91,7 @@ export default {
margin-right: 8px;
}
&__btn-block {
padding: 0 0 30px 0;
padding: 16px 0 32px 0;
text-align: center;
}
}
Expand Down
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
4 changes: 2 additions & 2 deletions src/components/nodes/coins/CoinNodesTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import NodesTableContainer from '@/components/nodes/components/NodesTableContain
import NodesTableHead from '@/components/nodes/components/NodesTableHead.vue'
import CoinNodesTableItem from './CoinNodesTableItem.vue'
import { type NodeStatusResult } from '@/lib/nodes/abstract.node'
import { sortNodesFn } from '@/components/nodes/utils/sortNodesFn'
import { sortCoinNodesFn } from '@/components/nodes/utils/sortNodesFn'
const className = 'nodes-table'
const classes = {
Expand All @@ -34,7 +34,7 @@ export default defineComponent({
const nodes = computed<NodeStatusResult[]>(() => {
const arr = store.getters['nodes/coins']
return [...arr].sort(sortNodesFn)
return [...arr].sort(sortCoinNodesFn)
})
return {
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
4 changes: 2 additions & 2 deletions src/components/nodes/services/ServiceNodesTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import NodesTableContainer from '@/components/nodes/components/NodesTableContain
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'
import { sortCoinNodesFn } from '@/components/nodes/utils/sortNodesFn'
const className = 'nodes-table'
const classes = {
Expand All @@ -39,7 +39,7 @@ export default defineComponent({
const nodes = computed<NodeStatusResult[]>(() => {
const arr = store.getters['services/services']
return [...arr].sort(sortNodesFn)
return [...arr].sort(sortCoinNodesFn)
})
return {
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
11 changes: 11 additions & 0 deletions src/components/nodes/utils/sortNodesFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,14 @@ export function sortNodesFn(left: NodeStatusResult, right: NodeStatusResult) {

return left.url > right.url ? 1 : right.url > left.url ? -1 : 0
}

/**
* Group nodes by node label and sort them alphabetically by URL.
*/
export function sortCoinNodesFn(left: NodeStatusResult, right: NodeStatusResult) {
if (left.label !== right.label) {
return left.label > right.label ? 1 : -1
}

return sortNodesFn(left, right)
}
7 changes: 6 additions & 1 deletion src/components/transactions/KlyTransaction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
:inconsistent-status="inconsistentStatus"
:adm-tx="admTx"
:crypto="crypto"
:text-data="textData"
@refetch-status="refetch"
/>
</template>
Expand Down Expand Up @@ -105,6 +106,9 @@ export default defineComponent({
})
const fee = computed(() => transaction.value?.fee)
const textData = computed(() =>
transaction.value && 'data' in transaction.value ? transaction.value.data : ''
)
return {
refetch,
Expand All @@ -118,7 +122,8 @@ export default defineComponent({
admTx,
queryStatus,
transactionStatus,
inconsistentStatus
inconsistentStatus,
textData
}
}
})
Expand Down
3 changes: 3 additions & 0 deletions src/lib/nodes/abstract.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export abstract class Client<N extends Node> {
}
})
}

await Promise.all(this.nodes.map((node) => node.startHealthcheck()))
this.resolve()
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/lib/nodes/abstract.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ export abstract class Node<C = unknown> {
if (this.active) {
void this.fetchNodeVersion()
}

void this.startHealthcheck()
}

async startHealthcheck() {
Expand Down
22 changes: 0 additions & 22 deletions src/lib/nodes/btc-indexer/BtcIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ import { createBtcLikeClient } from '../utils/createBtcLikeClient'
import { AxiosInstance, AxiosRequestConfig } from 'axios'
import { Node } from '@/lib/nodes/abstract.node'
import { NODE_LABELS } from '@/lib/nodes/constants'
import { formatBtcVersion } from '@/lib/nodes/utils/nodeVersionFormatters'

type FetchBtcNodeInfoResult = {
error: string
result: {
version: number
}
}

/**
* Encapsulates a node. Provides methods to send API-requests
Expand All @@ -36,20 +28,6 @@ export class BtcIndexer extends Node<AxiosInstance> {
}
}

// @todo fetch version from the indexer, not node
protected async fetchNodeVersion(): Promise<void> {
const { data } = await this.client.post<FetchBtcNodeInfoResult>('/bitcoind', {
jsonrpc: '1.0',
id: 'adm',
method: 'getnetworkinfo',
params: []
})
const { version } = data.result
if (version) {
this.version = formatBtcVersion(version)
}
}

/**
* Performs a request to the Bitcoin indexer.
*/
Expand Down
10 changes: 0 additions & 10 deletions src/lib/nodes/doge-indexer/DogeIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { createBtcLikeClient } from '../utils/createBtcLikeClient'
import type { AxiosInstance, AxiosRequestConfig } from 'axios'
import { Node } from '@/lib/nodes/abstract.node'
import { NODE_LABELS } from '@/lib/nodes/constants'
import { formatDogeVersion } from '@/lib/nodes/utils/nodeVersionFormatters'
import { NodeStatus } from './types/api/node-status'

/**
* Encapsulates a node. Provides methods to send API-requests
Expand All @@ -30,14 +28,6 @@ export class DogeIndexer extends Node<AxiosInstance> {
}
}

protected async fetchNodeVersion(): Promise<void> {
const data = await this.request<NodeStatus>('GET', '/api/status')
const { version } = data.info
if (version) {
this.version = formatDogeVersion(version)
}
}

/**
* Performs a request to the Doge Indexer.
*/
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
10 changes: 5 additions & 5 deletions src/lib/nodes/eth-indexer/EthIndexerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ export class EthIndexerClient extends Client<EthIndexer> {

const requestParams: GetTransactionsRequest = {
and: `(${filters.join(',')})`,
order: 'time.desc',
limit: limit ? limit : undefined
order: 'time.desc'
// limit: limit ? limit : undefined
}

if (limit) requestParams.limit = limit

const transactions = await this.request('GET /ethtxs', {
...requestParams
})

return transactions.map((transaction) => normalizeTransaction(transaction, address, decimals))
return transactions
.map((transaction) => normalizeTransaction(transaction, address, decimals))
.slice(0, limit)
}
}
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
Loading

0 comments on commit 997e749

Please sign in to comment.