From 1d1ca8a698635cfac91e977c8355d1a86af731e3 Mon Sep 17 00:00:00 2001 From: anhnhu Date: Fri, 24 May 2024 11:02:52 +0700 Subject: [PATCH] Update code task on chain --- .../src/Popup/Home/Mission/TaskItem.tsx | 15 +++++++++------ .../extension-koni-ui/src/connector/booka/sdk.ts | 10 +++++++++- 2 files changed, 18 insertions(+), 7 deletions(-) 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 960a724f93..e9e2432f30 100644 --- a/packages/extension-koni-ui/src/Popup/Home/Mission/TaskItem.tsx +++ b/packages/extension-koni-ui/src/Popup/Home/Mission/TaskItem.tsx @@ -18,12 +18,13 @@ import React, { useCallback, useEffect, useState } from 'react'; import styled from 'styled-components'; type Props = { - task: Task + task: Task, + actionReloadPoint: VoidFunction; } & ThemeProps; const apiSDK = BookaSdk.instance; - -const _TaskItem = ({ className, task }: Props): React.ReactElement => { +const telegramConnector = TelegramConnector.instance; +const _TaskItem = ({ className, task, actionReloadPoint }: Props): React.ReactElement => { useSetCurrentPage('/home/mission'); const notify = useNotification(); const [account, setAccount] = useState(apiSDK.account); @@ -38,12 +39,13 @@ const _TaskItem = ({ className, task }: Props): React.ReactElement => { if (checking) { taskItemUpdaterInterval = setInterval(() => { apiSDK.completeTask(task.taskHistoryId) - .then((data: any) => { - if (data.completed) { + .then((data: boolean) => { + if (data) { // @ts-ignore clearInterval(taskItemUpdaterInterval); setCompleted(true); setChecking(false); + actionReloadPoint(); } }) .catch(console.error); @@ -115,12 +117,13 @@ const _TaskItem = ({ className, task }: Props): React.ReactElement => { setChecking(true); } else { setCompleted(true); + actionReloadPoint(); } }) .catch(console.error); setTimeout(() => { - // task.url && telegramConnector.openLink(task.url); + task.url && telegramConnector.openLink(task.url); }, 100); }, [task.id, task.url]); diff --git a/packages/extension-koni-ui/src/connector/booka/sdk.ts b/packages/extension-koni-ui/src/connector/booka/sdk.ts index 002f1ea2f7..b4ed8bb597 100644 --- a/packages/extension-koni-ui/src/connector/booka/sdk.ts +++ b/packages/extension-koni-ui/src/connector/booka/sdk.ts @@ -243,7 +243,15 @@ export class BookaSdk { } async completeTask (taskHistoryId: number|undefined) { - return await this.postRequest(`${GAME_API_HOST}/api/task/check-complete-task`, { taskHistoryId: taskHistoryId }); + const taskHistoryCheck = await this.postRequest<{completed: boolean}>(`${GAME_API_HOST}/api/task/check-complete-task`, { taskHistoryId: taskHistoryId }); + + if (taskHistoryCheck && taskHistoryCheck.completed) { + await this.reloadAccount(); + + return true; + } + + return false; } async finishTask (taskId: number, extrinsicHash: string, network: string) {