Skip to content

Commit

Permalink
[transactions] Fix change address for mixed sends (#3553)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlyp authored Sep 17, 2021
1 parent d7461a8 commit 03d712b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
27 changes: 26 additions & 1 deletion app/actions/ControlActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ export const getNextAddressAttempt = (accountNumber) => (dispatch, getState) =>
});
});

export const GETNEXTCHANGEADDRESS_ATTEMPT = "GETNEXTCHANGEADDRESS_ATTEMPT";
export const GETNEXTCHANGEADDRESS_FAILED = "GETNEXTCHANGEADDRESS_FAILED";
export const GETNEXTCHANGEADDRESS_SUCCESS = "GETNEXTCHANGEADDRESS_SUCCESS";

export const getNextChangeAddressAttempt = () => (dispatch, getState) =>
new Promise((resolve, reject) => {
const changeAccount = sel.getChangeAccount(getState());
dispatch({ type: GETNEXTCHANGEADDRESS_ATTEMPT });
return wallet
.getNextAddress(sel.walletService(getState()), changeAccount)
.then((res) => {
res.accountNumber = changeAccount;
dispatch({
getNextChangeAddressResponse: res,
type: GETNEXTCHANGEADDRESS_SUCCESS
});
resolve(res);
})
.catch((error) => {
dispatch({ error, type: GETNEXTCHANGEADDRESS_FAILED });
reject(error);
});
});

export const RENAMEACCOUNT_ATTEMPT = "RENAMEACCOUNT_ATTEMPT";
export const RENAMEACCOUNT_FAILED = "RENAMEACCOUNT_FAILED";
export const RENAMEACCOUNT_SUCCESS = "RENAMEACCOUNT_SUCCESS";
Expand Down Expand Up @@ -692,7 +716,8 @@ export const constructTransactionAttempt = (
dispatch({ error, type: CONSTRUCTTX_FAILED });
};
}
const newChangeAddress = sel.nextAddress(getState());
await dispatch(getNextChangeAddressAttempt());
const newChangeAddress = sel.nextChangeAddress(getState());
change = { address: newChangeAddress };
}
}
Expand Down
22 changes: 22 additions & 0 deletions app/reducers/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import {
GETNEXTADDRESS_ATTEMPT,
GETNEXTADDRESS_FAILED,
GETNEXTADDRESS_SUCCESS,
GETNEXTCHANGEADDRESS_ATTEMPT,
GETNEXTCHANGEADDRESS_FAILED,
GETNEXTCHANGEADDRESS_SUCCESS,
RENAMEACCOUNT_ATTEMPT,
RENAMEACCOUNT_FAILED,
RENAMEACCOUNT_SUCCESS,
Expand Down Expand Up @@ -118,6 +121,25 @@ export default function control(state = {}, action) {
getNextAddressRequestAttempt: false,
getNextAddressResponse: action.getNextAddressResponse
};
case GETNEXTCHANGEADDRESS_ATTEMPT:
return {
...state,
getNextChangeAddressError: null,
getNextChangeAddressRequestAttempt: true
};
case GETNEXTCHANGEADDRESS_FAILED:
return {
...state,
getNextChangeAddressError: String(action.error),
getNextChangeAddressRequestAttempt: false
};
case GETNEXTCHANGEADDRESS_SUCCESS:
return {
...state,
getNextChangeAddressError: "",
getNextChangeAddressRequestAttempt: false,
getNextChangeAddressResponse: action.getNextChangeAddressResponse
};
case RENAMEACCOUNT_ATTEMPT:
return {
...state,
Expand Down
9 changes: 9 additions & 0 deletions app/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,15 @@ export const defaultSpendingAccount = createSelector(
accounts.find(compose(eq(mixedAccount || 0), get("value")))
);

const getNextChangeAddressResponse = get([
"control",
"getNextChangeAddressResponse"
]);
export const nextChangeAddress = compose(
get("address"),
getNextChangeAddressResponse
);

export const defaultSpendingAccountDisregardMixedAccount = createSelector(
[visibleAccounts],
(accounts) => accounts.find(compose(eq(0), get("value")))
Expand Down
2 changes: 1 addition & 1 deletion scripts/dexsite.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var exec = require('child_process').exec;
var os = require('os');

if (os.type() === 'Linux' || os.type() === 'Darwin' )
exec("rm -rf bin/site && cp -R ./node_modules/dcrdex-assets/dexc/site bin/");
exec("rm -rf bin/site && cp -R ./node_modules/dcrdex-assets/dexc/site bin/");
else if (os.type() === 'Windows_NT')
exec("rd /s /q \"bin/site\" && Xcopy /E /I \"./node_modules/dcrdex-assets/dexc/site\" \"bin/site\"");
else
Expand Down

0 comments on commit 03d712b

Please sign in to comment.