From ded5ffe74c9e241f249c8a8e3fb6df9c085f7ebc Mon Sep 17 00:00:00 2001 From: kyranjamie Date: Mon, 2 Nov 2020 10:55:52 +0100 Subject: [PATCH] fix: faucet requests, improve ci --- .github/workflows/audit.yml | 6 +- .github/workflows/build-release.yml | 71 ++++++++++++------- .github/workflows/build.yml | 6 +- .github/workflows/commitlint.yml | 4 +- .github/workflows/exact-versions.yml | 8 +-- .github/workflows/lint.yml | 6 +- .github/workflows/test.yml | 6 +- app/api/api.ts | 7 +- app/components/beta-notice.tsx | 52 +++++++++----- app/components/home/balance-card.tsx | 56 +++++++++------ app/package.json | 2 +- app/pages/home/home.tsx | 4 +- configs/webpack.config.base.js | 1 + configs/webpack.config.main.prod.babel.js | 2 - configs/webpack.config.renderer.dev.babel.js | 1 + configs/webpack.config.renderer.prod.babel.js | 2 - package.json | 2 +- 17 files changed, 135 insertions(+), 101 deletions(-) diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index 3bedfabd0..223963a46 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -1,10 +1,6 @@ name: Audit -on: - push: - branches: ['release/stacking'] - pull_request: - branches: ['release/stacking'] +on: [push] jobs: audit: diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 16c976023..7d721f82b 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -20,51 +20,66 @@ jobs: NPM_COMMAND: win steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.6.0 + with: + access_token: ${{ secrets.GITHUB_TOKEN }} + - name: Check out Git repository uses: actions/checkout@v1 - - name: Get git commit - id: git-commit - run: echo "::set-output name=sha::$(git rev-parse --short HEAD)" - - - name: Get build date - id: build-date - run: echo "::set-output name=date::$(date)" + - uses: FranzDiebold/github-env-vars-action@v1.2.1 + - name: Print environment variables + run: | + echo "GITHUB_REPOSITORY_SLUG=$GITHUB_REPOSITORY_SLUG" + echo "GITHUB_REPOSITORY_OWNER=$GITHUB_REPOSITORY_OWNER" + echo "GITHUB_REPOSITORY_OWNER_SLUG=$GITHUB_REPOSITORY_OWNER_SLUG" + echo "GITHUB_REPOSITORY_NAME=$GITHUB_REPOSITORY_NAME" + echo "GITHUB_REPOSITORY_NAME_SLUG=$GITHUB_REPOSITORY_NAME_SLUG" + echo "GITHUB_REF_SLUG=$GITHUB_REF_SLUG" + echo "GITHUB_REF_NAME=$GITHUB_REF_NAME" + echo "GITHUB_REF_NAME_SLUG=$GITHUB_REF_NAME_SLUG" + echo "GITHUB_SHA_SHORT=$GITHUB_SHA_SHORT" + echo "GITHUB_SHA=$GITHUB_SHA" + + - name: Variables + id: vars + run: | + echo "::set-output name=version::$(cat package.json | jq -r .version)" + echo "::set-output name=branch_name::$(echo ${GITHUB_REF#refs/heads/})" + echo "::set-output name=pull_request_id::$(echo $GITHUB_REF)" + + # - run: echo "${{github.event.number}} ${{ steps.vars.outputs.branch_name }} ${{ github.event.pull_request.head.sha }} ${{ steps.vars.outputs.sha2 }}" + + # - run: echo "${GITHUB_CONTEXT}" + # env: + # GITHUB_CONTEXT: ${{ toJson(github) }} + + # - run: echo "${GITHUB_CONTEXT}" | jq + # env: + # GITHUB_CONTEXT: ${{ toJson(github) }} - name: Install Node.js, NPM and Yarn uses: actions/setup-node@v1 with: node-version: 10 - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" - - - uses: actions/cache@v2 - id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - name: Install packages run: yarn - - run: echo ${{ matrix.NPM_COMMAND }} - - name: Build releases run: ./node_modules/.bin/cross-env DEBUG_PROD=true yarn package-${{ matrix.NPM_COMMAND }} env: + SHA: ${{ github.event.pull_request.head.sha }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SHA: ${{ steps.git-commit.outputs.sha }} - BUILD_DATE: ${{ steps.build-date.outputs.date }} + PULL_REQUEST: ${{ steps.vars.outputs.pull_request_id }} + BRANCH_NAME: ${{ steps.vars.outputs.branch_name }} - uses: actions/upload-artifact@v2 name: Upload Windows build if: matrix.os == 'windows-latest' with: - name: stacks-wallet-${{ steps.git-commit.outputs.sha }}-windows + name: stacks-wallet-${{ steps.vars.outputs.version }}-windows path: | release/**/*.exe release/**/*.msi @@ -73,19 +88,21 @@ jobs: name: Upload MacOS build if: matrix.os == 'macos-latest' with: - name: stacks-wallet-${{ steps.git-commit.outputs.sha }}-macos + name: stacks-wallet-${{ steps.vars.outputs.version }}-macos path: release/**/*.dmg - uses: actions/upload-artifact@v2 name: Upload Linux build if: matrix.os == 'ubuntu-latest' with: - name: stacks-wallet-${{ steps.git-commit.outputs.sha }}-linux + name: stacks-wallet-${{ steps.vars.outputs.version }}-linux path: | release/**/*.deb release/**/*.rpm - uses: lucasmotta/pull-request-sticky-header@1.0.0 + # Only update it once per build + if: matrix.os == 'macos-latest' with: - header: '> [Download the latest builds](https://github.com/blockstack/stacks-wallet/actions/runs/${{ github.run_id }})' + header: '> [Download the latest builds [${{ steps.vars.outputs.version }}]](https://github.com/blockstack/stacks-wallet/actions/runs/${{ github.run_id }}).' GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b6dda5875..804b1991c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,10 +1,6 @@ name: Build -on: - push: - branches: ['release/stacking'] - pull_request: - branches: ['release/stacking'] +on: [push] jobs: build: diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml index 22ff45e08..5d2bc1a96 100644 --- a/.github/workflows/commitlint.yml +++ b/.github/workflows/commitlint.yml @@ -1,5 +1,7 @@ name: Commitlint -on: [pull_request] + +on: [push] + jobs: lint: runs-on: ubuntu-latest diff --git a/.github/workflows/exact-versions.yml b/.github/workflows/exact-versions.yml index 092c03b45..27e7321b4 100644 --- a/.github/workflows/exact-versions.yml +++ b/.github/workflows/exact-versions.yml @@ -1,9 +1,7 @@ name: Exact versions -on: - push: - branches: [release/stacking] - pull_request: - branches: [release/stacking] + +on: [push] + jobs: check-versions: runs-on: ubuntu-latest diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 337307759..ff1c1babe 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,10 +1,6 @@ name: Linting -on: - push: - branches: ['release/stacking'] - pull_request: - branches: ['release/stacking'] +on: [push] jobs: lint: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a8be1ef1d..77a31db1b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,10 +1,6 @@ name: Testing -on: - push: - branches: ['release/stacking'] - pull_request: - branches: ['release/stacking'] +on: [push] jobs: test: diff --git a/app/api/api.ts b/app/api/api.ts index e3b110461..450fd97fc 100644 --- a/app/api/api.ts +++ b/app/api/api.ts @@ -31,9 +31,12 @@ export class Api { ); } - async getFaucetStx(address: string) { + async getFaucetStx(address: string, stacking?: boolean) { return axios.post( - urljoin(this.baseUrl, `/extended/v1/faucets/stx?address=${address}&stacking=true`) + urljoin( + this.baseUrl, + `/extended/v1/faucets/stx?address=${address}${stacking ? '&stacking=true' : ''}` + ) ); } diff --git a/app/components/beta-notice.tsx b/app/components/beta-notice.tsx index f0ac6fae5..15673f8a1 100644 --- a/app/components/beta-notice.tsx +++ b/app/components/beta-notice.tsx @@ -5,10 +5,12 @@ import { openExternalLink } from '@utils/external-links'; import packageJson from '../../package.json'; const sha = process.env.SHA; -const buildDate = process.env.BUILD_DATE; +const shaShort = sha && sha.substr(0, 7); +const pullRequest = process.env.PULL_REQUEST; +const branchName = process.env.BRANCH_NAME; +const version = packageJson.version; const issueParams = new URLSearchParams(); - const issueTitle = `[${String(packageJson.version)}] Bug: `; const issueLabels = 'bug,reported-from-ui'; const issueBody = ` @@ -21,7 +23,7 @@ const issueBody = ` --> -Bug found testing Stacks Wallet build ${String(sha)}, ${String(buildDate)}. +Bug found testing Stacks Wallet build ${String(shaShort)}, ${String(version)}. `; @@ -30,12 +32,14 @@ issueParams.set('labels', issueLabels); issueParams.set('body', issueBody); const openIssueLink = () => - openExternalLink( - `https://github.com/blockstack/stacks-wallet/issues/new?${issueParams.toString()}` - ); + openExternalLink(`https://github.com/blockstack/stacks-wallet/issues/new?${String(issueParams)}`); + +const openPullRequestLink = () => + openExternalLink(`https://github.com/blockstack/stacks-wallet/pull/${String(pullRequest)}`); export const BetaNotice: FC = () => { - if (!sha && !buildDate) return null; + if (!sha && !version.includes('beta')) return null; + return ( { bottom="base" flexDirection={['column', 'row']} > - + Found a bug? Open an issue - {/* - Commit:{' '} + {pullRequest && branchName && ( - openExternalLink( - `https://github.com/blockstack/stacks-wallet/pull/203/commits/${sha || ''}` - ) - } + cursor="pointer" > - {sha} + {branchName} + + )} + {shaShort && ( + + Commit:{' '} + + openExternalLink(`https://github.com/blockstack/stacks-wallet/commit/${sha || ''}`) + } + > + {shaShort} + - */} - Build date: {buildDate} + )} + [{packageJson.version}] ); }; diff --git a/app/components/home/balance-card.tsx b/app/components/home/balance-card.tsx index 2e532f1aa..93f810fc7 100644 --- a/app/components/home/balance-card.tsx +++ b/app/components/home/balance-card.tsx @@ -1,18 +1,18 @@ import React, { FC, useState } from 'react'; import { Box, Button, Text, ArrowIcon, EncryptionIcon, Flex } from '@blockstack/ui'; -import { features } from '@constants/index'; +import { features, NETWORK } from '@constants/index'; import { toHumanReadableStx } from '@utils/unit-convert'; import { safeAwait } from '@utils/safe-await'; import { delay } from '@utils/delay'; -import { BigNumber } from 'bignumber.js'; +import BN from 'bn.js'; interface BalanceCardProps { balance: string | null; lockedStx?: string; onSelectSend(): void; onSelectReceive(): void; - onRequestTestnetStx(): Promise; + onRequestTestnetStx({ stacking }: { stacking: boolean }): Promise; } export const BalanceCard: FC = props => { @@ -20,13 +20,21 @@ export const BalanceCard: FC = props => { const [requestingTestnetStx, setRequestingTestnetStx] = useState(false); - const requestTestnetStacks = async () => { - setRequestingTestnetStx(true); - await safeAwait(Promise.allSettled([onRequestTestnetStx(), delay(1500)])); + const requestTestnetStacks = async (e: React.MouseEvent) => { + if (NETWORK !== 'testnet') return; + if (e.nativeEvent) setRequestingTestnetStx(true); + const [error] = await safeAwait( + Promise.all([onRequestTestnetStx({ stacking: e.nativeEvent.altKey }), delay(1500)]) + ); + if (error) { + window.alert('Faucet request failed'); + } setRequestingTestnetStx(false); }; - const availableBalance = new BigNumber(balance || 0).minus(lockedStx || 0); + const balanceBN = new BN(balance || 0, 10); + const lockedBN = new BN(lockedStx || 0, 10); + const available = balanceBN.sub(lockedBN); return ( @@ -37,12 +45,12 @@ export const BalanceCard: FC = props => { {balance === null ? 'โ€“' : toHumanReadableStx(balance)} - {features.stacking && lockedStx && ( + {features.stacking && lockedBN.toNumber() !== 0 && ( {toHumanReadableStx(lockedStx || '0')} locked - {toHumanReadableStx(availableBalance.toString())} available + {toHumanReadableStx(available)} available )} @@ -55,18 +63,26 @@ export const BalanceCard: FC = props => { Receive - + + ๐Ÿšฐ + + {requestingTestnetStx ? 'Requesting faucet' : 'Get testnet STX'} + + )} ); diff --git a/app/package.json b/app/package.json index a58c2c9ce..4fc7cf367 100644 --- a/app/package.json +++ b/app/package.json @@ -1,7 +1,7 @@ { "name": "stacks-wallet", "productName": "Stacks Wallet", - "version": "4.0.0-beta.5", + "version": "4.0.0-beta.6", "description": "", "main": "./main.prod.js", "author": { diff --git a/app/pages/home/home.tsx b/app/pages/home/home.tsx index 30d8b24ca..7ea30a946 100644 --- a/app/pages/home/home.tsx +++ b/app/pages/home/home.tsx @@ -137,7 +137,9 @@ export const Home: FC = () => { balance={balance} onSelectSend={() => dispatch(homeActions.openTxModal())} onSelectReceive={() => dispatch(homeActions.openReceiveModal())} - onRequestTestnetStx={async () => new Api(activeNode.url).getFaucetStx(address)} + onRequestTestnetStx={async ({ stacking }) => + new Api(activeNode.url).getFaucetStx(address, stacking) + } /> ); diff --git a/configs/webpack.config.base.js b/configs/webpack.config.base.js index fa566f6cd..6a9230244 100644 --- a/configs/webpack.config.base.js +++ b/configs/webpack.config.base.js @@ -64,6 +64,7 @@ export default { plugins: [ new webpack.EnvironmentPlugin({ NODE_ENV: 'production', + SHA: '', }), new webpack.NamedModulesPlugin(), diff --git a/configs/webpack.config.main.prod.babel.js b/configs/webpack.config.main.prod.babel.js index d931a8445..288de500e 100644 --- a/configs/webpack.config.main.prod.babel.js +++ b/configs/webpack.config.main.prod.babel.js @@ -65,8 +65,6 @@ export default merge.smart(baseConfig, { DEBUG_PROD: false, START_MINIMIZED: false, E2E_BUILD: false, - SHA: process.env.SHA, - BUILD_DATE: process.env.BUILD_DATE, }), ], diff --git a/configs/webpack.config.renderer.dev.babel.js b/configs/webpack.config.renderer.dev.babel.js index aa82b823a..48722ea4a 100644 --- a/configs/webpack.config.renderer.dev.babel.js +++ b/configs/webpack.config.renderer.dev.babel.js @@ -135,6 +135,7 @@ export default merge.smart(baseConfig, { new webpack.EnvironmentPlugin({ NODE_ENV: 'development', STX_NETWORK: 'testnet', + SHA: '', }), new webpack.LoaderOptionsPlugin({ diff --git a/configs/webpack.config.renderer.prod.babel.js b/configs/webpack.config.renderer.prod.babel.js index be46ae913..f4d83c962 100644 --- a/configs/webpack.config.renderer.prod.babel.js +++ b/configs/webpack.config.renderer.prod.babel.js @@ -116,8 +116,6 @@ export default merge.smart(baseConfig, { DEBUG_PROD: false, STX_NETWORK: 'testnet', E2E_BUILD: false, - SHA: process.env.SHA, - BUILD_DATE: process.env.BUILD_DATE, }), new BundleAnalyzerPlugin({ diff --git a/package.json b/package.json index cf9cc25be..6a2abe7c5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "stacks-wallet", "productName": "Stacks Wallet", - "version": "4.0.0-beta.5", + "version": "4.0.0-beta.6", "description": "Stacks Wallet 2.0 โ€” Stacking", "prettier": "@blockstack/prettier-config", "author": {