Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/koni/dev/issue-103'…
Browse files Browse the repository at this point in the history
… into telegram-dev
  • Loading branch information
saltict committed Aug 17, 2024
2 parents 038429a + 88dca98 commit e452517
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
27 changes: 25 additions & 2 deletions packages/extension-koni-ui/src/Popup/Home/Mission/TaskItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions packages/extension-koni-ui/src/connector/booka/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,17 @@ 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();

await this.fetchTaskList();

await this.reloadAccount();

return true;
}

return false;
return taskHistoryCheck;
}

async finishTask (taskId: number, extrinsicHash: string, network: string) {
Expand Down

0 comments on commit e452517

Please sign in to comment.