Skip to content

Commit

Permalink
Send and delegate from correct account
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBenc committed Jan 14, 2021
1 parent 4dfda5e commit 3e80a83
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 51 deletions.
77 changes: 46 additions & 31 deletions app/frontend/actions.ts
Expand Up @@ -373,6 +373,41 @@ export default ({setState, getState}: {setState: SetStateFn; getState: GetStateF
})
}

/* ACCOUNT MODALS */

const showSendTransactionModal = (state, address, title) => {
setState({
sendTransactionTitle: title,
sendAddress: {fieldValue: address},
shouldShowSendTransactionModal: true,
txSuccessTab: '',
keepConfirmationDialogOpen: true,
})
}

const closeSendTransactionModal = (state) => {
setState({
sendAddress: {fieldValue: ''},
sendAmount: {fieldValue: '', coins: 0},
shouldShowSendTransactionModal: false,
})
}

const showDelegationModal = (state, title) => {
setState({
delegationTitle: title,
shouldShowDelegationModal: true,
txSuccessTab: '',
keepConfirmationDialogOpen: true,
})
}

const closeDelegationModal = (state) => {
setState({
shouldShowDelegationModal: false,
})
}

/* TRANSACTION */

const confirmTransaction = async (state, txConfirmType) => {
Expand Down Expand Up @@ -411,6 +446,8 @@ export default ({setState, getState}: {setState: SetStateFn; getState: GetStateF

const cancelTransaction = () => ({
shouldShowConfirmTransactionDialog: false,
shouldShowSendTransactionModal: false,
shouldShowDelegationModal: false,
})

const setRawTransactionOpen = (state, open) => {
Expand Down Expand Up @@ -815,6 +852,9 @@ export default ({setState, getState}: {setState: SetStateFn; getState: GetStateF
stopLoadingAction(state, {})
return
}
setState({
keepConfirmationDialogOpen: true,
})
setTransactionSummary('stake', plan, rewards)
await confirmTransaction(getState(), 'withdraw')
stopLoadingAction(state, {})
Expand Down Expand Up @@ -1001,6 +1041,10 @@ export default ({setState, getState}: {setState: SetStateFn; getState: GetStateF
}

const submitTransaction = async (state) => {
setState({
shouldShowSendTransactionModal: false,
shouldShowDelegationModal: false,
})
if (!state.keepConfirmationDialogOpen) {
setState({
shouldShowConfirmTransactionDialog: false,
Expand Down Expand Up @@ -1190,35 +1234,6 @@ export default ({setState, getState}: {setState: SetStateFn; getState: GetStateF
resetTransactionSummary(newState)
}

const shouldShowSendTransactionModal = (state, address, title) => {
setState({
sendTransactionTitle: title,
sendAddress: {fieldValue: address},
shouldShowSendTransactionModal: true,
})
}

const closeSendTransactionModal = (state) => {
setState({
sendAddress: {fieldValue: ''},
sendAmount: {fieldValue: '', coins: 0},
shouldShowSendTransactionModal: false,
})
}

const shouldShowDelegationModal = (state, title) => {
setState({
delegationTitle: title,
shouldShowDelegationModal: true,
})
}

const closeDelegationModal = (state) => {
setState({
shouldShowDelegationModal: false,
})
}

return {
loadingAction,
stopLoadingAction,
Expand Down Expand Up @@ -1270,9 +1285,9 @@ export default ({setState, getState}: {setState: SetStateFn; getState: GetStateF
openInfoModal,
closeInfoModal,
closePremiumBanner,
shouldShowSendTransactionModal,
showSendTransactionModal,
closeSendTransactionModal,
shouldShowDelegationModal,
showDelegationModal,
closeDelegationModal,
}
}
46 changes: 26 additions & 20 deletions app/frontend/components/pages/accounts/accounts.tsx
Expand Up @@ -16,9 +16,11 @@ const Account = ({
firstAddressPerAccount,
setAccount,
selectedAccount,
shouldShowDelegationModal,
shouldShowSendTransactionModal,
showDelegationModal,
showSendTransactionModal,
}) => {
const isSelected = selectedAccount === i

const Balance = ({value}: {value: Lovelace}) => (
<Fragment>
{printAda(value, 3)}
Expand All @@ -34,23 +36,24 @@ const Account = ({
const SendFromButton = () => (
<button
className="button primary nowrap account-button"
disabled={selectedAccount === i}
onClick={() =>
shouldShowSendTransactionModal(
disabled={isSelected}
onClick={() => {
setAccount(i)
showSendTransactionModal(
firstAddressPerAccount[selectedAccount],
`Send ADA from account ${i} to account ${selectedAccount}`
)
}
}}
>
Send from
</button>
)
const SendToButton = () => (
<button
className="button primary nowrap account-button"
disabled={selectedAccount === i}
disabled={isSelected}
onClick={() =>
shouldShowSendTransactionModal(
showSendTransactionModal(
firstAddressPerAccount[i],
`Send ADA from account ${selectedAccount} to account ${i}`
)
Expand All @@ -62,22 +65,25 @@ const Account = ({
const DelegateButton = () => (
<button
className="button primary nowrap account-button"
onClick={() => shouldShowDelegationModal(`Delegate Account ${i} Stake`)}
onClick={() => {
setAccount(i)
showDelegationModal(`Delegate Account ${i} Stake`)
}}
>
Delegate
</button>
)

return (
<div key={i} className={`card account ${selectedAccount === i ? 'selected' : ''}`}>
<div key={i} className={`card account ${isSelected ? 'selected' : ''}`}>
<div className="header-wrapper mobile">
<h2 className="card-title small-margin">Account {i}</h2>
</div>
<div className="card-column account-button-wrapper">
<h2 className="card-title small-margin account-header desktop">Account {i}</h2>
<button
className="button primary nowrap"
disabled={selectedAccount === i}
disabled={isSelected}
onClick={() => {
setAccount(i)
}}
Expand Down Expand Up @@ -123,10 +129,10 @@ const Account = ({
</div>
</div>
<div className="account-action-buttons desktop">
<div {...tooltip(`Transfer funds from account ${i}`, selectedAccount !== i)}>
<div {...tooltip(`Transfer funds from account ${i}`, !isSelected)}>
<SendFromButton />
</div>
<div {...tooltip(`Transfer funds to account ${i}`, selectedAccount !== i)}>
<div {...tooltip(`Transfer funds to account ${i}`, !isSelected)}>
<SendToButton />
</div>
<div {...tooltip(`Delegate account ${i} stake`, true)}>
Expand All @@ -142,7 +148,7 @@ const Accounts = ({
setAccount,
selectedAccount,
reloadWalletInfo,
showTransactionModal,
showSendTransactionModal,
showDelegationModal,
shouldShowSendTransactionModal,
shouldShowDelegationModal,
Expand Down Expand Up @@ -190,8 +196,8 @@ const Accounts = ({

return (
<Fragment>
{showTransactionModal && <SendTransactionModal />}
{showDelegationModal && <DelegationModal />}
{shouldShowSendTransactionModal && <SendTransactionModal />}
{shouldShowDelegationModal && <DelegationModal />}
<div className="dashboard-column account">
<div className="card account-aggregated">
<div className="balance">
Expand Down Expand Up @@ -232,8 +238,8 @@ const Accounts = ({
firstAddressPerAccount={firstAddressPerAccount}
setAccount={setAccount}
selectedAccount={selectedAccount}
shouldShowSendTransactionModal={shouldShowSendTransactionModal}
shouldShowDelegationModal={shouldShowDelegationModal}
showSendTransactionModal={showSendTransactionModal}
showDelegationModal={showDelegationModal}
/>
)
)}
Expand All @@ -253,8 +259,8 @@ export default connect(
isDemoWallet: state.isDemoWallet,
accounts: state.accounts,
selectedAccount: state.selectedAccount,
showTransactionModal: state.shouldShowSendTransactionModal,
showDelegationModal: state.shouldShowDelegationModal,
shouldShowSendTransactionModal: state.shouldShowSendTransactionModal,
shouldShowDelegationModal: state.shouldShowDelegationModal,
}),
actions
)(Accounts)
2 changes: 2 additions & 0 deletions app/frontend/components/pages/login/keyFileAuth.tsx
Expand Up @@ -82,6 +82,7 @@ class LoadKeyFileClass extends Component<Props, State> {
this.props.loadWallet({
cryptoProviderType: CRYPTO_PROVIDER_TYPES.WALLET_SECRET,
walletSecretDef,
bulkExportPubKeys: true,
})
} catch (e) {
this.props.stopLoadingAction()
Expand Down Expand Up @@ -144,6 +145,7 @@ class LoadKeyFileClass extends Component<Props, State> {
this.props.loadWallet({
cryptoProviderType: CRYPTO_PROVIDER_TYPES.WALLET_SECRET,
walletSecretDef,
bulkExportPubKeys: true,
})
this.setState({keyfileError: undefined})
}
Expand Down
2 changes: 2 additions & 0 deletions app/frontend/components/pages/login/mnemonicAuth.tsx
Expand Up @@ -42,6 +42,7 @@ class LoadByMnemonicSectionClass extends Component<Props> {
await this.props.loadWallet({
cryptoProviderType: CRYPTO_PROVIDER_TYPES.WALLET_SECRET,
walletSecretDef: await mnemonicToWalletSecretDef(sanitizedMnemonic),
bulkExportPubKeys: true,
})
}

Expand Down Expand Up @@ -95,6 +96,7 @@ class LoadByMnemonicSectionClass extends Component<Props> {
cryptoProviderType: CRYPTO_PROVIDER_TYPES.WALLET_SECRET,
// TODO(ppershing): get rid of mnemonic sanitization in this component
walletSecretDef: await mnemonicToWalletSecretDef(sanitizedMnemonic),
bulkExportPubKeys: true,
})
}
{...tooltip(
Expand Down

0 comments on commit 3e80a83

Please sign in to comment.