Skip to content

Commit

Permalink
Update code task on chain
Browse files Browse the repository at this point in the history
  • Loading branch information
anhnhu committed May 24, 2024
1 parent b9ba00a commit 1d1ca8a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
15 changes: 9 additions & 6 deletions packages/extension-koni-ui/src/Popup/Home/Mission/TaskItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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]);

Expand Down
10 changes: 9 additions & 1 deletion packages/extension-koni-ui/src/connector/booka/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 1d1ca8a

Please sign in to comment.