diff --git a/.github/workflows/push-koni-dev.yml b/.github/workflows/push-koni-dev.yml deleted file mode 100644 index 2781f6789d..0000000000 --- a/.github/workflows/push-koni-dev.yml +++ /dev/null @@ -1,94 +0,0 @@ -name: Koni Dev -on: - pull_request: - branches: - - koni-dev - - upgrade-ui - - subwallet-dev - push: - branches: - - koni-dev - - upgrade-ui - - subwallet-dev - -jobs: - master: - if: "! startsWith(github.event.head_commit.message, '[CI Skip]')" - runs-on: ubuntu-22.04 - name: Build Development Preview - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - token: ${{ secrets.GH_PAT }} - - name: Set Params - id: setup_params - run: | - time_tag="$(date +'%Y-%m-%d_%H-%M')" - ref_with_prefix="${{ github.ref }}" - ref_without_prefix="${ref_with_prefix#refs/heads/}" - - echo "time_tag=$time_tag" >> $GITHUB_OUTPUT - if [[ -n "${{ github.event.pull_request }}" ]]; then - echo "ref=pr-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT - else - echo "ref=$ref_without_prefix" >> $GITHUB_OUTPUT - fi - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: '18' - cache: 'yarn' - - name: Build Dev - env: - CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} - GH_PAT: ${{ secrets.GH_PAT }} - GH_RELEASE_GITHUB_API_TOKEN: ${{ secrets.GH_PAT }} - TRANSAK_API_KEY: ${{ secrets.TRANSAK_API_KEY }} - COINBASE_PAY_ID: ${{ secrets.COINBASE_PAY_ID }} - GH_RELEASE_FILES: master-build.zip,master-src.zip - COMMIT_MESSAGE: ${{ github.event.head_commit.message }} - REF_NAME: ${{ github.ref_name }} - PR_NUMBER: ${{ github.event.number }} - TARGET_BRANCH: ${{ github.event.pull_request.base.ref }} - CURRENT_BRANCH: ${{ github.event.pull_request.head.ref || github.ref }} - BRANCH_NAME: ${{ github.ref_name }} - run: | - yarn install --immutable | grep -v 'YN0013' - yarn build:koni-dev - # Deploy after build - - name: Upload to Build to Nextcloud - id: nextcloud_upload - uses: trympet/nextcloud-artifacts-action@v2 - with: - name: '${{ steps.setup_params.outputs.ref }}-build-${{ steps.setup_params.outputs.time_tag }}' - path: 'master-build.zip' - nextcloud-url: 'https://file.cdmteck.com' - nextcloud-username: ${{ secrets.NEXTCLOUD_USERNAME }} - nextcloud-password: ${{ secrets.NEXTCLOUD_PASSWORD }} - - name: Deploy Webrunner to Netlify - id: netlify_deployment - uses: nwtgck/actions-netlify@v2.0 - with: - publish-dir: './packages/web-runner/build' - alias: ${{ steps.setup_params.outputs.ref }} - github-token: ${{ secrets.GH_PAT }} - deploy-message: ${{ github.event.head_commit.message }} - enable-pull-request-comment: true - enable-commit-comment: true - env: - NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} - NETLIFY_SITE_ID: ${{ secrets.NETLIFY_WEB_RUNNER_SITE_ID }} - timeout-minutes: 1 - - name: Notify to Discord - uses: sarisia/actions-status-discord@v1 - if: always() - with: - webhook: ${{ secrets.DISCORD_WEBHOOK }} - status: ${{ job.status }} - username: Extension Worker - title: ${{ github.workflow }} - description: | - The Deployment has been completed. - - Extension: ${{ steps.nextcloud_upload.outputs.SHAREABLE_URL }} - - Web-runner: ${{ steps.netlify_deployment.outputs.deploy-url }} diff --git a/.github/workflows/push-master.yml b/.github/workflows/push-master.yml deleted file mode 100644 index 3a04ca5802..0000000000 --- a/.github/workflows/push-master.yml +++ /dev/null @@ -1,71 +0,0 @@ -name: Master -on: - push: - branches: - - master - -jobs: - master: - if: "! startsWith(github.event.head_commit.message, '[CI Skip]')" - strategy: - matrix: - step: ['build:release'] - name: ${{ matrix.step }} - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - token: ${{ secrets.GH_PAT }} - - name: ${{ matrix.step }} - env: - CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} - GH_PAT: ${{ secrets.GH_PAT }} - GH_RELEASE_GITHUB_API_TOKEN: ${{ secrets.GH_PAT }} - GH_RELEASE_FILES: master-build.zip,master-src.zip - DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - TRANSAK_API_KEY: ${{ secrets.TRANSAK_API_KEY }} - COINBASE_PAY_ID: ${{ secrets.COINBASE_PAY_ID }} - BRANCH_NAME: ${{ github.ref_name }} - run: | - yarn install --immutable | grep -v 'YN0013' - yarn ${{ matrix.step }} - - - name: Upload to Build to Nextcloud - id: nextcloud_upload - uses: trympet/nextcloud-artifacts-action@v2 - with: - name: 'master-build.zip' - path: 'master-build.zip' - nextcloud-url: 'https://file.cdmteck.com' - nextcloud-username: ${{ secrets.NEXTCLOUD_USERNAME }} - nextcloud-password: ${{ secrets.NEXTCLOUD_PASSWORD }} - - - name: Deploy Webrunner to Netlify - id: netlify_deployment - uses: nwtgck/actions-netlify@v2.0 - with: - publish-dir: './packages/web-runner/build' - production-branch: master - github-token: ${{ secrets.GH_PAT }} - deploy-message: ${{ github.event.head_commit.message }} - enable-pull-request-comment: true - enable-commit-comment: true - env: - NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} - NETLIFY_SITE_ID: ${{ secrets.NETLIFY_WEB_RUNNER_SITE_ID }} - timeout-minutes: 1 - - - name: Notify to Discord - uses: sarisia/actions-status-discord@v1 - if: always() - with: - webhook: ${{ secrets.DISCORD_WEBHOOK }} - status: ${{ job.status }} - username: Extension Worker - title: ${{ github.workflow }} - description: | - Master is completed. - - Extension: ${{ steps.nextcloud_upload.outputs.SHAREABLE_URL }} - - Web-runner: ${{ steps.netlify_deployment.outputs.deploy-url }} diff --git a/.github/workflows/push-web-runner.yml b/.github/workflows/push-web-runner.yml deleted file mode 100644 index 6b6130316b..0000000000 --- a/.github/workflows/push-web-runner.yml +++ /dev/null @@ -1,64 +0,0 @@ -name: Web Runner -on: - pull_request: - branches: - - web-runner - - web-runner-demo - push: - branches: - - web-runner - - web-runner-demo - -jobs: - master: - strategy: - matrix: - step: ['web-runner:build-zip'] - name: ${{ matrix.step }} - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - token: ${{ secrets.GH_PAT }} - - name: ${{ matrix.step }} - env: - CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} - GH_PAT: ${{ secrets.GH_PAT }} - GH_RELEASE_GITHUB_API_TOKEN: ${{ secrets.GH_PAT }} - GH_RELEASE_FILES: master-build.zip,master-src.zip - DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - TRANSAK_API_KEY: ${{ secrets.TRANSAK_API_KEY }} - COINBASE_PAY_ID: ${{ secrets.COINBASE_PAY_ID }} - BRANCH_NAME: master - run: | - yarn install --immutable | grep -v 'YN0013' - yarn ${{ matrix.step }} - - - name: Deploy Webrunner to Netlify - id: netlify_deployment - uses: nwtgck/actions-netlify@v2.0 - with: - publish-dir: './packages/web-runner/build' - production-branch: master - github-token: ${{ secrets.GH_PAT }} - deploy-message: ${{ github.event.head_commit.message }} - enable-pull-request-comment: true - enable-commit-comment: true - env: - NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} - NETLIFY_SITE_ID: ${{ secrets.NETLIFY_WEB_RUNNER_SITE_ID }} - timeout-minutes: 1 - - - name: Notify to Discord - uses: sarisia/actions-status-discord@v1 - if: always() - with: - webhook: ${{ secrets.DISCORD_WEBHOOK }} - status: ${{ job.status }} - username: Extension Worker - title: ${{ github.workflow }} - description: | - Web-runner is completed. - - Web-runner: ${{ steps.netlify_deployment.outputs.deploy-url }} diff --git a/.github/workflows/push-webapp-test-01.yml b/.github/workflows/push-webapp-test-01.yml new file mode 100644 index 0000000000..c86143b7af --- /dev/null +++ b/.github/workflows/push-webapp-test-01.yml @@ -0,0 +1,70 @@ +name: Build Telegram MiniApp 01 +on: + pull_request: + branches: + - telegram-dev-01 + + push: + branches: + - telegram-dev-01 + +jobs: + master: + if: "!startsWith(github.event.head_commit.message, '[CI Skip]')" + name: Deploy Telegram MiniApp 01 + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + token: ${{ secrets.GH_AUTOMATION_TOKEN }} + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: '18' + cache: 'yarn' + - name: Build + env: + TRANSAK_API_KEY: ${{ secrets.TRANSAK_API_KEY }} + COINBASE_PAY_ID: ${{ secrets.COINBASE_PAY_ID }} + NFT_MINTING_HOST: ${{ secrets.NFT_MINTING_HOST }} + BRANCH_NAME: ${{ github.ref_name }} + GAME_API_HOST: ${{ vars.API_DEV_SERVER_1 }} + TELEGRAM_WEBAPP_LINK: ${{ vars.TELEGRAM_WEBAPP_LINK_01 }} + run: | + yarn install --immutable | grep -v 'YN0013' + if [ ${{ github.ref_name }} == 'telegram-wallet' ]; then + yarn run webapp:change-build-number + fi + yarn webapp:build + - name: Publish to Cloudflare Pages + id: cloudflare_deployment + uses: cloudflare/pages-action@v1 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + projectName: ${{ vars.CLOUDFLARE_PAGES_PROJECT_NAME }} + gitHubToken: ${{ secrets.GH_AUTOMATION_TOKEN }} + branch: ${{ github.ref_name }} + directory: './packages/webapp/build' + wranglerVersion: '3' + - if: "github.ref_name == 'telegram-wallet' && github.event_name == 'push'" + name: Automation Bot + uses: EndBug/add-and-commit@v9 + with: + author_name: Automation Bot + author_email: bot@subwallet.app + message: '[CI Skip] Auto increase webapp build number' + - name: Notify to Discord + uses: sarisia/actions-status-discord@v1 + if: always() + with: + webhook: ${{ secrets.DISCORD_WEBHOOK }} + status: ${{ job.status }} + username: WebApp Worker + title: ${{ github.workflow }} + description: | + The deployment is completed. + - URL: ${{ steps.cloudflare_deployment.outputs.url }} + - Alias: ${{ steps.cloudflare_deployment.outputs.alias }} diff --git a/.github/workflows/push-webapp-test-02.yml b/.github/workflows/push-webapp-test-02.yml new file mode 100644 index 0000000000..b099c933eb --- /dev/null +++ b/.github/workflows/push-webapp-test-02.yml @@ -0,0 +1,70 @@ +name: Build Telegram MiniApp 02 +on: + pull_request: + branches: + - telegram-dev-02 + + push: + branches: + - telegram-dev-02 + +jobs: + master: + if: "!startsWith(github.event.head_commit.message, '[CI Skip]')" + name: Deploy Telegram MiniApp 02 + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + token: ${{ secrets.GH_AUTOMATION_TOKEN }} + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: '18' + cache: 'yarn' + - name: Build + env: + TRANSAK_API_KEY: ${{ secrets.TRANSAK_API_KEY }} + COINBASE_PAY_ID: ${{ secrets.COINBASE_PAY_ID }} + NFT_MINTING_HOST: ${{ secrets.NFT_MINTING_HOST }} + BRANCH_NAME: ${{ github.ref_name }} + GAME_API_HOST: ${{ vars.API_DEV_SERVER_2 }} + TELEGRAM_WEBAPP_LINK: ${{ vars.TELEGRAM_WEBAPP_LINK_02 }} + run: | + yarn install --immutable | grep -v 'YN0013' + if [ ${{ github.ref_name }} == 'telegram-wallet' ]; then + yarn run webapp:change-build-number + fi + yarn webapp:build + - name: Publish to Cloudflare Pages + id: cloudflare_deployment + uses: cloudflare/pages-action@v1 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + projectName: ${{ vars.CLOUDFLARE_PAGES_PROJECT_NAME }} + gitHubToken: ${{ secrets.GH_AUTOMATION_TOKEN }} + branch: ${{ github.ref_name }} + directory: './packages/webapp/build' + wranglerVersion: '3' + - if: "github.ref_name == 'telegram-wallet' && github.event_name == 'push'" + name: Automation Bot + uses: EndBug/add-and-commit@v9 + with: + author_name: Automation Bot + author_email: bot@subwallet.app + message: '[CI Skip] Auto increase webapp build number' + - name: Notify to Discord + uses: sarisia/actions-status-discord@v1 + if: always() + with: + webhook: ${{ secrets.DISCORD_WEBHOOK }} + status: ${{ job.status }} + username: WebApp Worker + title: ${{ github.workflow }} + description: | + The deployment is completed. + - URL: ${{ steps.cloudflare_deployment.outputs.url }} + - Alias: ${{ steps.cloudflare_deployment.outputs.alias }} diff --git a/.github/workflows/push-webapp-test-03.yml b/.github/workflows/push-webapp-test-03.yml new file mode 100644 index 0000000000..a9743dbe9e --- /dev/null +++ b/.github/workflows/push-webapp-test-03.yml @@ -0,0 +1,70 @@ +name: Build Telegram MiniApp 03 +on: + pull_request: + branches: + - telegram-dev-03 + + push: + branches: + - telegram-dev-03 + +jobs: + master: + if: "!startsWith(github.event.head_commit.message, '[CI Skip]')" + name: Deploy Telegram MiniApp 03 + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + token: ${{ secrets.GH_AUTOMATION_TOKEN }} + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: '18' + cache: 'yarn' + - name: Build + env: + TRANSAK_API_KEY: ${{ secrets.TRANSAK_API_KEY }} + COINBASE_PAY_ID: ${{ secrets.COINBASE_PAY_ID }} + NFT_MINTING_HOST: ${{ secrets.NFT_MINTING_HOST }} + BRANCH_NAME: ${{ github.ref_name }} + GAME_API_HOST: ${{ vars.API_DEV_SERVER_2 }} + TELEGRAM_WEBAPP_LINK: ${{ vars.TELEGRAM_WEBAPP_LINK_02 }} + run: | + yarn install --immutable | grep -v 'YN0013' + if [ ${{ github.ref_name }} == 'telegram-wallet' ]; then + yarn run webapp:change-build-number + fi + yarn webapp:build + - name: Publish to Cloudflare Pages + id: cloudflare_deployment + uses: cloudflare/pages-action@v1 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + projectName: ${{ vars.CLOUDFLARE_PAGES_PROJECT_NAME }} + gitHubToken: ${{ secrets.GH_AUTOMATION_TOKEN }} + branch: ${{ github.ref_name }} + directory: './packages/webapp/build' + wranglerVersion: '3' + - if: "github.ref_name == 'telegram-wallet' && github.event_name == 'push'" + name: Automation Bot + uses: EndBug/add-and-commit@v9 + with: + author_name: Automation Bot + author_email: bot@subwallet.app + message: '[CI Skip] Auto increase webapp build number' + - name: Notify to Discord + uses: sarisia/actions-status-discord@v1 + if: always() + with: + webhook: ${{ secrets.DISCORD_WEBHOOK }} + status: ${{ job.status }} + username: WebApp Worker + title: ${{ github.workflow }} + description: | + The deployment is completed. + - URL: ${{ steps.cloudflare_deployment.outputs.url }} + - Alias: ${{ steps.cloudflare_deployment.outputs.alias }} diff --git a/.github/workflows/push-webapp-yield.yml b/.github/workflows/push-webapp-yield.yml deleted file mode 100644 index c8fbec4c31..0000000000 --- a/.github/workflows/push-webapp-yield.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: Build Yield WebApp Preview -on: - pull_request: - branches: - - webapp-yield - push: - branches: - - webapp-yield - -jobs: - master: - if: "! startsWith(github.event.head_commit.message, '[CI Skip]')" - name: Deploy Yield WebApp Preview - runs-on: ubuntu-22.04 - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - token: ${{ secrets.GH_PAT }} - - uses: actions/setup-node@v3 - with: - node-version: '18' - cache: 'yarn' - - run: yarn install --immutable | grep -v 'YN0013' - - name: Build - env: - TRANSAK_API_KEY: ${{ secrets.TRANSAK_API_KEY }} - COINBASE_PAY_ID: ${{ secrets.COINBASE_PAY_ID }} - NFT_MINTING_HOST: ${{ secrets.NFT_MINTING_HOST }} - BRANCH_NAME: ${{ github.ref_name }} - run: | - yarn webapp:build - - name: Publish to Cloudflare Pages - uses: cloudflare/pages-action@v1 - with: - apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - projectName: ${{ vars.CLOUDFLARE_PAGES_YIELD_PROJECT_NAME }} - gitHubToken: ${{ secrets.GH_AUTOMATION_TOKEN }} - branch: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || 'main' }} - directory: './packages/webapp/build' - wranglerVersion: '3' diff --git a/.github/workflows/push-webapp.yml b/.github/workflows/push-webapp.yml index 6a632b7364..296ec105e3 100644 --- a/.github/workflows/push-webapp.yml +++ b/.github/workflows/push-webapp.yml @@ -1,25 +1,24 @@ -name: Build WebApp Preview +name: Build Telegram MiniApp on: pull_request: branches: - - webapp - - webapp-dev + - telegram-wallet + push: branches: - - webapp - - webapp-dev + - telegram-wallet jobs: master: - if: "! startsWith(github.event.head_commit.message, '[CI Skip]') || github.ref == 'refs/heads/webapp'" - 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: @@ -31,9 +30,11 @@ jobs: COINBASE_PAY_ID: ${{ secrets.COINBASE_PAY_ID }} NFT_MINTING_HOST: ${{ secrets.NFT_MINTING_HOST }} BRANCH_NAME: ${{ github.ref_name }} + GAME_API_HOST: ${{ vars.API_DEV_SERVER }} + TELEGRAM_WEBAPP_LINK: ${{ vars.TELEGRAM_WEBAPP_LINK }} run: | yarn install --immutable | grep -v 'YN0013' - if [ ${{ github.ref_name }} == 'webapp-dev' ]; then + if [ ${{ github.ref_name }} == 'telegram-wallet' ]; then yarn run webapp:change-build-number fi yarn webapp:build @@ -45,10 +46,10 @@ jobs: accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} projectName: ${{ vars.CLOUDFLARE_PAGES_PROJECT_NAME }} gitHubToken: ${{ secrets.GH_AUTOMATION_TOKEN }} - branch: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || github.ref_name }} + branch: ${{ github.ref_name }} directory: './packages/webapp/build' wranglerVersion: '3' - - if: "github.ref_name == 'webapp-dev' && github.event_name == 'push'" + - if: "github.ref_name == 'telegram-wallet' && github.event_name == 'push'" name: Automation Bot uses: EndBug/add-and-commit@v9 with: diff --git a/.github/workflows/semgrep.yml b/.github/workflows/semgrep.yml deleted file mode 100644 index f15a4422ea..0000000000 --- a/.github/workflows/semgrep.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Semgrep -on: - push: - branches: - - master - -jobs: - check: - if: "! startsWith(github.event.head_commit.message, '[CI Skip]') && (!github.event.pull_request || github.event.pull_request.head.repo.full_name == github.repository)" - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v3 - - uses: returntocorp/semgrep-action@v1 - with: - auditOn: push - publishToken: ${{ secrets.SEMGREP_APP_TOKEN }} - publishDeployment: 1395 diff --git a/packages/extension-base/src/background/KoniTypes.ts b/packages/extension-base/src/background/KoniTypes.ts index 134b0eeffe..72ec0114ce 100644 --- a/packages/extension-base/src/background/KoniTypes.ts +++ b/packages/extension-base/src/background/KoniTypes.ts @@ -506,7 +506,8 @@ export enum ExtrinsicType { TOKEN_APPROVE = 'evm.token_approve', EVM_EXECUTE = 'evm.execute', - UNKNOWN = 'unknown' + UNKNOWN = 'unknown', + REMARK_WITH_EVENT = 'remark_with_event' } export interface ExtrinsicDataTypeMap { @@ -1129,6 +1130,12 @@ export interface NftTransactionRequest { nftItem: NftItem } +export interface RemarkWithEvent { + networkKey: string, + address: string, + dataRemark: string +} + export interface EvmNftTransaction extends ValidateTransactionResponse { tx: Record | null; } diff --git a/packages/extension-base/src/koni/background/handlers/Extension.ts b/packages/extension-base/src/koni/background/handlers/Extension.ts index 4cbdf470d0..17fa217edd 100644 --- a/packages/extension-base/src/koni/background/handlers/Extension.ts +++ b/packages/extension-base/src/koni/background/handlers/Extension.ts @@ -7,7 +7,153 @@ import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError'; import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers'; import { createSubscription } from '@subwallet/extension-base/background/handlers/subscriptions'; -import { AccountExternalError, AccountExternalErrorCode, AccountsWithCurrentAddress, AddressBookInfo, AmountData, AmountDataWithId, AssetSetting, AssetSettingUpdateReq, BasicTxErrorType, BasicTxWarningCode, BondingOptionParams, BrowserConfirmationType, CampaignBanner, CampaignData, CampaignDataType, ChainType, CreateDeriveAccountInfo, CronReloadRequest, CurrentAccountInfo, DeriveAccountInfo, ExternalRequestPromiseStatus, ExtrinsicType, KeyringState, MantaPayEnableMessage, MantaPayEnableParams, MantaPayEnableResponse, MantaPaySyncState, NftCollection, NftJson, NftTransactionRequest, NftTransactionResponse, OptionInputAddress, PriceJson, RequestAccountCreateExternalV2, RequestAccountCreateHardwareMultiple, RequestAccountCreateHardwareV2, RequestAccountCreateSuriV2, RequestAccountCreateWithSecretKey, RequestAccountExportPrivateKey, RequestAccountMeta, RequestAddInjectedAccounts, RequestApproveConnectWalletSession, RequestApproveWalletConnectNotSupport, RequestAuthorization, RequestAuthorizationBlock, RequestAuthorizationPerAccount, RequestAuthorizationPerSite, RequestAuthorizeApproveV2, RequestBatchRestoreV2, RequestBondingSubmit, RequestCameraSettings, RequestCampaignBannerComplete, RequestChangeEnableChainPatrol, RequestChangeLanguage, RequestChangeMasterPassword, RequestChangeShowBalance, RequestChangeShowZeroBalance, RequestChangeTimeAutoLock, RequestCheckPublicAndSecretKey, RequestConfirmationComplete, RequestConnectWalletConnect, RequestCrossChainTransfer, RequestDeleteContactAccount, RequestDeriveCreateMultiple, RequestDeriveCreateV2, RequestDeriveCreateV3, RequestDeriveValidateV2, RequestDisconnectWalletConnectSession, RequestEditContactAccount, RequestFindRawMetadata, RequestForgetSite, RequestFreeBalance, RequestGetDeriveAccounts, RequestGetTransaction, RequestJsonRestoreV2, RequestKeyringExportMnemonic, RequestMaxTransferable, RequestMigratePassword, RequestParseEvmContractInput, RequestParseTransactionSubstrate, RequestPassPhishingPage, RequestQrParseRLP, RequestQrSignEvm, RequestQrSignSubstrate, RequestRejectConnectWalletSession, RequestRejectExternalRequest, RequestRejectWalletConnectNotSupport, RequestRemoveInjectedAccounts, RequestResetWallet, RequestResolveExternalRequest, RequestSaveRecentAccount, RequestSeedCreateV2, RequestSeedValidateV2, RequestSettingsType, RequestSigningApprovePasswordV2, RequestStakePoolingBonding, RequestStakePoolingUnbonding, RequestSubscribeHistory, RequestSubstrateNftSubmitTransaction, RequestTransfer, RequestTransferCheckReferenceCount, RequestTransferCheckSupporting, RequestTransferExistentialDeposit, RequestTuringCancelStakeCompound, RequestTuringStakeCompound, RequestUnbondingSubmit, RequestUnlockKeyring, RequestUnlockType, ResolveAddressToDomainRequest, ResolveDomainRequest, ResponseAccountCreateSuriV2, ResponseAccountCreateWithSecretKey, ResponseAccountExportPrivateKey, ResponseAccountMeta, ResponseChangeMasterPassword, ResponseCheckPublicAndSecretKey, ResponseDeriveValidateV2, ResponseFindRawMetadata, ResponseGetDeriveAccounts, ResponseKeyringExportMnemonic, ResponseMigratePassword, ResponseParseEvmContractInput, ResponseParseTransactionSubstrate, ResponsePrivateKeyValidateV2, ResponseQrParseRLP, ResponseQrSignEvm, ResponseQrSignSubstrate, ResponseRejectExternalRequest, ResponseResetWallet, ResponseResolveExternalRequest, ResponseSeedCreateV2, ResponseSeedValidateV2, ResponseSubscribeHistory, ResponseUnlockKeyring, StakingTxErrorType, StakingType, SupportTransferResponse, ThemeNames, TransactionHistoryItem, TransactionResponse, TransferTxErrorType, ValidateNetworkRequest, ValidateNetworkResponse, ValidatorInfo } from '@subwallet/extension-base/background/KoniTypes'; +import { + AccountExternalError, + AccountExternalErrorCode, + AccountsWithCurrentAddress, + AddressBookInfo, + AmountData, + AmountDataWithId, + AssetSetting, + AssetSettingUpdateReq, + BasicTxErrorType, + BasicTxWarningCode, + BondingOptionParams, + BrowserConfirmationType, + CampaignBanner, + CampaignData, + CampaignDataType, + ChainType, + CreateDeriveAccountInfo, + CronReloadRequest, + CurrentAccountInfo, + DeriveAccountInfo, + ExternalRequestPromiseStatus, + ExtrinsicType, + KeyringState, + MantaPayEnableMessage, + MantaPayEnableParams, + MantaPayEnableResponse, + MantaPaySyncState, + NftCollection, + NftJson, + NftTransactionRequest, + NftTransactionResponse, + OptionInputAddress, + PriceJson, + RemarkWithEvent, + RequestAccountCreateExternalV2, + RequestAccountCreateHardwareMultiple, + RequestAccountCreateHardwareV2, + RequestAccountCreateSuriV2, + RequestAccountCreateWithSecretKey, + RequestAccountExportPrivateKey, + RequestAccountMeta, + RequestAddInjectedAccounts, + RequestApproveConnectWalletSession, + RequestApproveWalletConnectNotSupport, + RequestAuthorization, + RequestAuthorizationBlock, + RequestAuthorizationPerAccount, + RequestAuthorizationPerSite, + RequestAuthorizeApproveV2, + RequestBatchRestoreV2, + RequestBondingSubmit, + RequestCameraSettings, + RequestCampaignBannerComplete, + RequestChangeEnableChainPatrol, + RequestChangeLanguage, + RequestChangeMasterPassword, + RequestChangeShowBalance, + RequestChangeShowZeroBalance, + RequestChangeTimeAutoLock, + RequestCheckPublicAndSecretKey, + RequestConfirmationComplete, + RequestConnectWalletConnect, + RequestCrossChainTransfer, + RequestDeleteContactAccount, + RequestDeriveCreateMultiple, + RequestDeriveCreateV2, + RequestDeriveCreateV3, + RequestDeriveValidateV2, + RequestDisconnectWalletConnectSession, + RequestEditContactAccount, + RequestFindRawMetadata, + RequestForgetSite, + RequestFreeBalance, + RequestGetDeriveAccounts, + RequestGetTransaction, + RequestJsonRestoreV2, + RequestKeyringExportMnemonic, + RequestMaxTransferable, + RequestMigratePassword, + RequestParseEvmContractInput, + RequestParseTransactionSubstrate, + RequestPassPhishingPage, + RequestQrParseRLP, + RequestQrSignEvm, + RequestQrSignSubstrate, + RequestRejectConnectWalletSession, + RequestRejectExternalRequest, + RequestRejectWalletConnectNotSupport, + RequestRemoveInjectedAccounts, + RequestResetWallet, + RequestResolveExternalRequest, + RequestSaveRecentAccount, + RequestSeedCreateV2, + RequestSeedValidateV2, + RequestSettingsType, + RequestSigningApprovePasswordV2, + RequestStakePoolingBonding, + RequestStakePoolingUnbonding, + RequestSubscribeHistory, + RequestSubstrateNftSubmitTransaction, + RequestTransfer, + RequestTransferCheckReferenceCount, + RequestTransferCheckSupporting, + RequestTransferExistentialDeposit, + RequestTuringCancelStakeCompound, + RequestTuringStakeCompound, + RequestUnbondingSubmit, + RequestUnlockKeyring, + RequestUnlockType, + ResolveAddressToDomainRequest, + ResolveDomainRequest, + ResponseAccountCreateSuriV2, + ResponseAccountCreateWithSecretKey, + ResponseAccountExportPrivateKey, + ResponseAccountMeta, + ResponseChangeMasterPassword, + ResponseCheckPublicAndSecretKey, + ResponseDeriveValidateV2, + ResponseFindRawMetadata, + ResponseGetDeriveAccounts, + ResponseKeyringExportMnemonic, + ResponseMigratePassword, + ResponseParseEvmContractInput, + ResponseParseTransactionSubstrate, + ResponsePrivateKeyValidateV2, + ResponseQrParseRLP, + ResponseQrSignEvm, + ResponseQrSignSubstrate, + ResponseRejectExternalRequest, + ResponseResetWallet, + ResponseResolveExternalRequest, + ResponseSeedCreateV2, + ResponseSeedValidateV2, + ResponseSubscribeHistory, + ResponseUnlockKeyring, + StakingTxErrorType, + StakingType, + SupportTransferResponse, + ThemeNames, + TransactionHistoryItem, + TransactionResponse, + TransferTxErrorType, + ValidateNetworkRequest, + ValidateNetworkResponse, + ValidatorInfo +} from '@subwallet/extension-base/background/KoniTypes'; import RequestBytesSign from '@subwallet/extension-base/background/RequestBytesSign'; import RequestExtrinsicSign from '@subwallet/extension-base/background/RequestExtrinsicSign'; import { AccountAuthType, AccountJson, AuthorizeRequest, MessageTypes, MetadataRequest, RequestAccountChangePassword, RequestAccountCreateExternal, RequestAccountCreateHardware, RequestAccountCreateSuri, RequestAccountEdit, RequestAccountExport, RequestAccountForget, RequestAccountShow, RequestAccountTie, RequestAccountValidate, RequestAuthorizeCancel, RequestAuthorizeReject, RequestBatchRestore, RequestCurrentAccountAddress, RequestDeriveCreate, RequestDeriveValidate, RequestJsonRestore, RequestMetadataApprove, RequestMetadataReject, RequestSeedCreate, RequestSeedValidate, RequestSigningApproveSignature, RequestSigningCancel, RequestTypes, ResponseAccountExport, ResponseAuthorizeList, ResponseDeriveValidate, ResponseJsonGetAccountInfo, ResponseSeedCreate, ResponseSeedValidate, ResponseSigning, ResponseType, SigningRequest, WindowOpenParams } from '@subwallet/extension-base/background/types'; @@ -3963,6 +4109,29 @@ export default class KoniExtension { return this.#koniState.sign('https://booka.games', new RequestExtrinsicSign(request), { address, ...pair.meta }); } + private async remarkWithEvent (request: RemarkWithEvent): Promise { + const address = request.address; + const networkKey = request.networkKey; + const apiProps = this.#koniState.getSubstrateApi(networkKey); + if (!apiProps) { + return; + } + const transaction = apiProps.api.tx.system.remarkWithEvent(request.dataRemark); + const rs = await this.#koniState.transactionService.handleTransaction({ + address: address, + chain: networkKey, + transaction: transaction, + extrinsicType: ExtrinsicType.REMARK_WITH_EVENT, + chainType: ChainType.SUBSTRATE, + resolveOnDone: true, + data: {} + }); + + return rs; + + return rs; + } + // -------------------------------------------------------------- // eslint-disable-next-line @typescript-eslint/require-await public async handle (id: string, type: TMessageType, request: RequestTypes[TMessageType], port: chrome.runtime.Port): Promise> { @@ -4273,6 +4442,9 @@ export default class KoniExtension { return this.evmNftSubmitTransaction(request as NftTransactionRequest); case 'pri(substrateNft.submitTransaction)': return this.substrateNftSubmitTransaction(request as RequestSubstrateNftSubmitTransaction); + /// Remark + case 'pri(remark.remarkWithEvent)': + return this.remarkWithEvent(request as RemarkWithEvent); /// Transfer case 'pri(accounts.transfer)': diff --git a/packages/extension-base/src/services/chain-service/index.ts b/packages/extension-base/src/services/chain-service/index.ts index 6781d797b1..5bb5db754b 100644 --- a/packages/extension-base/src/services/chain-service/index.ts +++ b/packages/extension-base/src/services/chain-service/index.ts @@ -26,7 +26,8 @@ const forceChainInfoMap = (() => { const enableList = [ 'polkadot', 'goldberg_testnet', - 'kusama' + 'kusama', + 'alephTest' ]; return Object.fromEntries(enableList.map((slug) => { diff --git a/packages/extension-koni-ui/src/Popup/Confirmations/index.tsx b/packages/extension-koni-ui/src/Popup/Confirmations/index.tsx index 0a35114a44..1581590871 100644 --- a/packages/extension-koni-ui/src/Popup/Confirmations/index.tsx +++ b/packages/extension-koni-ui/src/Popup/Confirmations/index.tsx @@ -232,6 +232,7 @@ const Component = function ({ className }: Props) { case ExtrinsicType.CROWDLOAN: case ExtrinsicType.EVM_EXECUTE: case ExtrinsicType.UNKNOWN: + case ExtrinsicType.REMARK_WITH_EVENT: return t('Transaction confirm'); } } else { diff --git a/packages/extension-koni-ui/src/Popup/Confirmations/variants/Transaction/index.tsx b/packages/extension-koni-ui/src/Popup/Confirmations/variants/Transaction/index.tsx index ba40ef17b1..727c382f63 100644 --- a/packages/extension-koni-ui/src/Popup/Confirmations/variants/Transaction/index.tsx +++ b/packages/extension-koni-ui/src/Popup/Confirmations/variants/Transaction/index.tsx @@ -74,6 +74,7 @@ const getTransactionComponent = (extrinsicType: ExtrinsicType): typeof BaseTrans case ExtrinsicType.STAKING_CANCEL_COMPOUNDING: case ExtrinsicType.STAKING_COMPOUNDING: case ExtrinsicType.EVM_EXECUTE: + case ExtrinsicType.REMARK_WITH_EVENT: case ExtrinsicType.UNKNOWN: return BaseTransactionConfirmation; } 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 16e14c7650..e9e2432f30 100644 --- a/packages/extension-koni-ui/src/Popup/Home/Mission/TaskItem.tsx +++ b/packages/extension-koni-ui/src/Popup/Home/Mission/TaskItem.tsx @@ -1,41 +1,124 @@ // Copyright 2019-2022 @subwallet/extension-ui authors & contributors // SPDX-License-Identifier: Apache-2.0 +import { SWTransactionResponse } from '@subwallet/extension-base/services/transaction-service/types'; import CountDown from '@subwallet/extension-koni-ui/components/Common/CountDown'; import { GamePoint } from '@subwallet/extension-koni-ui/components/Games/Logo'; import { BookaSdk } from '@subwallet/extension-koni-ui/connector/booka/sdk'; -import { Task } from '@subwallet/extension-koni-ui/connector/booka/types'; +import { Task, TaskHistoryStatus } from '@subwallet/extension-koni-ui/connector/booka/types'; import { TelegramConnector } from '@subwallet/extension-koni-ui/connector/telegram'; -import { useSetCurrentPage, useTranslation } from '@subwallet/extension-koni-ui/hooks'; +import { useNotification, useSetCurrentPage, useTranslation } from '@subwallet/extension-koni-ui/hooks'; import { ThemeProps } from '@subwallet/extension-koni-ui/types'; import { formatInteger } from '@subwallet/extension-koni-ui/utils'; +import { actionTaskOnChain } from '@subwallet/extension-koni-ui/utils/game/task'; import { Button, Icon, Image, Typography } from '@subwallet/react-ui'; import CN from 'classnames'; import { CheckCircle } from 'phosphor-react'; -import React, { useCallback, useState } from 'react'; +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 telegramConnector = TelegramConnector.instance; - -const _TaskItem = ({ className, task }: Props): React.ReactElement => { +const _TaskItem = ({ className, task, actionReloadPoint }: Props): React.ReactElement => { useSetCurrentPage('/home/mission'); + const notify = useNotification(); + const [account, setAccount] = useState(apiSDK.account); const [taskLoading, setTaskLoading] = useState(false); const { t } = useTranslation(); - const completed = !!task.completedAt; + const [completed, setCompleted] = useState(!!task.completedAt); + const [checking, setChecking] = useState(task.status === TaskHistoryStatus.CHECKING); + + useEffect(() => { + let taskItemUpdaterInterval: NodeJS.Timer; + + if (checking) { + taskItemUpdaterInterval = setInterval(() => { + apiSDK.completeTask(task.taskHistoryId) + .then((data: boolean) => { + if (data) { + // @ts-ignore + clearInterval(taskItemUpdaterInterval); + setCompleted(true); + setChecking(false); + actionReloadPoint(); + } + }) + .catch(console.error); + }, 10000); + } + + return () => clearInterval(taskItemUpdaterInterval); + }, [checking]); + + useEffect(() => { + const accountSub = apiSDK.subscribeAccount().subscribe((data) => { + setAccount(data); + }); + + return () => { + accountSub.unsubscribe(); + }; + }, []); - const finishTask = useCallback(() => { + const finishTask = useCallback(async () => { const taskId = task.id; + const onChainType = task.onChainType; + const { address } = account?.info || {}; + + if (!address) { + return; + } setTaskLoading(true); + let res: SWTransactionResponse | null = null; + const networkKey = 'alephTest'; + + if (onChainType) { + const now = new Date(); + const date = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`; + const data = JSON.stringify({ address, type: onChainType, date }); + + res = await actionTaskOnChain(onChainType, 'alephTest', address, data); + + if ((res && res.errors.length > 0) || !res) { + setTaskLoading(false); + let message = t(`Network ${networkKey} not enable`); + if (res && res.errors.length > 0) { + const error = res?.errors[0] || {}; + // @ts-ignore + message = error?.message || ''; + } + + notify({ + message: message, + type: 'error' + }); - apiSDK.finishTask(taskId) + return; + } + } + + let extrinsicHash = ''; + + if (res) { + extrinsicHash = res.extrinsicHash || ''; + } + + apiSDK.finishTask(taskId, extrinsicHash, networkKey) .finally(() => { setTaskLoading(false); + + if (onChainType) { + setChecking(true); + } else { + setCompleted(true); + actionReloadPoint(); + } }) .catch(console.error); @@ -108,7 +191,7 @@ const _TaskItem = ({ className, task }: Props): React.ReactElement => { } - {!completed && } - {completed &&