diff --git a/.github/workflows/push-webapp-test-01.yml b/.github/workflows/push-webapp-test-01.yml index adb6181cf0..c86143b7af 100644 --- a/.github/workflows/push-webapp-test-01.yml +++ b/.github/workflows/push-webapp-test-01.yml @@ -1,4 +1,4 @@ -name: Build WebApp Preview +name: Build Telegram MiniApp 01 on: pull_request: branches: @@ -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 diff --git a/.github/workflows/push-webapp-test-02.yml b/.github/workflows/push-webapp-test-02.yml index 0398b81138..b099c933eb 100644 --- a/.github/workflows/push-webapp-test-02.yml +++ b/.github/workflows/push-webapp-test-02.yml @@ -1,4 +1,4 @@ -name: Build WebApp Preview +name: Build Telegram MiniApp 02 on: pull_request: branches: @@ -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 diff --git a/.github/workflows/push-webapp-test-03.yml b/.github/workflows/push-webapp-test-03.yml index ca3f958f19..a9743dbe9e 100644 --- a/.github/workflows/push-webapp-test-03.yml +++ b/.github/workflows/push-webapp-test-03.yml @@ -1,4 +1,4 @@ -name: Build WebApp Preview +name: Build Telegram MiniApp 03 on: pull_request: branches: @@ -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 diff --git a/.github/workflows/push-webapp.yml b/.github/workflows/push-webapp.yml index 00bcd9d3e8..296ec105e3 100644 --- a/.github/workflows/push-webapp.yml +++ b/.github/workflows/push-webapp.yml @@ -1,4 +1,4 @@ -name: Build WebApp Preview +name: Build Telegram MiniApp on: pull_request: branches: @@ -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: 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/Popup/Home/Mission/TaskList.tsx b/packages/extension-koni-ui/src/Popup/Home/Mission/TaskList.tsx index 1289f2a666..cfeec490cb 100644 --- a/packages/extension-koni-ui/src/Popup/Home/Mission/TaskList.tsx +++ b/packages/extension-koni-ui/src/Popup/Home/Mission/TaskList.tsx @@ -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'; @@ -14,9 +14,11 @@ type Props = ThemeProps & { currentTaskCategory?: number; taskCategoryInfoMap: Record; 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(() => { @@ -24,28 +26,36 @@ const Component = ({ className, currentTaskCategory, onBackToCategoryList, taskC 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 ( @@ -63,12 +73,13 @@ const Component = ({ className, currentTaskCategory, onBackToCategoryList, taskC /> - {t('Missions')} + {taskCategory ? taskCategory.name : t('Missions')} {sortedTaskList.map((task) => ( diff --git a/packages/extension-koni-ui/src/Popup/Home/Mission/index.tsx b/packages/extension-koni-ui/src/Popup/Home/Mission/index.tsx index 88d8ebe18c..c5b018fc90 100644 --- a/packages/extension-koni-ui/src/Popup/Home/Mission/index.tsx +++ b/packages/extension-koni-ui/src/Popup/Home/Mission/index.tsx @@ -65,12 +65,26 @@ const Component = ({ className }: Props): React.ReactElement => { const [account, setAccount] = useState(apiSDK.account); const [currentViewMode, setCurrentViewMode] = useState(ViewMode.CATEGORY_LIST); const [currentTaskCategory, setCurrentTaskCategory] = useState(); + const [taskCategory, setTaskCategory] = useState(); + const [reloadAccount, setReloadAccount] = useState(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); }); @@ -88,7 +102,6 @@ const Component = ({ className }: Props): React.ReactElement => { }); return () => { - accountSub.unsubscribe(); taskCategoryListSub.unsubscribe(); taskListSub.unsubscribe(); clearInterval(taskListUpdaterInterval); @@ -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(() => { @@ -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} /> )} @@ -131,6 +145,8 @@ const Component = ({ className }: Props): React.ReactElement => { ) 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) { diff --git a/packages/webapp/package.json b/packages/webapp/package.json index 2cf64d37f2..21ba72d23b 100644 --- a/packages/webapp/package.json +++ b/packages/webapp/package.json @@ -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", @@ -50,4 +50,4 @@ "webpack-cli": "^4.10.0", "webpack-dev-server": "^4.11.1" } -} +} \ No newline at end of file