Skip to content

Commit

Permalink
feat: add debug mode for transaction signing
Browse files Browse the repository at this point in the history
  • Loading branch information
hstove committed Jul 21, 2020
1 parent a205e14 commit 3c66887
Show file tree
Hide file tree
Showing 86 changed files with 3,416 additions and 609 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ module.exports = {
root: true,
reportUnusedDisableDirectives: true,
extends: ['@blockstack/eslint-config'],
parserOptions: {
tsconfigRootDir: __dirname,
project: './tsconfig.json',
}
};
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ dist/
.rts2_cache_umd/
yarn-error.log
.github/workflows/event.json
.npmrc
.npmrc
coverage/
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "root",
"private": true,
"scripts": {
"typecheck": "lerna run typecheck --parallel",
"dev": "yarn lerna exec --parallel 'yarn dev' --scope test-app --scope @blockstack/app",
"typecheck": "lerna run typecheck --parallel --no-bail --stream",
"dev": "NODE_ENV=development yarn lerna exec --parallel 'yarn dev' --scope test-app --scope @blockstack/app",
"bootstrap": "yarn lerna exec --parallel 'yarn'",
"build:libs": "yarn build:ui && yarn build:keychain && yarn build:connect",
"build:ui": "lerna run build --scope @blockstack/ui",
Expand Down Expand Up @@ -39,6 +39,7 @@
"eslint-config-prettier": "^6.11.0",
"eslint-config-react-app": "^5.2.1",
"eslint-plugin-flowtype": "^4.7.0",
"eslint-plugin-import": "^2.21.2 ",
"eslint-plugin-jest": "^23.11.0",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.3",
Expand All @@ -47,14 +48,16 @@
"husky": "^4.2.3",
"lerna": "^3.20.2",
"prettier": "^2.0.5",
"typescript": "^3.8.2"
"typescript": "^3.9.3"
},
"dependencies": {
"@babel/preset-env": "^7.10.3",
"tsdx": "^0.13.2"
},
"resolutions": {
"@blockstack/eslint-config": "^1.0.5",
"@blockstack/prettier-config": "^0.0.6"
"eslint-plugin-import": "2.21.2",
"@blockstack/prettier-config": "^0.0.6",
"buffer": "5.6.0"
}
}
2 changes: 1 addition & 1 deletion packages/app/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ module.exports = {
// testResultsProcessor: null,

// This option allows use of a custom test runner
testRunner: "jest-circus/runner",
testRunner: 'jest-circus/runner',

// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
// testURL: "http://localhost",
Expand Down
20 changes: 12 additions & 8 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,20 @@
"@blockstack/connect": "^2.8.3",
"@blockstack/keychain": "^0.7.5",
"@blockstack/prettier-config": "^0.0.6",
"@blockstack/stacks-transactions": "^0.4.6",
"@blockstack/stats": "^0.7.0",
"@blockstack/ui": "^2.9.5",
"@blockstack/rpc-client": "^0.3.0-alpha.0",
"@blockstack/stacks-transactions": "0.5.1",
"@rehooks/document-title": "^1.0.1",
"@types/react-router-dom": "^5.1.3",
"blockstack": "^19.3.0",
"bignumber.js": "^9.0.0",
"blockstack": "21.0.0",
"bn.js": "^5.1.1",
"buffer": "^5.6.0",
"formik": "^2.1.4",
"history": "^5.0.0-beta.4",
"mdi-react": "^6.7.0",
"preact": "^10.4.0",
"prettier": "^2.0.5",
"react": "^16.13.1",
"react-chrome-redux": "^2.0.0-alpha.5",
"react-dom": "^16.13.1",
Expand All @@ -64,6 +67,7 @@
"@babel/preset-react": "^7.9.4",
"@babel/preset-typescript": "^7.9.0",
"@babel/runtime": "^7.9.2",
"@blockstack/prettier-config": "^0.0.6",
"@pmmmwh/react-refresh-webpack-plugin": "^0.2.0",
"@schemastore/web-manifest": "^0.0.4",
"@types/chrome": "^0.0.104",
Expand Down Expand Up @@ -91,16 +95,13 @@
"playwright": "^1.1.1",
"playwright-chromium": "^1.1.1",
"playwright-core": "^1.1.1",
"playwright-firefox": "^1.1.1",
"playwright-webkit": "^1.1.1",
"prettier": "^2.0.4",
"prettier": "^2.0.5",
"react-dev-utils": "^10.2.0",
"react-refresh": "^0.7.2",
"react-test-renderer": "^16.8.6",
"terser-webpack-plugin": "^2.3.5",
"ts-jest": "^25.2.0",
"ts-loader": "^6.0.4",
"typescript": "3.7.5",
"webpack": "^4.41.6",
"webpack-bundle-analyzer": "^3.6.0",
"webpack-chrome-extension-reloader": "^1.3.0",
Expand All @@ -120,6 +121,9 @@
"prettier": "@blockstack/prettier-config",
"repository": {
"type": "git",
"url": "git://github.com/blockstack/blockstack-app.git"
"url": "git://github.com/blockstack/ux.git"
},
"resolutions": {
"buffer": "5.6.0"
}
}
15 changes: 14 additions & 1 deletion packages/app/src/common/hooks/use-wallet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useSelector } from 'react-redux';
import { useSelector, useDispatch } from 'react-redux';
import {
selectIdentities,
selectCurrentWallet,
Expand All @@ -10,8 +10,10 @@ import { selectSecretKey } from '@store/onboarding/selectors';
import { decrypt } from '@blockstack/keychain';
import { DEFAULT_PASSWORD } from '@store/onboarding/types';
import { useState, useEffect } from 'react';
import { doStoreSeed } from '@store/wallet';

export const useWallet = () => {
const dispatch = useDispatch();
const identities = useSelector(selectIdentities);
const firstIdentity = useSelector(selectFirstIdentity);
const wallet = useSelector(selectCurrentWallet);
Expand All @@ -27,9 +29,20 @@ export const useWallet = () => {
}
};

const updateSTXKeychain = async () => {
if (wallet && !wallet.stacksPrivateKey) {
const decryptedKey = await decrypt(wallet?.encryptedBackupPhrase, DEFAULT_PASSWORD);
dispatch(doStoreSeed(decryptedKey, DEFAULT_PASSWORD));
}
};

useEffect(() => {
void fetchSecretKey();
}, [onboardingSecretKey]);

useEffect(() => {
void updateSTXKeychain();
}, []);

return { identities, firstIdentity, wallet, secretKey, isRestoringWallet, isSignedIn };
};
29 changes: 1 addition & 28 deletions packages/app/src/common/onboarding-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,4 @@ const faqs = (appName: string) => {
];
};

const howDataVaultWorks = [
{
icon: '/assets/images/icon-cross-over-eye.svg',
title: 'Private data storage',
body:
'Normally, companies store your data on their servers for them to keep. Data Vault stores your encrypted data independently from the app, so companies like Nurx (and even Data Vault) can’t have access.',
},
{
icon: '/assets/images/icon-padlock.svg',
title: 'Encryption that’s always on',
body:
'Encryption turns your data into indecipherable text that can be read only using the Secret Key that you control. This keeps everything you do private.',
},
{
icon: '/assets/images/icon-chain-of-blocks.svg',
title: 'Blockchain technology',
body:
'The Secret Key that unlocks your Data Vault is made using blockchain technology. That ensures there is only ever one, and that no one can take it from you. Your data will be private, out of the hands of companies, and only accessible to you.',
},
{
icon: '/assets/images/icon-shapes.svg',
title: 'One Vault works with 100s of apps',
body:
'You’ll only ever have to create one Data Vault to use 100s of other apps like Nurx privately.',
},
];

export { faqs, howDataVaultWorks };
export { faqs };
57 changes: 57 additions & 0 deletions packages/app/src/common/stacks-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { ContractCallArgument, ContractCallArgumentType } from '@blockstack/connect';
import {
uintCV,
intCV,
falseCV,
trueCV,
contractPrincipalCV,
standardPrincipalCV,
bufferCV,
} from '@blockstack/stacks-transactions';
import RPCClient from '@blockstack/rpc-client';
import BigNumber from 'bignumber.js';

export const encodeContractCallArgument = ({ type, value }: ContractCallArgument) => {
switch (type) {
case ContractCallArgumentType.UINT:
return uintCV(value);
case ContractCallArgumentType.INT:
return intCV(value);
case ContractCallArgumentType.BOOL:
if (value === 'false' || value === '0') return falseCV();
else if (value === 'true' || value === '1') return trueCV();
else throw new Error(`Unexpected Clarity bool value: ${JSON.stringify(value)}`);
case ContractCallArgumentType.PRINCIPAL:
if (value.includes('.')) {
const [addr, name] = value.split('.');
return contractPrincipalCV(addr, name);
} else {
return standardPrincipalCV(value);
}
case ContractCallArgumentType.BUFFER:
return bufferCV(Buffer.from(value));
default:
throw new Error(`Unexpected Clarity type: ${type}`);
}
};

export const getRPCClient = () => {
const { origin } = location;
const url = origin.includes('localhost')
? 'http://localhost:3999'
: 'https://sidecar.staging.blockstack.xyz';
return new RPCClient(url);
};

export const stacksValue = ({
value,
fixedDecimals = false,
}: {
value: number;
fixedDecimals?: boolean;
}) => {
const microStacks = new BigNumber(value);
const stacks = microStacks.shiftedBy(-6);
const stxString = fixedDecimals ? stacks.toFormat(6) : stacks.decimalPlaces(6).toFormat();
return `${stxString} STX`;
};
6 changes: 5 additions & 1 deletion packages/app/src/common/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export const USERNAME_SUBMITTED = 'Submit Username';
export const USERNAME_VALIDATION_ERROR = 'Validation Error Username';
export const USERNAME_SUBMIT_SUCCESS = 'Submit Username Success';

export const TRANSACTION_SIGN_START = 'Start Transaction Sign Screen';
export const TRANSACTION_SIGN_SUBMIT = 'Submit Transaction Sign';
export const TRANSACTION_SIGN_ERROR = 'Fail Transaction Sign';

// Nice page names for Mark to see in Mixpanel
export const pageTrackingNameMap = {
[ScreenPaths.CHOOSE_ACCOUNT]: 'Choose Account',
Expand Down Expand Up @@ -53,7 +57,7 @@ export const titleNameMap = {

export const doTrackScreenChange = (
screen: ScreenPaths,
decodedAuthRequest: DecodedAuthRequest | undefined
decodedAuthRequest?: DecodedAuthRequest
) => {
if (titleNameMap[screen]) {
document.title = titleNameMap[screen];
Expand Down
Loading

0 comments on commit 3c66887

Please sign in to comment.