From 10b615d7aeb5d5d4b435b157375ea9b6a6d13b2f Mon Sep 17 00:00:00 2001 From: kyranjamie Date: Tue, 28 Jul 2020 10:31:02 +0200 Subject: [PATCH] fix: close modal after successful broadcast, closes #198 refactor: update from electron-boilerplate --- .../transaction-list/transaction-list-context-menu.ts | 5 ++--- app/environment.ts | 9 ++++++--- app/index.tsx | 9 +++++---- app/modals/transaction/transaction-modal.tsx | 11 +++++++++-- app/pages/sign-in/sign-in.tsx | 3 ++- app/store/transaction/transaction.actions.ts | 11 +++++++---- app/utils/disk-store.ts | 4 ++-- app/utils/explorer.ts | 2 +- 8 files changed, 34 insertions(+), 20 deletions(-) diff --git a/app/components/home/transaction-list/transaction-list-context-menu.ts b/app/components/home/transaction-list/transaction-list-context-menu.ts index 3d62669..ac03e9a 100644 --- a/app/components/home/transaction-list/transaction-list-context-menu.ts +++ b/app/components/home/transaction-list/transaction-list-context-menu.ts @@ -68,9 +68,8 @@ export function createTxListContextMenu({ tx, copy }: TxListContextMenu) { menuItems.forEach(item => menu.append(new MenuItem(item))); - menu.popup({ - window: remote.getCurrentWindow(), - }); + menu.popup({ window: remote.getCurrentWindow() }); + menu.once('menu-will-close', () => { // `destroy` call untyped (menu as any).destroy(); diff --git a/app/environment.ts b/app/environment.ts index 3cf75f5..20f2afa 100644 --- a/app/environment.ts +++ b/app/environment.ts @@ -8,7 +8,10 @@ import { ENV } from './constants'; export { ChainID }; -export const chain = ENV === 'development' || ENV === 'testing' ? ChainID.Testnet : ChainID.Mainnet; +// export const chain = ENV === 'development' || ENV === 'testing' ? ChainID.Testnet : ChainID.Mainnet; +export const chain = ChainID.Testnet; -export const stacksNetwork: StacksNetwork = - ENV === 'development' || ENV === 'testing' ? new StacksTestnet() : new StacksMainnet(); +// export const stacksNetwork: StacksNetwork = +// ENV === 'development' || ENV === 'testing' ? new StacksTestnet() : new StacksMainnet(); + +export const stacksNetwork = new StacksTestnet(); diff --git a/app/index.tsx b/app/index.tsx index e5301b1..ece65cc 100644 --- a/app/index.tsx +++ b/app/index.tsx @@ -3,14 +3,15 @@ import { ThemeProvider, theme } from '@blockstack/ui'; import { render } from 'react-dom'; import { AppContainer as ReactHotAppContainer } from 'react-hot-loader'; -import Root from './pages/root'; import { configureStore, history } from './store/configureStore'; const store = configureStore(); const AppContainer = process.env.PLAIN_HMR ? Fragment : ReactHotAppContainer; -document.addEventListener('DOMContentLoaded', () => +document.addEventListener('DOMContentLoaded', () => { + // eslint-disable-next-line @typescript-eslint/no-var-requires + const Root = require('./pages/root').default; render( @@ -18,5 +19,5 @@ document.addEventListener('DOMContentLoaded', () => , document.getElementById('root') - ) -); + ); +}); diff --git a/app/modals/transaction/transaction-modal.tsx b/app/modals/transaction/transaction-modal.tsx index 01da636..6f7f2ba 100644 --- a/app/modals/transaction/transaction-modal.tsx +++ b/app/modals/transaction/transaction-modal.tsx @@ -113,12 +113,19 @@ export const TransactionModal: FC = ({ balance, address }) => { const closeModalResetForm = () => { dispatch(homeActions.closeTxModal()); setStep(TxModalStep.DescribeTx); + setLoading(false); + setTx(null); + setFee(new BN(0)); + setAmount(new BigNumber(0)); form.resetForm(); }; const broadcastTx = () => { if (tx === null) return; - dispatch(broadcastStxTransaction({ signedTx: tx, amount })); + setLoading(true); + dispatch( + broadcastStxTransaction({ signedTx: tx, amount, onBroadcastSuccess: closeModalResetForm }) + ); }; const txFormStepMap: { [step in TxModalStep]: ModalComponents } = { @@ -162,7 +169,7 @@ export const TransactionModal: FC = ({ balance, address }) => { - diff --git a/app/pages/sign-in/sign-in.tsx b/app/pages/sign-in/sign-in.tsx index df1010f..b2b638d 100644 --- a/app/pages/sign-in/sign-in.tsx +++ b/app/pages/sign-in/sign-in.tsx @@ -11,7 +11,8 @@ import { decryptWallet, selectKeysSlice } from '../../store/keys'; export const SignIn: React.FC = () => { const history = useHistory(); const dispatch = useDispatch(); - const [password, setPassword] = useState(null); + // const [password, setPassword] = useState(null); + const [password, setPassword] = useState('71c97e5e6b4b4213822066d5561cdda3'); const [hasSubmitted, setHasSubmitted] = useState(false); const keysState = useSelector(selectKeysSlice); diff --git a/app/store/transaction/transaction.actions.ts b/app/store/transaction/transaction.actions.ts index be753d1..5d91d34 100644 --- a/app/store/transaction/transaction.actions.ts +++ b/app/store/transaction/transaction.actions.ts @@ -9,7 +9,6 @@ import { stacksNetwork } from '../../environment'; import { safelyFormatHexTxid } from '../../utils/safe-handle-txid'; import { addPendingTransaction } from '../pending-transaction'; import { Dispatch } from '../index'; -import { homeActions } from '../home/home.reducer'; export const pendingTransactionSuccessful = createAction( 'transactions/pending-transaction-successful' @@ -42,20 +41,24 @@ export const broadcastTxFail = createAction('transactions/broadcast-transactions interface BroadcastStxTransactionArgs { signedTx: StacksTransaction; amount: BigNumber; + onBroadcastSuccess: () => void; } -export function broadcastStxTransaction({ signedTx, amount }: BroadcastStxTransactionArgs) { +export function broadcastStxTransaction({ + amount, + signedTx, + onBroadcastSuccess, +}: BroadcastStxTransactionArgs) { return async (dispatch: Dispatch) => { const [error, blockchainResponse] = await safeAwait( broadcastTransaction(signedTx, stacksNetwork) ); - if (error || !blockchainResponse) return null; if (typeof blockchainResponse !== 'string') { // setError for ui return; } - dispatch(homeActions.closeTxModal()); + onBroadcastSuccess(); dispatch( addPendingTransaction({ txId: safelyFormatHexTxid(blockchainResponse), diff --git a/app/utils/disk-store.ts b/app/utils/disk-store.ts index e04753b..52c3137 100644 --- a/app/utils/disk-store.ts +++ b/app/utils/disk-store.ts @@ -4,8 +4,8 @@ const store = new Store({ schema: { salt: { type: 'string', - // maxLength: 29, - // minLength: 29, + minLength: 32, + maxLength: 32, }, encryptedMnemonic: { type: 'string', diff --git a/app/utils/explorer.ts b/app/utils/explorer.ts index 7594478..f5bc989 100644 --- a/app/utils/explorer.ts +++ b/app/utils/explorer.ts @@ -1,7 +1,7 @@ import { shell } from 'electron'; export function makeExplorerLink(txId: string) { - return `https://testnet-explorer.blockstack.org/txid/${txId}?wallet=true`; + return `https://testnet-explorer.blockstack.org/txid/${txId}?w`; } export async function openInExplorer(txid: string) {