Skip to content

Commit

Permalink
fix: issues - 237、238 (#2789)
Browse files Browse the repository at this point in the history
* fix: issue 238

* fix: issue 237

* fix
  • Loading branch information
devchenyan authored Aug 4, 2023
1 parent 34fff73 commit 0ab3583
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
position: absolute;
top: 0px;
right: 0px;
border-radius: 16px;
}

.balanceValue {
Expand Down
12 changes: 10 additions & 2 deletions packages/neuron-ui/src/components/PricePanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,19 @@ const PricePanel: React.FunctionComponent<PricePanelProps> = ({
setFeeRateValueArray(res)
})
} else {
useGetBatchGeneratedTx({ walletID, items: send.outputs, priceArray }).then(res => {
useGetBatchGeneratedTx({ walletID, items: send.outputs, priceArray, isSendMax: send.isSendMax }).then(res => {
setFeeRateValueArray(res)
})
}
}, [send.outputs, priceArray, isExperimental, experimental, batchGenerateExperimental, setFeeRateValueArray])
}, [
send.outputs,
send.isSendMax,
priceArray,
isExperimental,
experimental,
batchGenerateExperimental,
setFeeRateValueArray,
])

useEffect(() => {
if (suggestFeeRate === 0) {
Expand Down
25 changes: 19 additions & 6 deletions packages/neuron-ui/src/components/Send/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,15 @@ export const useGetBatchGeneratedTx = async ({
walletID,
priceArray = [],
items,
isSendMax,
}: {
walletID: string
priceArray?: string[]
items: Readonly<State.Output[]>
isSendMax: boolean
}) => {
const getUpdateGeneratedTx = (params: Controller.GenerateTransactionParams) =>
generateTx(params).then((res: ControllerResponse<State.Transaction>) => {
(isSendMax ? generateSendingAllTx : generateTx)(params).then((res: ControllerResponse<State.Transaction>) => {
if (res.status === 1) {
return (res as SuccessFromController).result
}
Expand Down Expand Up @@ -333,6 +335,17 @@ export const useInitialize = (
[items, isSendMax, sending]
)

const updateIsSendMax = useCallback(
(payload: boolean) => {
setIsSendMax(payload)
dispatch({
type: AppActions.UpdateSendIsSendMax,
payload,
})
},
[dispatch, setIsSendMax]
)

const updateTransactionOutput = useUpdateTransactionOutput(dispatch)
const onItemChange = useOnItemChange(updateTransactionOutput)
const addTransactionOutput = useAddTransactionOutput(dispatch)
Expand All @@ -355,22 +368,22 @@ export const useInitialize = (
t,
}).then(tx => {
if (!tx) {
setIsSendMax(false)
updateIsSendMax(false)
}
})
}, [walletID, updateTransactionOutput, price, items, dispatch, t, isMainnet])
}, [walletID, updateTransactionOutput, price, items, dispatch, t, isMainnet, updateIsSendMax])

const onSendMaxClick = useCallback(() => {
if (!isSendMax) {
setIsSendMax(true)
updateIsSendMax(true)
updateSendingAllTransaction()
} else {
setIsSendMax(false)
updateIsSendMax(false)
updateTransactionOutput('amount')(outputs.length - 1)('')
const total = outputsToTotalAmount(items.filter(item => item.amount))
setTotalAmount(total)
}
}, [updateSendingAllTransaction, setIsSendMax, isSendMax, outputs.length, updateTransactionOutput, items])
}, [updateSendingAllTransaction, updateIsSendMax, isSendMax, outputs.length, updateTransactionOutput, items])

useEffect(() => {
if (isSendMax) {
Expand Down
4 changes: 2 additions & 2 deletions packages/neuron-ui/src/components/Send/send.module.scss
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@import '../../styles/mixin.scss';
$bottomHeight: 124px;
$bottomHeight: 84px;
$headerHeight: 104px;

.content {
overflow-y: scroll;
margin-bottom: 100px;
margin-bottom: 60px;
height: calc(100vh - $headerHeight - $bottomHeight);
}

Expand Down
1 change: 1 addition & 0 deletions packages/neuron-ui/src/states/init/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const appState: State.App = {
price: INIT_SEND_PRICE,
description: '',
generatedTx: null,
isSendMax: false,
},
passwordRequest: {
actionType: null,
Expand Down
6 changes: 6 additions & 0 deletions packages/neuron-ui/src/states/stateProvider/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export enum AppActions {
UpdateSendOutput = 'updateSendOutput',
UpdateSendPrice = 'updateSendPrice',
UpdateSendDescription = 'updateSendDescription',
UpdateSendIsSendMax = 'updateSendIsSendMax',
UpdateGeneratedTx = 'updateGeneratedTx',
ClearSendState = 'clearSendState',
UpdateMessage = 'updateMessage',
Expand Down Expand Up @@ -72,6 +73,7 @@ export type StateAction =
| { type: AppActions.UpdateSendOutput; payload: { idx: number; item: Partial<State.Output> } }
| { type: AppActions.UpdateSendPrice; payload: string }
| { type: AppActions.UpdateSendDescription; payload: string }
| { type: AppActions.UpdateSendIsSendMax; payload: boolean }
| { type: AppActions.UpdateGeneratedTx; payload: State.GeneratedTx | null }
| { type: AppActions.ClearSendState }
| { type: AppActions.UpdateMessage; payload: any }
Expand Down Expand Up @@ -275,6 +277,10 @@ export const reducer = produce((state: Draft<State.AppWithNeuronWallet>, action:
state.app.send.description = action.payload
break
}
case AppActions.UpdateSendIsSendMax: {
state.app.send.isSendMax = action.payload
break
}
case AppActions.UpdateGeneratedTx: {
state.app.send.generatedTx = action.payload || null
break
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-ui/src/types/App/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ declare namespace State {
price: string
description: string
generatedTx: GeneratedTx | null
isSendMax: boolean
}

interface Popup {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
.dropdown-control {
position: relative;
overflow: hidden;
background-color: var(--secondary-background-color);
border: 1px solid var(--divide-line-color);
border-radius: 8px;
box-sizing: border-box;
Expand Down Expand Up @@ -42,7 +41,7 @@

.dropdown-menu {
background-color: var(--secondary-background-color);
box-shadow: 0px 1px 4px #EEEEEE;
box-shadow: 0px 1px 4px #eeeeee;
border-radius: 8px;
@media (prefers-color-scheme: dark) {
box-shadow: none;
Expand Down

2 comments on commit 0ab3583

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packaging for test is done in 5761216998

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packaging for test is done in 5761218083

Please sign in to comment.