Skip to content

Commit dce695f

Browse files
authored
Merge pull request #750 from Adamant-im/feat/message-sending-timeouts
Feat/message sending timeouts
2 parents 2224b71 + ab7c036 commit dce695f

File tree

11 files changed

+318
-45
lines changed

11 files changed

+318
-45
lines changed

scripts/wallets.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ async function initCoins() {
7777
defaultGasLimit: coin.defaultGasLimit,
7878
defaultGasPriceGwei: coin.defaultGasPriceGwei,
7979
txFetchInfo: coin.txFetchInfo,
80+
timeout: coin.timeout,
8081
txConsistencyMaxTime: coin.txConsistencyMaxTime,
8182
defaultOrdinalLevel: coin.defaultOrdinalLevel,
8283
explorerTx: coin.explorerTx

src/App.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import Notifications from '@/lib/notifications'
1818
import { ThemeName } from './plugins/vuetify'
1919
import { useStore } from 'vuex'
2020
import { useI18n } from 'vue-i18n'
21+
import { useResendPendingMessages } from '@/hooks/useResendPendingMessages'
22+
23+
useResendPendingMessages()
2124
2225
const store = useStore()
2326
const isSnackbarShowing = computed(() => store.state.snackbar.show)

src/components/icons/cryptos/QntIcon.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
<path
44
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"
55
/>
6-
<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" />
6+
<path
7+
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"
8+
/>
79
<path
810
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
911
s1.6-9.3-20-12.4C426.5,192,426.5,193.6,426.5,193.6z"

src/components/icons/cryptos/UniIcon.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
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
3939
C395.3,262.7,394.8,272.8,393.5,278z"
4040
/>
41-
<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" />
41+
<path
42+
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"
43+
/>
4244
</g>
4345
</template>

src/components/icons/cryptos/UsdpIcon.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<template>
22
<g>
3-
<path d="M211.2,176.7c-16.6,0-30,13.4-30,30s13.4,30,30,30h20.7v-60H211.2z" />
3+
<path
4+
d="M211.2,176.7c-16.6,0-30,13.4-30,30s13.4,30,30,30h20.7v-60H211.2z"
5+
/>
46
<path
57
d="M256,16C123.5,16,16,123.5,16,256s107.5,240,240,240s240-107.5,240-240S388.5,16,256,16z
68
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

src/hooks/useResendPendingMessages.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { computed, onBeforeUnmount } from 'vue'
2+
import { useStore } from 'vuex'
3+
import { watchImmediate } from '@vueuse/core'
4+
import { MessageType } from '@/lib/constants'
5+
import { NodeStatusResult } from '@/lib/nodes/abstract.node'
6+
import { FileData } from '@/lib/files'
7+
8+
type PendingMessage = {
9+
recipientId: string
10+
timeout: ReturnType<typeof setTimeout>
11+
type: number
12+
files?: FileData[]
13+
}
14+
15+
export function useResendPendingMessages() {
16+
const store = useStore()
17+
18+
const admNodes = computed<NodeStatusResult[]>(() => store.getters['nodes/adm'])
19+
const ipfsNodes = computed<NodeStatusResult[]>(() => store.getters['nodes/ipfs'])
20+
const areAdmNodesOnline = computed(() => admNodes.value.some((node) => node.status === 'online'))
21+
const areIpfsNodesOnline = computed(() =>
22+
ipfsNodes.value.some((node) => node.status === 'online')
23+
)
24+
const pendingMessages = computed<Record<string, PendingMessage>>(
25+
() => store.state.chat.pendingMessages
26+
)
27+
28+
watchImmediate([areAdmNodesOnline, areIpfsNodesOnline], ([admOnline, ipfsOnline]) => {
29+
const hasMessagesWithFiles = Object.values(pendingMessages.value).some(
30+
(message) => message.files && message.files.length > 0
31+
)
32+
33+
const isReady = hasMessagesWithFiles ? admOnline && ipfsOnline : admOnline
34+
35+
if (!isReady) return
36+
37+
Object.entries(pendingMessages.value).forEach(([messageId, message]) => {
38+
;(message.type === MessageType.BASIC_ENCRYPTED_MESSAGE
39+
? store.dispatch('chat/resendMessage', {
40+
recipientId: message.recipientId,
41+
messageId
42+
})
43+
: store.dispatch('chat/resendAttachment', {
44+
recipientId: message.recipientId,
45+
files: message.files,
46+
messageId
47+
})
48+
).then((res) => {
49+
if (res.success) {
50+
store.commit('chat/deletePendingMessage', messageId)
51+
}
52+
})
53+
})
54+
})
55+
56+
onBeforeUnmount(() => {
57+
Object.values(pendingMessages.value).forEach((message) => {
58+
clearTimeout(message.timeout)
59+
})
60+
})
61+
}

src/lib/adamant-api/asset.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,21 +201,23 @@ export interface AttachmentAsset {
201201
* AIP-18: https://github.com/Adamant-im/AIPs/pull/54/files
202202
* @param {Array<FileData>} files
203203
* @param {string} [comment] Optional comment associated with the transaction
204-
* @param {Array<[string, string]>} [cids] List of files IDs after uploading to IPFS. First element is the ID of original file, second is ID of preview.
204+
* @param {Array<[string]>} [cids] List of files IDs after uploading to IPFS. ID of original file and ID of preview go one by one.
205205
*/
206206
export function attachmentAsset(
207207
files: FileData[],
208208
comment?: string,
209-
cids?: [string, string]
209+
cids?: string[]
210210
): AttachmentAsset {
211211
return {
212-
files: files.map(({ file, width, height, cid, preview, encoded }) => {
212+
files: files.map(({ file, width, height, cid, preview, encoded }, index) => {
213+
const cidsChunk = index * 2
214+
213215
const name = extractFileName(file.name)
214216
const extension = extractFileExtension(file.name)!
215217
const resolution: FileAsset['resolution'] = width && height ? [width, height] : undefined
216218

217-
const fileCid = cids?.[0] || cid
218-
const previewCid = cids?.[1] || preview?.cid
219+
const fileCid = (cids && cids[cidsChunk]) || cid
220+
const previewCid = (cids && cids[cidsChunk + 1]) || preview?.cid
219221

220222
return {
221223
mimeType: file.type,

src/lib/constants/cryptos/data.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@
9090
"oldPendingInterval": 4000,
9191
"registeredInterval": 4000
9292
},
93+
"timeout": {
94+
"message": 300000,
95+
"attachment": 300000
96+
},
9397
"defaultOrdinalLevel": 0,
9498
"explorerTx": "https://explorer.adamant.im/tx/${ID}"
9599
},

src/lib/nodes/ipfs/IpfsClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isNodeOfflineError } from '@/lib/nodes/utils/errors'
1+
import { isNodeOfflineError, AllNodesOfflineError } from '@/lib/nodes/utils/errors'
22
import { AxiosProgressEvent } from 'axios'
33
import { NODE_LABELS } from '@/lib/nodes/constants'
44
import { IpfsNode, Payload, RequestConfig } from './IpfsNode'
@@ -69,7 +69,7 @@ export class IpfsClient extends Client<IpfsNode> {
6969
// All nodes seem to be offline: let's refresh the statuses
7070
this.checkHealth()
7171
// But there's nothing we can do right now
72-
return Promise.reject(new Error('No online nodes at the moment'))
72+
return Promise.reject(new AllNodesOfflineError('ipfs'))
7373
}
7474

7575
return node.request(config).catch((error) => {

0 commit comments

Comments
 (0)