Skip to content

Commit

Permalink
Merge branch 'refs/heads/koni/dev/issue-task-onchain' into telegram-d…
Browse files Browse the repository at this point in the history
…ev-02
  • Loading branch information
anhnhu committed May 24, 2024
2 parents 03561ad + 1d1ca8a commit 39a5190
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 44 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/push-webapp-test-01.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build WebApp Preview
name: Build Telegram MiniApp 01
on:
pull_request:
branches:
Expand All @@ -10,8 +10,8 @@ on:

jobs:
master:
if: "! startsWith(github.event.head_commit.message, '[CI Skip]') || github.ref == 'refs/heads/telegram-wallet'"
name: Deploy WebApp Preview
if: "!startsWith(github.event.head_commit.message, '[CI Skip]')"
name: Deploy Telegram MiniApp 01
runs-on: ubuntu-22.04
steps:
- name: Checkout
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/push-webapp-test-02.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build WebApp Preview
name: Build Telegram MiniApp 02
on:
pull_request:
branches:
Expand All @@ -10,8 +10,8 @@ on:

jobs:
master:
if: "! startsWith(github.event.head_commit.message, '[CI Skip]') || github.ref == 'refs/heads/telegram-wallet'"
name: Deploy WebApp Preview
if: "!startsWith(github.event.head_commit.message, '[CI Skip]')"
name: Deploy Telegram MiniApp 02
runs-on: ubuntu-22.04
steps:
- name: Checkout
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/push-webapp-test-03.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build WebApp Preview
name: Build Telegram MiniApp 03
on:
pull_request:
branches:
Expand All @@ -10,8 +10,8 @@ on:

jobs:
master:
if: "! startsWith(github.event.head_commit.message, '[CI Skip]') || github.ref == 'refs/heads/telegram-wallet'"
name: Deploy WebApp Preview
if: "!startsWith(github.event.head_commit.message, '[CI Skip]')"
name: Deploy Telegram MiniApp 03
runs-on: ubuntu-22.04
steps:
- name: Checkout
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/push-webapp.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build WebApp Preview
name: Build Telegram MiniApp
on:
pull_request:
branches:
Expand All @@ -10,15 +10,15 @@ on:

jobs:
master:
if: "! startsWith(github.event.head_commit.message, '[CI Skip]') || github.ref == 'refs/heads/telegram-wallet'"
name: Deploy WebApp Preview
if: "!startsWith(github.event.head_commit.message, '[CI Skip]')"
name: Deploy Telegram MiniApp
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GH_PAT }}
token: ${{ secrets.GH_AUTOMATION_TOKEN }}
- name: Setup Node
uses: actions/setup-node@v3
with:
Expand Down
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
51 changes: 31 additions & 20 deletions packages/extension-koni-ui/src/Popup/Home/Mission/TaskList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2019-2022 @subwallet/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { TaskCategoryInfo } from '@subwallet/extension-koni-ui/connector/booka/types';
import { TaskCategory, TaskCategoryInfo } from '@subwallet/extension-koni-ui/connector/booka/types';
import { useTranslation } from '@subwallet/extension-koni-ui/hooks';
import TaskItem from '@subwallet/extension-koni-ui/Popup/Home/Mission/TaskItem';
import { ThemeProps } from '@subwallet/extension-koni-ui/types';
Expand All @@ -14,38 +14,48 @@ type Props = ThemeProps & {
currentTaskCategory?: number;
taskCategoryInfoMap: Record<number, TaskCategoryInfo>;
onBackToCategoryList: VoidFunction;
actionReloadPoint: VoidFunction;
taskCategory: TaskCategory | undefined;
};

const Component = ({ className, currentTaskCategory, onBackToCategoryList, taskCategoryInfoMap }: Props): React.ReactElement => {
const Component = ({ actionReloadPoint, className, currentTaskCategory, onBackToCategoryList, taskCategory, taskCategoryInfoMap }: Props): React.ReactElement => {
const { t } = useTranslation();

const sortedTaskList = useMemo(() => {
const now = Date.now();

const taskList = currentTaskCategory ? taskCategoryInfoMap[currentTaskCategory]?.tasks || [] : [];

return taskList.sort((a, b) => {
const aDisabled = ((a.startTime && new Date(a.startTime).getTime() > now) || (a.endTime && new Date(a.endTime).getTime() < now));
const bDisabled = ((b.startTime && new Date(b.startTime).getTime() > now) || (b.endTime && new Date(b.endTime).getTime() < now));

if (aDisabled && !bDisabled) {
return 1;
return taskList.filter((task) => {
// Filter out the task that ended more than 1 day ago
if (!task.completedAt && task.endTime && new Date(task.endTime).getTime() < now) {
return false;
} else {
return true;
}
})
.sort((a, b) => {
const aDisabled = ((a.startTime && new Date(a.startTime).getTime() > now) || (a.endTime && new Date(a.endTime).getTime() < now));
const bDisabled = ((b.startTime && new Date(b.startTime).getTime() > now) || (b.endTime && new Date(b.endTime).getTime() < now));

if (!aDisabled && bDisabled) {
return -1;
}
if (aDisabled && !bDisabled) {
return 1;
}

if (a.status === 0 && b.status !== 0) {
return -1;
}
if (!aDisabled && bDisabled) {
return -1;
}

if (a.status !== 0 && b.status === 0) {
return 1;
}
if (a.status === 0 && b.status !== 0) {
return -1;
}

if (a.status !== 0 && b.status === 0) {
return 1;
}

return a.status - b.status;
});
return a.status - b.status;
});
}, [currentTaskCategory, taskCategoryInfoMap]);

return (
Expand All @@ -63,12 +73,13 @@ const Component = ({ className, currentTaskCategory, onBackToCategoryList, taskC
/>

<Typography.Title level={4}>
{t('Missions')}
{taskCategory ? taskCategory.name : t('Missions')}
</Typography.Title>
</div>

{sortedTaskList.map((task) => (
<TaskItem
actionReloadPoint={actionReloadPoint}
key={task.id}
task={task}
/>
Expand Down
20 changes: 18 additions & 2 deletions packages/extension-koni-ui/src/Popup/Home/Mission/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,26 @@ const Component = ({ className }: Props): React.ReactElement => {
const [account, setAccount] = useState(apiSDK.account);
const [currentViewMode, setCurrentViewMode] = useState<ViewMode>(ViewMode.CATEGORY_LIST);
const [currentTaskCategory, setCurrentTaskCategory] = useState<number | undefined>();
const [taskCategory, setTaskCategory] = useState<TaskCategory | undefined>();
const [reloadAccount, setReloadAccount] = useState<number>(0);
const [point, setPoint] = useState(account?.attributes.point || 0);

const actionReloadPoint = useCallback(() => {
setReloadAccount(reloadAccount + 1);
}, [reloadAccount]);

useEffect(() => {
const accountSub = apiSDK.subscribeAccount().subscribe((data) => {
setAccount(data);
setPoint(data?.attributes.point || 0);
});

return () => {
accountSub.unsubscribe();
};
}, [reloadAccount]);

useEffect(() => {
const taskCategoryListSub = apiSDK.subscribeTaskCategoryList().subscribe((data) => {
setTaskCategoryList(data);
});
Expand All @@ -88,7 +102,6 @@ const Component = ({ className }: Props): React.ReactElement => {
});

return () => {
accountSub.unsubscribe();
taskCategoryListSub.unsubscribe();
taskListSub.unsubscribe();
clearInterval(taskListUpdaterInterval);
Expand All @@ -98,6 +111,7 @@ const Component = ({ className }: Props): React.ReactElement => {
const onClickCategoryItem = useCallback((categoryId: number) => {
setCurrentViewMode(ViewMode.TASK_LIST);
setCurrentTaskCategory(categoryId);
setTaskCategory(taskCategoryList.find((tc) => tc.id === categoryId));
}, []);

const onBackToCategoryList = useCallback(() => {
Expand All @@ -112,7 +126,7 @@ const Component = ({ className }: Props): React.ReactElement => {
avatar={account.info.photoUrl}
className={'account-info'}
name={`${account.info.firstName || ''} ${account.info.lastName || ''}`}
point={account.attributes.point}
point={point}
/>
)}

Expand All @@ -131,6 +145,8 @@ const Component = ({ className }: Props): React.ReactElement => {
<TaskList
currentTaskCategory={currentTaskCategory}
onBackToCategoryList={onBackToCategoryList}
taskCategory={taskCategory}
actionReloadPoint={actionReloadPoint}
taskCategoryInfoMap={taskCategoryInfoMap}
/>
)
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
4 changes: 2 additions & 2 deletions packages/webapp/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Koni Studio",
"bugs": "https://github.com/Koniverse/Subwallet-V2/issues",
"buildNumber": "1131001",
"buildNumber": "1151-1010",
"contributors": [],
"description": "A web runner simulate background.js can be use on mobile or environment support web view",
"homepage": "https://github.com/Koniverse/Subwallet-V2/tree/master/packages/webapp#readme",
Expand Down Expand Up @@ -50,4 +50,4 @@
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.11.1"
}
}
}

0 comments on commit 39a5190

Please sign in to comment.