Skip to content

Feat/message sending timeouts #750

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

Draft
wants to merge 8 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions scripts/wallets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ async function initCoins() {
defaultGasLimit: coin.defaultGasLimit,
defaultGasPriceGwei: coin.defaultGasPriceGwei,
txFetchInfo: coin.txFetchInfo,
timeout: coin.timeout,
txConsistencyMaxTime: coin.txConsistencyMaxTime,
defaultOrdinalLevel: coin.defaultOrdinalLevel,
explorerTx: coin.explorerTx
Expand Down
3 changes: 3 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import Notifications from '@/lib/notifications'
import { ThemeName } from './plugins/vuetify'
import { useStore } from 'vuex'
import { useI18n } from 'vue-i18n'
import { useResendPendingMessages } from '@/hooks/useResendPendingMessages'

useResendPendingMessages()

const store = useStore()
const isSnackbarShowing = computed(() => store.state.snackbar.show)
Expand Down
4 changes: 3 additions & 1 deletion src/components/icons/cryptos/QntIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<path
d="M134.8,44.5l121.9,142.9l81.8-48.1c0,0-98.7-132-125.1-122.7C188.8,25.9,134.8,44.5,134.8,44.5z"
/>
<path d="M341.7,139.2c0,0,18.6-32.6,27.8-76.1c0,0,92.6,37.2,57.1,130.5L341.7,139.2z" />
<path
d="M341.7,139.2c0,0,18.6-32.6,27.8-76.1c0,0,92.6,37.2,57.1,130.5L341.7,139.2z"
/>
<path
d="M426.5,193.6l7.8,97.9l35.5-4.6c0,0,9.2-3.1,7.8-20.1c-1.6-18.7-4.6-57.5-4.6-57.5
s1.6-9.3-20-12.4C426.5,192,426.5,193.6,426.5,193.6z"
Expand Down
4 changes: 3 additions & 1 deletion src/components/icons/cryptos/UniIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
c0-2.8,0.1-5.1,0.1-5.1c0.1,0,1.3,1,2.8,2.1c6.6,5.3,14,7.6,34.7,10.5c12.1,1.8,19,3.1,25.3,5.3c20,6.6,32.3,20.1,35.3,38.5
C395.3,262.7,394.8,272.8,393.5,278z"
/>
<path d="M117.1,60c0,0,0,0.1,0.1,0.2c0,0,0,0,0.1,0C117.2,60.1,117.1,60,117.1,60z" />
<path
d="M117.1,60c0,0,0,0.1,0.1,0.2c0,0,0,0,0.1,0C117.2,60.1,117.1,60,117.1,60z"
/>
</g>
</template>
4 changes: 3 additions & 1 deletion src/components/icons/cryptos/UsdpIcon.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<template>
<g>
<path d="M211.2,176.7c-16.6,0-30,13.4-30,30s13.4,30,30,30h20.7v-60H211.2z" />
<path
d="M211.2,176.7c-16.6,0-30,13.4-30,30s13.4,30,30,30h20.7v-60H211.2z"
/>
<path
d="M256,16C123.5,16,16,123.5,16,256s107.5,240,240,240s240-107.5,240-240S388.5,16,256,16z
M308.2,373.1h-29.6V431h-46.7v-57.9h-90.1v-37.5h90.1v-60.8h-30c-36.3-0.8-65.4-30-66.3-66.3c-0.8-37.4,28.8-68.4,66.3-69.3h30V81
Expand Down
51 changes: 51 additions & 0 deletions src/hooks/useResendPendingMessages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { computed, onBeforeUnmount } from 'vue'
import { useStore } from 'vuex'
import { watchImmediate } from '@vueuse/core'
import { MessageType } from '@/lib/constants'
import { NodeStatusResult } from '@/lib/nodes/abstract.node'
import { FileData } from '@/lib/files'

type PendingMessage = {
recipientId: string
timeout: ReturnType<typeof setTimeout>
type: number
files?: FileData[]
}

export function useResendPendingMessages() {
const store = useStore()

const admNodes = computed<NodeStatusResult[]>(() => store.getters['nodes/adm'])
const admNodesOnline = computed(() => admNodes.value.some((node) => node.status === 'online'))
const pendingMessages = computed<Record<string, PendingMessage>>(
() => store.state.chat.pendingMessages
)

watchImmediate(admNodesOnline, (online) => {
if (!online) return

Object.entries(pendingMessages.value).forEach(([messageId, message]) => {
;(message.type === MessageType.BASIC_ENCRYPTED_MESSAGE
? store.dispatch('chat/resendMessage', {
recipientId: message.recipientId,
messageId
})
: store.dispatch('chat/resendAttachment', {
recipientId: message.recipientId,
files: message.files,
messageId
})
).then((res) => {
if (res.success) {
store.commit('chat/deletePendingMessage', messageId)
}
})
})
})

onBeforeUnmount(() => {
Object.values(pendingMessages.value).forEach((message) => {
clearTimeout(message.timeout)
})
})
}
4 changes: 4 additions & 0 deletions src/lib/constants/cryptos/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
"oldPendingInterval": 4000,
"registeredInterval": 4000
},
"timeout": {
"message": 300000,
"attachment": 300000
},
"defaultOrdinalLevel": 0,
"explorerTx": "https://explorer.adamant.im/tx/${ID}"
},
Expand Down
4 changes: 2 additions & 2 deletions src/lib/nodes/ipfs/IpfsClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isNodeOfflineError } from '@/lib/nodes/utils/errors'
import { isNodeOfflineError, AllNodesOfflineError } from '@/lib/nodes/utils/errors'
import { AxiosProgressEvent } from 'axios'
import { NODE_LABELS } from '@/lib/nodes/constants'
import { IpfsNode, Payload, RequestConfig } from './IpfsNode'
Expand Down Expand Up @@ -69,7 +69,7 @@ export class IpfsClient extends Client<IpfsNode> {
// All nodes seem to be offline: let's refresh the statuses
this.checkHealth()
// But there's nothing we can do right now
return Promise.reject(new Error('No online nodes at the moment'))
return Promise.reject(new AllNodesOfflineError('ipfs'))
}

return node.request(config).catch((error) => {
Expand Down
Loading