Skip to content

Commit

Permalink
fix: address review points
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Sep 25, 2020
1 parent ff77a95 commit 6526686
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 40 deletions.
19 changes: 4 additions & 15 deletions app/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,21 @@ import {
Transaction,
TransactionResults,
MempoolTransaction,
AccountBalance,
} from '@blockstack/stacks-blockchain-sidecar-types';

const api = 'https://sidecar.staging.blockstack.xyz/sidecar';

//
// TODO: move to sidecar repo, should be documented there
export interface AddressBalanceResponse {
stx: {
balance: string;
total_sent: string;
total_received: string;
};
fungible_tokens: any;
non_fungible_tokens: any;
}

async function getAddressBalance(address: string) {
return await axios.get<AddressBalanceResponse>(api + `/v1/address/${address}/balances`);
return axios.get<AccountBalance>(api + `/v1/address/${address}/balances`);
}

async function getAddressTransactions(address: string) {
return await axios.get<TransactionResults>(api + `/v1/address/${address}/transactions`);
return axios.get<TransactionResults>(api + `/v1/address/${address}/transactions`);
}

async function getTxDetails(txid: string) {
return await axios.get<Transaction | MempoolTransaction>(api + `/v1/tx/${txid}`);
return axios.get<Transaction | MempoolTransaction>(api + `/v1/tx/${txid}`);
}

export const Api = {
Expand Down
2 changes: 1 addition & 1 deletion app/crypto/create-stx-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface CreateStxTxArgs {
export async function createStxTransaction({ mnemonic, recipient, amount }: CreateStxTxArgs) {
const rootNode = await deriveRootKeychainFromMnemonic(mnemonic);
const { privateKey } = deriveStxAddressKeychain(rootNode);
return await makeSTXTokenTransfer({
return makeSTXTokenTransfer({
recipient,
amount: new BN(amount.toString()),
senderKey: privateKey,
Expand Down
14 changes: 4 additions & 10 deletions app/modals/receive-stx/receive-stx-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, useState } from 'react';
import React, { FC } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import Qr from 'qrcode.react';
import { Text, Modal, Button, Flex, Box, useClipboard } from '@blockstack/ui';
Expand All @@ -13,13 +13,7 @@ interface ReceiveStxModalProps {
export const ReceiveStxModal: FC<ReceiveStxModalProps> = ({ address }) => {
const dispatch = useDispatch();
const modalOpen = useSelector(selectReceiveModalOpen);
const copyAddressToClipboard = useClipboard(address);
const [buttonText, setButtonText] = useState('Copy address');
const onCopyAddress = () => {
copyAddressToClipboard.onCopy();
setButtonText('Copied');
setTimeout(() => setButtonText('Copy address'), 800);
};
const { hasCopied, onCopy } = useClipboard(address);
const closeModal = () => dispatch(homeActions.closeReceiveModal());
if (!modalOpen) return null;
return (
Expand Down Expand Up @@ -55,8 +49,8 @@ export const ReceiveStxModal: FC<ReceiveStxModalProps> = ({ address }) => {
{address}
</Text>
</Flex>
<Button variant="link" mt="tight" mb="loose" onClick={onCopyAddress}>
{buttonText}
<Button variant="link" mt="tight" mb="loose" onClick={onCopy}>
{hasCopied ? 'Copied' : 'Copy address'}
</Button>
</Flex>
</Modal>
Expand Down
1 change: 0 additions & 1 deletion app/modals/transaction/transaction-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export const TransactionModal: FC<TxModalProps> = ({ balance, address }) => {
.number()
.positive('You cannot send a negative amount of STX')
.typeError('Amount of STX must be described as number')
.min(1, 'Smallest transaction is 1 STX')
.test(
'test-has-less-than-or-equal-to-6-decimal-places',
'STX cannot have more than 6 decimal places',
Expand Down
2 changes: 1 addition & 1 deletion app/pages/onboarding/03-restore-wallet/restore-wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const RestoreWallet: React.FC = () => {
setError('The Stacks Wallet can only be used with a 24-word Secret Key');
return;
}
const [error] = await safeAwait(deriveRootKeychainFromMnemonic(mnemonic, ''));
const [error] = await safeAwait(deriveRootKeychainFromMnemonic(mnemonic));
if (error) {
setError('Not a valid bip39 mnemonic');
return;
Expand Down
3 changes: 1 addition & 2 deletions app/pages/sign-in/sign-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import { decryptWallet, selectKeysSlice } from '../../store/keys';
export const SignIn: React.FC = () => {
const history = useHistory();
const dispatch = useDispatch();
// const [password, setPassword] = useState<string | null>(null);
const [password, setPassword] = useState<string | null>('980aa096dd224bd69685583b363de2be');
const [password, setPassword] = useState<string | null>(null);
const [hasSubmitted, setHasSubmitted] = useState(false);
const keysState = useSelector(selectKeysSlice);

Expand Down
5 changes: 3 additions & 2 deletions app/store/address/address.actions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Dispatch } from '../index';
import { createAction } from '@reduxjs/toolkit';
import { AccountBalance } from '@blockstack/stacks-blockchain-sidecar-types';
import { safeAwait } from '@blockstack/ui';

import { Api, AddressBalanceResponse } from '../../api/api';
import { Api } from '../../api/api';

export const fetchAddress = createAction('address/fetch-address');
export const fetchAddressDone = createAction<AddressBalanceResponse>('address/fetch-address-done');
export const fetchAddressDone = createAction<AccountBalance>('address/fetch-address-done');
export const fetchAddressFail = createAction('address/fetch-address-fail');

export function getAddressDetails(address: string) {
Expand Down
2 changes: 1 addition & 1 deletion app/store/address/address.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface AddressState {

const initialState: AddressState = {
// balance: null,
balance: '100900',
balance: '1000000000001',
};

export const addressReducer = createReducer(initialState, builder =>
Expand Down
23 changes: 23 additions & 0 deletions app/store/transaction/transaction.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,29 @@ export const broadcastTx = createAction('transactions/broadcast-transactions');
export const broadcastTxDone = createAction('transactions/broadcast-transactions-done');
export const broadcastTxFail = createAction('transactions/broadcast-transactions-fail');

export function broadcastStxTransaction({ tx }: { tx: StacksTransaction }) {
return async (dispatch: Dispatch, getState: () => RootState) => {
const [error, blockchainResponse] = await safeAwait(broadcastTransaction(tx, stacksNetwork));

if (error || !blockchainResponse) return null;
console.log({ error });
// anything but string of id === error
console.log(blockchainResponse);
if (typeof blockchainResponse !== 'string') {
// setError for ui
return;
}
// dispatch(
// addPendingTransaction({
// txId: pendingTxId as string,
// amount: amount.toString(),
// time: +new Date(),
// })
// );
// return blockchainResponse;
};
}

export async function openInExplorer(txId: string) {
return await shell.openExternal(
`https://testnet-explorer.blockstack.org/txid/${txId}?wallet=true`
Expand Down
4 changes: 2 additions & 2 deletions app/utils/disk-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const store = new Store({
schema: {
salt: {
type: 'string',
maxLength: 29,
minLength: 29,
// maxLength: 29,
// minLength: 29,
},
encryptedMnemonic: {
type: 'string',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"@babel/register": "7.10.5",
"@blockstack/eslint-config": "1.0.5",
"@blockstack/prettier-config": "0.0.6",
"@blockstack/stacks-blockchain-sidecar-types": "0.0.20",
"@blockstack/stacks-blockchain-sidecar-types": "0.0.21",
"@commitlint/config-conventional": "9.0.1",
"@types/argon2-browser": "1.12.0",
"@types/bcryptjs": "2.4.2",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1750,10 +1750,10 @@
"@blockstack/stacks-transactions" "0.3.0-alpha.5"
cross-fetch "^3.0.4"

"@blockstack/stacks-blockchain-sidecar-types@0.0.20":
version "0.0.20"
resolved "https://registry.yarnpkg.com/@blockstack/stacks-blockchain-sidecar-types/-/stacks-blockchain-sidecar-types-0.0.20.tgz#d84e13dc56a2573707ba88dcb043ab7481d4e91d"
integrity sha512-bEoUh8eyYAempTj48KaF+94ecmXXfYsALlT7eqwhhivIPv+069IcYSGoLK0pvcACKLV6gyomBSu4dv7B+r5fuw==
"@blockstack/stacks-blockchain-sidecar-types@0.0.21":
version "0.0.21"
resolved "https://registry.yarnpkg.com/@blockstack/stacks-blockchain-sidecar-types/-/stacks-blockchain-sidecar-types-0.0.21.tgz#f6027560120380ffaec5afb27d926f7a2c67c0e7"
integrity sha512-5g1XHA1Ov6QUOp7iCXF6s9eZMM+toLJ7WoUcGOoMG9A/rIc5JPXKUuJ+LSLODWPO2X3nd7f+6LECwIJcLZqIEA==

"@blockstack/stacks-transactions@0.3.0-alpha.5":
version "0.3.0-alpha.5"
Expand Down

0 comments on commit 6526686

Please sign in to comment.