Skip to content

Commit

Permalink
fix: faucet requests, improve ci
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Nov 2, 2020
1 parent b787dc5 commit ded5ffe
Show file tree
Hide file tree
Showing 17 changed files with 135 additions and 101 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: Audit

on:
push:
branches: ['release/stacking']
pull_request:
branches: ['release/stacking']
on: [push]

jobs:
audit:
Expand Down
71 changes: 44 additions & 27 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
6 changes: 1 addition & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: Build

on:
push:
branches: ['release/stacking']
pull_request:
branches: ['release/stacking']
on: [push]

jobs:
build:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: Commitlint
on: [pull_request]

on: [push]

jobs:
lint:
runs-on: ubuntu-latest
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/exact-versions.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: Linting

on:
push:
branches: ['release/stacking']
pull_request:
branches: ['release/stacking']
on: [push]

jobs:
lint:
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: Testing

on:
push:
branches: ['release/stacking']
pull_request:
branches: ['release/stacking']
on: [push]

jobs:
test:
Expand Down
7 changes: 5 additions & 2 deletions app/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' : ''}`
)
);
}

Expand Down
52 changes: 33 additions & 19 deletions app/components/beta-notice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: <describe issue>`;
const issueLabels = 'bug,reported-from-ui';
const issueBody = `
Expand All @@ -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)}.
`;

Expand All @@ -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 (
<Flex
textStyle="caption.medium"
Expand All @@ -45,24 +49,34 @@ export const BetaNotice: FC = () => {
bottom="base"
flexDirection={['column', 'row']}
>
<Text mr="base" onClick={openIssueLink} textDecoration="underline" cursor="pointer">
<Text mr="base-tight" onClick={openIssueLink} textDecoration="underline" cursor="pointer">
Found a bug? Open an issue
</Text>
{/* <Text mr="base">
Commit:{' '}
{pullRequest && branchName && (
<Text
cursor="pointer"
mr="base-tight"
onClick={openPullRequestLink}
textDecoration="underline"
onClick={() =>
openExternalLink(
`https://github.com/blockstack/stacks-wallet/pull/203/commits/${sha || ''}`
)
}
cursor="pointer"
>
{sha}
{branchName}
</Text>
)}
{shaShort && (
<Text mr="base">
Commit:{' '}
<Text
cursor="pointer"
textDecoration="underline"
onClick={() =>
openExternalLink(`https://github.com/blockstack/stacks-wallet/commit/${sha || ''}`)
}
>
{shaShort}
</Text>
</Text>
</Text> */}
<Text mr="base">Build date: {buildDate}</Text>
)}
<Text mr="base">[{packageJson.version}]</Text>
</Flex>
);
};
56 changes: 36 additions & 20 deletions app/components/home/balance-card.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
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<any>;
onRequestTestnetStx({ stacking }: { stacking: boolean }): Promise<any>;
}

export const BalanceCard: FC<BalanceCardProps> = props => {
const { balance, onSelectReceive, onSelectSend, onRequestTestnetStx, lockedStx } = 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 (
<Box>
Expand All @@ -37,12 +45,12 @@ export const BalanceCard: FC<BalanceCardProps> = props => {
{balance === null ? '–' : toHumanReadableStx(balance)}
</Text>

{features.stacking && lockedStx && (
{features.stacking && lockedBN.toNumber() !== 0 && (
<Flex alignItems="center" mt="tight" color="ink.600" fontSize={['14px', '16px']}>
<EncryptionIcon size="16px" color="#409EF3" display={['none', 'block']} mr="tight" />
<Text>{toHumanReadableStx(lockedStx || '0')} locked</Text>
<Text children="·" mx="base-tight" />
<Text>{toHumanReadableStx(availableBalance.toString())} available</Text>
<Text>{toHumanReadableStx(available)} available</Text>
</Flex>
)}

Expand All @@ -55,18 +63,26 @@ export const BalanceCard: FC<BalanceCardProps> = props => {
<ArrowIcon direction="down" mr="base-tight" />
Receive
</Button>
<Button mode="secondary" size="md" ml="tight" onClick={requestTestnetStacks}>
<Box
mr="extra-tight"
fontSize="18px"
left="-4px"
position="relative"
display={['none', 'none', 'block']}
{NETWORK === 'testnet' && (
<Button
mode="secondary"
size="md"
ml="tight"
isDisabled={requestingTestnetStx}
onClick={e => requestTestnetStacks(e)}
>
🚰
</Box>
{requestingTestnetStx ? 'Requesting faucet' : 'Get testnet STX'}
</Button>
<Box
mr="extra-tight"
fontSize="18px"
left="-4px"
position="relative"
display={['none', 'none', 'block']}
>
🚰
</Box>
{requestingTestnetStx ? 'Requesting faucet' : 'Get testnet STX'}
</Button>
)}
</Box>
</Box>
);
Expand Down
Loading

0 comments on commit ded5ffe

Please sign in to comment.