diff --git a/packages/extension-koni-ui/src/Popup/Home/Mission/TaskItem.tsx b/packages/extension-koni-ui/src/Popup/Home/Mission/TaskItem.tsx index 31635b7a8fd..6382733f3b1 100644 --- a/packages/extension-koni-ui/src/Popup/Home/Mission/TaskItem.tsx +++ b/packages/extension-koni-ui/src/Popup/Home/Mission/TaskItem.tsx @@ -39,8 +39,8 @@ const _TaskItem = ({ actionReloadPoint, className, openWidget, reloadTask, task useEffect(() => { if (checking && reloadTask > 0) { apiSDK.completeTask(task.id) - .then((data: boolean) => { - if (data) { + .then((data: { completed: boolean, isSubmitting: boolean }) => { + if (data.completed) { setCompleted(true); setChecking(false); actionReloadPoint(); @@ -83,6 +83,29 @@ const _TaskItem = ({ actionReloadPoint, className, openWidget, reloadTask, task const date = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`; const data = JSON.stringify({ address, type: onChainType, date }); + const checkCompleted = await apiSDK.completeTask(taskId); + + if (checkCompleted) { + if (checkCompleted.completed) { + setCompleted(checkCompleted.completed); + setTaskLoading(false); + + return; + } + + if (checkCompleted.isSubmitting) { + setCompleted(false); + setTaskLoading(false); + + notify({ + message: t('Mission in progress on another device. Use one device to complete it.'), + type: 'warning' + }); + + return; + } + } + res = await actionTaskOnChain(onChainType, networkKey, address, data); if ((res && res.errors.length > 0) || !res) { diff --git a/packages/extension-koni-ui/src/connector/booka/sdk.ts b/packages/extension-koni-ui/src/connector/booka/sdk.ts index 4dd33f894d6..04293aa794b 100644 --- a/packages/extension-koni-ui/src/connector/booka/sdk.ts +++ b/packages/extension-koni-ui/src/connector/booka/sdk.ts @@ -272,7 +272,7 @@ export class BookaSdk { } async completeTask (taskId: number | undefined) { - const taskHistoryCheck = await this.postRequest<{ completed: boolean }>(`${GAME_API_HOST}/api/task/check-complete-task`, { taskId }); + const taskHistoryCheck = await this.postRequest<{ completed: boolean, isSubmitting: boolean }>(`${GAME_API_HOST}/api/task/check-complete-task`, { taskId }); if (taskHistoryCheck && taskHistoryCheck.completed) { await this.fetchTaskCategoryList(); @@ -280,11 +280,9 @@ export class BookaSdk { await this.fetchTaskList(); await this.reloadAccount(); - - return true; } - return false; + return taskHistoryCheck; } async finishTask (taskId: number, extrinsicHash: string, network: string) {