From 96e1d80e13785d8c41ccb42e31c5035ee5201930 Mon Sep 17 00:00:00 2001 From: Zachary Brown Date: Mon, 2 Oct 2023 23:17:59 -0700 Subject: [PATCH 1/7] ci: Don't wait for all builds to finish before creating release --- .github/workflows/build-installers.yml | 47 +++++--------------------- package.json | 2 +- 2 files changed, 9 insertions(+), 40 deletions(-) diff --git a/.github/workflows/build-installers.yml b/.github/workflows/build-installers.yml index 588e727..eb76ea9 100644 --- a/.github/workflows/build-installers.yml +++ b/.github/workflows/build-installers.yml @@ -37,9 +37,6 @@ jobs: intel: [ubuntu-latest] electron-builder-options: --linux electron-builder-unpacked: linux-unpacked - # token-driver-artifact: - # arm: climate-tokenization-chia-linux-arm64 - # intel: climate-tokenization-chia-linux-amd64 executable-extension: '' build-result-pattern: '"climate-wallet"*".deb"' artifact-name: linux @@ -51,9 +48,6 @@ jobs: intel: [macos-latest] electron-builder-options: --macos electron-builder-unpacked: mac - # token-driver-artifact: - # arm: climate-tokenization-chia-macos-arm64 - # intel: climate-tokenization-chia-macos-amd64 executable-extension: '' build-result-pattern: '"Climate Wallet-"*".dmg"' artifact-name: macos @@ -64,8 +58,6 @@ jobs: intel: [windows-latest] electron-builder-options: --windows electron-builder-unpacked: win-unpacked - # token-driver-artifact: - # intel: climate-tokenization-chia-windows-amd64 executable-extension: '.exe' build-result-pattern: '"Climate Wallet Setup "*".exe"' artifact-name: windows @@ -103,19 +95,6 @@ jobs: run: | npm install dmg-license - # - name: download token driver - # env: - # GH_TOKEN: ${{ secrets.GH_READ_REPOS }} - # DESTINATION: extraResources/main${{ matrix.os.executable-extension }} - # run: | - # RUN_ID=$(gh run list --repo chia-network/climate-token-driver --branch ${{ matrix.configuration.token-driver-artifact-ref }} --limit 1 --workflow "Build & Release" --json databaseId --jq '.[0].databaseId') - # gh run download $RUN_ID --repo chia-network/climate-token-driver --name climate-token-driver_${{ matrix.os.matrix }}_${{ matrix.configuration.token-driver-artifact-ref }}_${{ matrix.arch.artifact-name }} --dir downloaded-artifacts/ - # mkdir -p extraResources/ - # # expected to fail if there are multiple files - # mv downloaded-artifacts/* "${DESTINATION}" - # chmod a+x "${DESTINATION}" - # ls -la extraResources/ || true - - name: Download Token Driver Client env: GH_TOKEN: ${{ secrets.GH_READ_REPOS }} @@ -211,6 +190,14 @@ jobs: name: ${{ matrix.os.artifact-name }}-${{ matrix.arch.artifact-name}}-installer path: 'artifacts/*' + - name: Release + uses: softprops/action-gh-release@v0.1.15 + with: + files: artifacts/* + fail_on_unmatched_files: true + target_commitish: ${{ github.sha }} + if: startsWith(github.ref, 'refs/tags/') + # We want to delete this no matter what happened in the previous steps (failures, success, etc) - name: Delete signing keychain if: always() @@ -222,24 +209,6 @@ jobs: needs: - build steps: - - name: Download all artifacts - uses: actions/download-artifact@v3 - with: - path: installers - - - name: Report installers - run: | - ls -lda installers/* || true - echo ==== - ls -lda installers/*/* || true - - - name: Release - uses: softprops/action-gh-release@v0.1.15 - with: - files: installers/*/* - fail_on_unmatched_files: true - target_commitish: ${{ github.sha }} - - name: Get repo name id: repo-name run: | diff --git a/package.json b/package.json index 89e6b7a..45794d8 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "author": "Chia Network (https://chia.net/)", "description": "Climate Wallet for Chia Blockchain", "productName": "Climate Wallet", - "version": "1.1.21", + "version": "1.1.22", "private": true, "homepage": "./", "main": "build/electron/main.js", From c2fd9ba5f84efda3c282ea0baf46d0e1fbc9aa57 Mon Sep 17 00:00:00 2001 From: Zachary Brown Date: Mon, 2 Oct 2023 23:27:10 -0700 Subject: [PATCH 2/7] ci: No need to upload artifacts any longer --- .github/workflows/build-installers.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/build-installers.yml b/.github/workflows/build-installers.yml index eb76ea9..959b13f 100644 --- a/.github/workflows/build-installers.yml +++ b/.github/workflows/build-installers.yml @@ -184,12 +184,6 @@ jobs: sm_code_signing_cert_sha1_hash: ${{ secrets.SM_CODE_SIGNING_CERT_SHA1_HASH }} file: '${{ github.workspace }}/${{ env.INSTALLER_FILE }}' - - name: Upload Installer to artifacts - uses: actions/upload-artifact@v3 - with: - name: ${{ matrix.os.artifact-name }}-${{ matrix.arch.artifact-name}}-installer - path: 'artifacts/*' - - name: Release uses: softprops/action-gh-release@v0.1.15 with: From 642ac906cd525c6330e02abd4fb8331e3b8abe0c Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Tue, 3 Oct 2023 09:06:55 -0400 Subject: [PATCH 3/7] feat: autodetection of tokens on no token screen --- src/pages/NoTokensFound/NoTokensFound.tsx | 38 ++++++++++++++++++++--- src/pages/TokenWallet/TokenSidebar.tsx | 2 +- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/pages/NoTokensFound/NoTokensFound.tsx b/src/pages/NoTokensFound/NoTokensFound.tsx index a125a66..8096709 100644 --- a/src/pages/NoTokensFound/NoTokensFound.tsx +++ b/src/pages/NoTokensFound/NoTokensFound.tsx @@ -1,20 +1,29 @@ -import { useMemo } from 'react' +import { useMemo, useEffect } from 'react' import { Box, Grid } from '@mui/material' import { useNavigate } from 'react-router-dom' -import { useWalletsBalance, useWalletsList } from '@/hooks/wallet' +import { + useCWAddStrayCats, + useWalletsBalance, + useWalletsList, + useWalletState, +} from '@/hooks/wallet' import { useGetAllCWAssets } from '@/hooks/useGetAllCWAssets' +import SyncingStatus from '@/constants/SyncingStatus' import { WalletType } from '@chia/api' import { checkMarketplaceIdentifier } from '@/util/token' import { WalletListItem } from '../../types/WalletType' const NoTokensFound = () => { const navigate = useNavigate() + const { state: walletState } = useWalletState() const { list: wallets, isLoading: isLoadingWallets } = useWalletsList( [WalletType.STANDARD_WALLET, WalletType.CAT], '' ) + const { isLoadingAddStrayCats } = useCWAddStrayCats() + const { data: allCWAssets, isLoading: isLoadingAllCWAssets } = useGetAllCWAssets() @@ -36,9 +45,30 @@ const NoTokensFound = () => { useWalletsBalance(filteredWallets) const isLoading = - isLoadingWallets || isLoadingAllCWAssets || isLoadingWalletsBalance + isLoadingWallets || + isLoadingAllCWAssets || + isLoadingAddStrayCats || + isLoadingWalletsBalance + + useEffect(() => { + // Since most of the hooks in this repo are "hooks" of "hooks", + // Its difficult to use the traditional "pollingInterval" method + // So instead on an interval we are going to redirect to the dashboard + // where it will do a fresh check for climate tokens and redirect back here + // if there are none, where the cycle will continue until tokens are detected. + const interval = setInterval(() => { + console.log('Checking for Climate Tokens') + navigate('/dashboard') + }, 60000) + return () => clearInterval(interval) + }, [isLoading, filteredWallets]) - if (isLoading) { + if ( + isLoading && + walletState === SyncingStatus.SYNCED && + filteredWallets.length !== 0 + ) { + console.log('Climate Tokens Detected') navigate('/dashboard') } diff --git a/src/pages/TokenWallet/TokenSidebar.tsx b/src/pages/TokenWallet/TokenSidebar.tsx index c59082e..1843c5b 100644 --- a/src/pages/TokenWallet/TokenSidebar.tsx +++ b/src/pages/TokenWallet/TokenSidebar.tsx @@ -181,7 +181,7 @@ export default function TokenSidebar() { if ( !isLoading && - sortedWallets.length === 0 && + filteredWallets.length === 0 && walletState === SyncingStatus.SYNCED ) { navigate('/dashboard/wallets/no-token') From de82a55cba913d9739f3ea3d3de82b2fe9784f38 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Tue, 3 Oct 2023 10:29:19 -0400 Subject: [PATCH 4/7] feat: only allow whole number sends --- src/components/transaction/TransactionCATInput.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/transaction/TransactionCATInput.tsx b/src/components/transaction/TransactionCATInput.tsx index bda84f2..5c8e828 100644 --- a/src/components/transaction/TransactionCATInput.tsx +++ b/src/components/transaction/TransactionCATInput.tsx @@ -31,8 +31,8 @@ const TransactionCATInput = () => { fullWidth {...register('amount', { required: true, - pattern: TOKEN_AMOUNT_REGEX, - max: max, + pattern: /^-?\d+$/, + max, })} error={Boolean(errors['amount'])} InputProps={{ @@ -53,7 +53,15 @@ const TransactionCATInput = () => { wallet. ) : ( - Amount input format is error. + <> + {!isNaN(parseFloat(getValues('amount'))) && + isFinite(Number(getValues('amount'))) && + !Number.isInteger(Number(getValues('amount'))) ? ( + Only integers are allowed. + ) : ( + Amount input format is error. + )} + )) } required From 1565cca246de023d8d848fc47c5723500807170f Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Tue, 3 Oct 2023 11:02:49 -0400 Subject: [PATCH 5/7] fix: show validation error when fee amount is greater then wallet balance --- .../transaction/TransactionCATInput.tsx | 6 ++- .../transaction/TransactionFeeInput.tsx | 43 +++++++++++++++++-- src/constants/chia.ts | 1 + src/constants/regex.ts | 2 +- 4 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 src/constants/chia.ts diff --git a/src/components/transaction/TransactionCATInput.tsx b/src/components/transaction/TransactionCATInput.tsx index 5c8e828..d01f01a 100644 --- a/src/components/transaction/TransactionCATInput.tsx +++ b/src/components/transaction/TransactionCATInput.tsx @@ -25,13 +25,17 @@ const TransactionCATInput = () => { const max = (walletBalance?.confirmedWalletBalance ?? 1000) / 1000 + if (isLoadingWalletBalance) { + return null + } + return ( Quantity} fullWidth {...register('amount', { required: true, - pattern: /^-?\d+$/, + pattern: TOKEN_AMOUNT_REGEX, max, })} error={Boolean(errors['amount'])} diff --git a/src/components/transaction/TransactionFeeInput.tsx b/src/components/transaction/TransactionFeeInput.tsx index 76af1ba..d891583 100644 --- a/src/components/transaction/TransactionFeeInput.tsx +++ b/src/components/transaction/TransactionFeeInput.tsx @@ -1,24 +1,49 @@ +import { useMemo } from 'react' import { XCH_FEE_REGEX } from '@/constants/regex' -import { useWallet } from '@/hooks/wallet' +import { useWallet, useWalletsBalance, useWalletsList } from '@/hooks/wallet' import { InputType } from '@/types/SendType' import { Trans } from '@lingui/macro' import { InputAdornment, TextField, Typography } from '@mui/material' -import { useEffect } from 'react' import { useFormContext } from 'react-hook-form' +import { WalletType } from '@chia/api' +import { MOJO_PER_CHIA } from '@/constants/chia' const TransactionFeeInput = () => { const { unit } = useWallet(1) + const { list: wallets, isLoading: isLoadingWallets } = useWalletsList( + [WalletType.STANDARD_WALLET], + '' + ) + + const { isLoading: isLoadingWalletsBalance, data: walletsBalance } = + useWalletsBalance(wallets || []) + const { register, + getValues, formState: { errors }, } = useFormContext>() + const max = useMemo(() => { + const mojoBalance = walletsBalance?.[0] || 0 + + if (!mojoBalance || isNaN(mojoBalance)) { + return 0 + } + + return mojoBalance / MOJO_PER_CHIA + }, [walletsBalance]) + + if (isLoadingWallets || isLoadingWalletsBalance) { + return null + } + return ( Fee} fullWidth - {...register('fee', { required: true, pattern: XCH_FEE_REGEX })} + {...register('fee', { required: true, pattern: XCH_FEE_REGEX, max })} error={Boolean(errors['fee'])} InputProps={{ endAdornment: ( @@ -31,6 +56,18 @@ const TransactionFeeInput = () => { ), }} + helperText={ + Boolean(errors['fee']) && + (Number(getValues('fee')) > max ? ( + + Amount entered is higher than the amount you currently hold. Please + lower the amount so that it is below the number displayed in your + wallet. + + ) : ( + Amount input format is error. + )) + } required /> ) diff --git a/src/constants/chia.ts b/src/constants/chia.ts new file mode 100644 index 0000000..7063444 --- /dev/null +++ b/src/constants/chia.ts @@ -0,0 +1 @@ +export const MOJO_PER_CHIA = 1000000000000 diff --git a/src/constants/regex.ts b/src/constants/regex.ts index 48f737d..8a682cc 100644 --- a/src/constants/regex.ts +++ b/src/constants/regex.ts @@ -1,2 +1,2 @@ -export const TOKEN_AMOUNT_REGEX = /^[0-9]+(.[0-9]{1,3})?$/ +export const TOKEN_AMOUNT_REGEX = /^-?\d+$/ export const XCH_FEE_REGEX = /^[0-9]+(.[0-9]{1,12})?$/ From d5cd8eb2ef10d26d046e2d8d49bb83d2e02a1ae0 Mon Sep 17 00:00:00 2001 From: Zachary Brown Date: Tue, 3 Oct 2023 08:53:00 -0700 Subject: [PATCH 6/7] ci: add back in artifact upload --- .github/workflows/build-installers.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/build-installers.yml b/.github/workflows/build-installers.yml index 959b13f..13041f2 100644 --- a/.github/workflows/build-installers.yml +++ b/.github/workflows/build-installers.yml @@ -192,6 +192,13 @@ jobs: target_commitish: ${{ github.sha }} if: startsWith(github.ref, 'refs/tags/') + # Create aritifacts so we have builds to test from pull requests + - name: Upload Installer to artifacts + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.os.artifact-name }}-${{ matrix.arch.artifact-name}}-installer + path: 'artifacts/*' + # We want to delete this no matter what happened in the previous steps (failures, success, etc) - name: Delete signing keychain if: always() From 12ae9ea70dbf625a4cf3e377ad68f8ab569fa564 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Tue, 3 Oct 2023 13:08:57 -0400 Subject: [PATCH 7/7] feat: rework token types --- src/components/token/TokenType.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/token/TokenType.ts b/src/components/token/TokenType.ts index 402e924..680ee93 100644 --- a/src/components/token/TokenType.ts +++ b/src/components/token/TokenType.ts @@ -1,7 +1,7 @@ export enum TokenType { Default = 0, Send = 1, - Receive = 2, - Detokenize = 2051, - Retire = 2052, + Receive = 0, + Detokenize = 3, + Retire = 2, }