Skip to content

Commit

Permalink
fix: webpack serve
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie authored and edu-stx committed Jan 5, 2023
1 parent 40c51a9 commit 3dbce0a
Show file tree
Hide file tree
Showing 33 changed files with 561 additions and 1,339 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18

- name: Cache node_modules
uses: actions/cache@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/create-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18

- name: Cache node_modules
id: cache
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18

- name: Cache node_modules
id: cache
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/debug-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
access_token: ${{ secrets.GITHUB_TOKEN }}

- name: Check out Git repository
uses: actions/checkout@v1
uses: actions/checkout@v2

- name: Add required Linux dependencies
uses: ./.github/actions/linux-deps
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18

- uses: actions/setup-python@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/exact-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18

- name: Add @actions/core
uses: nick-invision/retry@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18

- name: Cache node_modules
id: cache
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

steps:
- name: Check out Git repository
uses: actions/checkout@v1
uses: actions/checkout@v2

- uses: actions/cache@v2
id: cache-node-modules
Expand All @@ -35,7 +35,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18

- name: Add required Linux dependencies
uses: ./.github/actions/linux-deps
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
#
# Windows build breaks when using the package.json script to install `app/` packages
# using separate run to install those packages separately
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18

- name: Install dependencies
uses: nick-invision/retry@v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const TransactionListItem: FC<TransactionListItemProps> = props => {
txWithEvents.stx_received
);

const inMicroblock = tx.is_unanchored;
const inMicroblock = (tx as any).is_unanchored;

const txFailed =
tx.tx_status === 'abort_by_response' || tx.tx_status === 'abort_by_post_condition';
Expand Down Expand Up @@ -115,7 +115,7 @@ export const TransactionListItem: FC<TransactionListItemProps> = props => {
tx.token_transfer.memo.replace('0x', '').replace(/^(0{2})+|(0{2})+$/g, ''),
'hex'
).toString('utf8');
const txDate = new Date(tx.burn_block_time_iso || tx.parent_burn_block_time_iso);
const txDate = new Date(tx.burn_block_time_iso || (tx as any).parent_burn_block_time_iso);
const txDateShort = txDate.toLocaleString();

const containerRef = useRef<HTMLButtonElement>(null);
Expand Down
6 changes: 3 additions & 3 deletions app/components/tx-signing/sign-transaction-software.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ export const SignTransactionSoftware: React.FC<SignTransactionSoftwareProps> = p
const { createSoftwareContractCallTx } = useCreateSoftwareContractCallTx();

const createSoftwareWalletTx = useCallback(async () => {
const { privateKey } = await decryptWallet(password);
const { stxPrivateKey } = await decryptWallet(password);
blastUndoStackToRemovePasswordFromMemory(inputRef.current);
if ('recipient' in txOptions) {
return createSoftwareWalletTokenTransferTx({ privateKey, txOptions });
return createSoftwareWalletTokenTransferTx({ privateKey: stxPrivateKey, txOptions });
}
return createSoftwareContractCallTx({ privateKey, txOptions });
return createSoftwareContractCallTx({ privateKey: stxPrivateKey, txOptions });
}, [decryptWallet, password, createSoftwareContractCallTx, txOptions]);

return (
Expand Down
6 changes: 6 additions & 0 deletions app/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TransactionVersion } from '@stacks/transactions';
import { whenNetwork } from '@utils/network-utils';
import packageJson from '../../package.json';
import { stxToMicroStx } from '../utils/unit-convert';
Expand Down Expand Up @@ -79,6 +80,11 @@ export const DEFAULT_POLLING_INTERVAL = 10_000;

export const SEND_MANY_CONTACT_ID = 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.send-many-memo';

export const TRANSACTION_VERSION = whenNetwork({
mainnet: TransactionVersion.Mainnet,
testnet: TransactionVersion.Testnet,
});

export const features = {
stacking: true,
lifetimeRewards: false,
Expand Down
4 changes: 0 additions & 4 deletions app/crypto/derive-address-keychain.ts

This file was deleted.

5 changes: 4 additions & 1 deletion app/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { whenNetwork } from './utils/network-utils';

export { ChainID };

export const chain = whenNetwork<ChainID>({ testnet: ChainID.Testnet, mainnet: ChainID.Mainnet });
export const chain = whenNetwork<ChainID>({
testnet: ChainID.Testnet,
mainnet: ChainID.Mainnet,
});

export const stacksNetwork = whenNetwork<StacksNetwork>({
mainnet: new StacksMainnet(),
Expand Down
22 changes: 20 additions & 2 deletions app/hooks/use-create-ledger-contract-call-tx.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import { useCallback } from 'react';
import { useSelector } from 'react-redux';
import { LedgerError } from '@zondax/ledger-blockstack';
import { bytesToHex } from '@stacks/common';

import { RootState } from '@store/index';
import {
ContractCallOptions,
createMessageSignature,
deserializeTransaction,
makeUnsignedContractCall,
makeUnsignedSTXTokenTransfer,
SingleSigSpendingCondition,
TokenTransferOptions,
} from '@stacks/transactions';
import { selectPublicKey } from '@store/keys';
import { selectCoreNodeInfo, selectPoxInfo } from '@store/stacking';

function signTransactionWithSignature(transaction: string, signatureVRS: string) {
const deserialzedTx = deserializeTransaction(transaction);
const spendingCondition = createMessageSignature(signatureVRS);
(deserialzedTx.auth.spendingCondition as SingleSigSpendingCondition).signature =
spendingCondition;
return deserialzedTx;
}

function useCreateLedgerTxFactory(
method: typeof makeUnsignedContractCall | typeof makeUnsignedSTXTokenTransfer
) {
Expand All @@ -27,17 +39,23 @@ function useCreateLedgerTxFactory(

if (!poxInfo) throw new Error('`poxInfo` or `stacksApp` is not defined');

console.log({ publicKey: publicKey.toString('hex') });

const unsignedTx = await method({
...options,
publicKey: publicKey.toString('hex'),
} as any);

const resp = await main.ledger.signTransaction(unsignedTx.serialize().toString('hex'));
const resp = await main.ledger.signTransaction(bytesToHex(unsignedTx.serialize()));

if (resp.returnCode !== LedgerError.NoErrors) {
throw new Error('Ledger responded with errors');
}
return unsignedTx.createTxWithSignature(resp.signatureVRS);
console.log('xxxxxxxxx', resp);
return signTransactionWithSignature(
bytesToHex(unsignedTx.serialize()),
resp.signatureVRS as unknown as string
);
},
[coreNodeInfo, method, poxInfo, publicKey]
);
Expand Down
16 changes: 7 additions & 9 deletions app/hooks/use-stacking-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@ import { useMemo } from 'react';
import { useSelector } from 'react-redux';
import { StackingClient } from '@stacks/stacking';

import { stacksNetwork } from 'app/environment';
import { RootState } from '@store/index';
import { selectActiveNodeApi } from '@store/stacks-node';
import { selectActiveStacksNetwork } from '@store/stacks-node';
import { selectAddress } from '@store/keys';

export function useStackingClient() {
const { node, address } = useSelector((state: RootState) => ({
node: selectActiveNodeApi(state),
const { network, address } = useSelector((state: RootState) => ({
network: selectActiveStacksNetwork(state),
address: selectAddress(state),
}));
const stackingClient = useMemo(() => {
const network = stacksNetwork;
network.coreApiUrl = node.url;
return new StackingClient(address || '', network as any);
}, [node.url, address]);
const stackingClient = useMemo(
() => new StackingClient(address || '', network),
[address, network]
);

return { stackingClient };
}
2 changes: 1 addition & 1 deletion app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const queryClient = new QueryClient({

const { store, persistor } = configureStore();

const AppContainer = CONFIG.PLAIN_HMR ? Fragment : ReactHotAppContainer;
const AppContainer = (CONFIG.PLAIN_HMR ? Fragment : ReactHotAppContainer) as unknown as any;

document.addEventListener('DOMContentLoaded', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down
5 changes: 2 additions & 3 deletions app/main.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,16 @@ const createWindow = async () => {
disableBlinkFeatures: 'Auxclick',
spellcheck: false,
webSecurity: true,
sandbox: false,
nodeIntegration: false,
nodeIntegrationInWorker: false,
nodeIntegrationInSubFrames: false,
enableRemoteModule: false,
worldSafeExecuteJavaScript: true,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js'),
},
});

if (process.platform === 'darwin') mainWindow.setTrafficLightPosition({ x: 10, y: 28 });
if (process.platform === 'darwin') mainWindow.setTrafficLightPosition({ x: 10, y: 14 });

mainWindowState.manage(mainWindow);

Expand Down
3 changes: 2 additions & 1 deletion app/main/register-context-menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export function registerIpcContextMenuHandlers(window: BrowserWindow) {
return newItem.menu;
});
const contextMenu = Menu.buildFromTemplate(copyMenu);
contextMenu.popup({ window: window.getParentWindow() });
const win = window.getParentWindow();
if (win) contextMenu.popup({ window: win });
}
);
}
5 changes: 2 additions & 3 deletions app/modals/delegated-stacking/delegated-stacking-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useSelector } from 'react-redux';
import { useHistory } from 'react-router-dom';
import { useHotkeys } from 'react-hotkeys-hook';
import { BigNumber } from 'bignumber.js';
import BN from 'bn.js';

import { RootState } from '@store/index';
import routes from '@constants/routes.json';
Expand Down Expand Up @@ -58,12 +57,12 @@ export const DelegatedStackingModal: FC<StackingModalProps> = props => {
console.log(amountToStack.toString());
return {
...stackingClient.getDelegateOptions({
amountMicroStx: new BN(amountToStack.toString()),
amountMicroStx: amountToStack.toString(),
contract: poxInfo.contract_id,
delegateTo: delegateeStxAddress,
untilBurnBlockHeight: burnHeight,
}),
fee: new BN(calcFee(POOLED_STACKING_TX_SIZE_BYTES).toString()),
fee: calcFee(POOLED_STACKING_TX_SIZE_BYTES).toString(),
};
}, [amountToStack, burnHeight, calcFee, delegateeStxAddress, poxInfo, stackingClient]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { FC, useRef } from 'react';
import { useFormik } from 'formik';
import { Input, Text, Button, Flex } from '@stacks/ui';
import { getStxAddress } from '@stacks/wallet-sdk';

import { HomeSelectors } from 'app/tests/features/home.selectors';
import { useDecryptWallet } from '@hooks/use-decrypt-wallet';
Expand All @@ -9,6 +10,7 @@ import { ErrorLabel } from '@components/error-label';
import { ErrorText } from '@components/error-text';
import { delay } from '@utils/delay';
import { blastUndoStackToRemovePasswordFromMemory } from '@utils/blast-undo-stack';
import { TRANSACTION_VERSION } from '@constants/index';

interface RevealStxPasswordFormProps {
onAddressDerived(address: string): void;
Expand All @@ -28,7 +30,8 @@ export const RevealStxPasswordForm: FC<RevealStxPasswordFormProps> = props => {
blastUndoStackToRemovePasswordFromMemory(passwordRef.current);

try {
const { address } = await decryptWallet(values.password);
const account = await decryptWallet(values.password);
const address = getStxAddress({ account, transactionVersion: TRANSACTION_VERSION });
onAddressDerived(address);
} catch (e) {
form.setErrors({ password: 'Unable to decrypt wallet' });
Expand Down
3 changes: 1 addition & 2 deletions app/modals/revoke-delegation/revoke-delegation-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { FC, useState, useCallback, useMemo } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { ContractCallOptions, StacksTransaction } from '@stacks/transactions';
import { useHotkeys } from 'react-hotkeys-hook';
import BN from 'bn.js';

import { selectPoxInfo } from '@store/stacking';
import { PostCoreNodeTransactionsError } from '@stacks/stacks-blockchain-api-types';
Expand Down Expand Up @@ -38,7 +37,7 @@ export const RevokeDelegationModal: FC = () => {
if (!poxInfo) throw new Error('`poxInfo` undefined');
return {
...stackingClient.getRevokeDelegateStxOptions(poxInfo.contract_id),
fee: new BN(calcFee(REVOKE_DELEGATION_TX_SIZE_BYTES).toString()),
fee: calcFee(REVOKE_DELEGATION_TX_SIZE_BYTES).toString(),
};
}, [calcFee, poxInfo, stackingClient]);

Expand Down
10 changes: 6 additions & 4 deletions app/modals/send-stx/send-stx-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { useDispatch } from 'react-redux';
import { useQueryClient } from 'react-query';
import { useFormik } from 'formik';
import * as yup from 'yup';
import BN from 'bn.js';

import { PostCoreNodeTransactionsError } from '@stacks/stacks-blockchain-api-types';
import { BigNumber } from 'bignumber.js';
import { Modal } from '@modals/components/base-modal';
import {
AnchorMode,
MEMO_MAX_LENGTH_BYTES,
StacksTransaction,
TokenTransferOptions,
Expand Down Expand Up @@ -162,10 +163,11 @@ export const SendStxModal: FC<TxModalProps> = ({ address, isOpen }) => {
setTxDetails({
recipient: form.values.recipient,
network: stacksNetwork,
amount: new BN(stxToMicroStx(form.values.amount || 0).toString()),
amount: stxToMicroStx(form.values.amount || 0).toString(),
memo: form.values.memo,
nonce: new BN(nonce),
fee: new BN(fee.toString()),
nonce: nonce,
fee: fee.toString(),
anchorMode: AnchorMode.Any,
});
setLoading(false);
},
Expand Down
Loading

0 comments on commit 3dbce0a

Please sign in to comment.