Skip to content

Commit 8606246

Browse files
committed
ui: add confirm modal when paying for someone else name
1 parent 3d86ada commit 8606246

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

app/ducks/walletActions.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ export const fetchWallet = () => async (dispatch, getState) => {
105105
}));
106106
};
107107

108+
export const hasAddress = (address) => async () => {
109+
return walletClient.hasAddress(address);
110+
};
111+
108112
export const revealSeed = (passphrase) => async () => {
109113
return walletClient.revealSeed(passphrase);
110114
};

app/pages/DomainManager/ClaimNameForPayment.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { MTX } from 'hsd/lib/primitives';
55
import { connect } from 'react-redux';
66
import { showSuccess } from '../../ducks/notifications';
77
import { claimPaidTransfer } from '../../ducks/names';
8-
import { waitForPassphrase } from '../../ducks/walletActions';
8+
import { waitForPassphrase, hasAddress } from '../../ducks/walletActions';
99

1010
@connect(
1111
(state) => ({
@@ -15,6 +15,7 @@ import { waitForPassphrase } from '../../ducks/walletActions';
1515
showSuccess: (message) => dispatch(showSuccess(message)),
1616
claimPaidTransfer: (hex) => dispatch(claimPaidTransfer(hex)),
1717
waitForPassphrase: () => dispatch(waitForPassphrase()),
18+
hasAddress: (address) => dispatch(hasAddress(address)),
1819
}),
1920
)
2021
export default class ClaimNameForPayment extends Component {
@@ -23,27 +24,36 @@ export default class ClaimNameForPayment extends Component {
2324
this.state = {
2425
step: 0,
2526
hex: '',
27+
isConfirming: false,
2628
};
2729
}
2830

29-
onClickVerify = () => {
31+
onClickVerify = async () => {
3032
try {
31-
const {network} = this.props;
33+
const {network, hasAddress} = this.props;
3234
const mtx = MTX.decode(Buffer.from(this.state.hex, 'hex'));
3335
const firstOutput = mtx.outputs[0];
3436
const nameReceiveAddr = firstOutput.address.toString(network);
3537
const name = firstOutput.covenant.items[2].toString('ascii');
3638
const secondOutput = mtx.outputs[1];
3739
const fundingAddr = secondOutput.address.toString(network);
3840
const price = secondOutput.value;
41+
const isOwn = await hasAddress(nameReceiveAddr);
3942

40-
this.setState({
41-
step: 1,
42-
name,
43-
nameReceiveAddr,
44-
fundingAddr,
45-
price,
46-
});
43+
if (!isOwn && !this.state.isConfirming) {
44+
this.setState({
45+
isConfirming: true,
46+
hexError: 'Receiving address is not yours. Are you are you want to pay for this name?',
47+
});
48+
} else {
49+
this.setState({
50+
step: 1,
51+
name,
52+
nameReceiveAddr,
53+
fundingAddr,
54+
price,
55+
});
56+
}
4757
} catch (e) {
4858
this.setState({
4959
hexError: 'Invalid hex value.',

0 commit comments

Comments
 (0)