@@ -5,7 +5,7 @@ import { MTX } from 'hsd/lib/primitives';
5
5
import { connect } from 'react-redux' ;
6
6
import { showSuccess } from '../../ducks/notifications' ;
7
7
import { claimPaidTransfer } from '../../ducks/names' ;
8
- import { waitForPassphrase } from '../../ducks/walletActions' ;
8
+ import { waitForPassphrase , hasAddress } from '../../ducks/walletActions' ;
9
9
10
10
@connect (
11
11
( state ) => ( {
@@ -15,6 +15,7 @@ import { waitForPassphrase } from '../../ducks/walletActions';
15
15
showSuccess : ( message ) => dispatch ( showSuccess ( message ) ) ,
16
16
claimPaidTransfer : ( hex ) => dispatch ( claimPaidTransfer ( hex ) ) ,
17
17
waitForPassphrase : ( ) => dispatch ( waitForPassphrase ( ) ) ,
18
+ hasAddress : ( address ) => dispatch ( hasAddress ( address ) ) ,
18
19
} ) ,
19
20
)
20
21
export default class ClaimNameForPayment extends Component {
@@ -23,27 +24,36 @@ export default class ClaimNameForPayment extends Component {
23
24
this . state = {
24
25
step : 0 ,
25
26
hex : '' ,
27
+ isConfirming : false ,
26
28
} ;
27
29
}
28
30
29
- onClickVerify = ( ) => {
31
+ onClickVerify = async ( ) => {
30
32
try {
31
- const { network} = this . props ;
33
+ const { network, hasAddress } = this . props ;
32
34
const mtx = MTX . decode ( Buffer . from ( this . state . hex , 'hex' ) ) ;
33
35
const firstOutput = mtx . outputs [ 0 ] ;
34
36
const nameReceiveAddr = firstOutput . address . toString ( network ) ;
35
37
const name = firstOutput . covenant . items [ 2 ] . toString ( 'ascii' ) ;
36
38
const secondOutput = mtx . outputs [ 1 ] ;
37
39
const fundingAddr = secondOutput . address . toString ( network ) ;
38
40
const price = secondOutput . value ;
41
+ const isOwn = await hasAddress ( nameReceiveAddr ) ;
39
42
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
+ }
47
57
} catch ( e ) {
48
58
this . setState ( {
49
59
hexError : 'Invalid hex value.' ,
0 commit comments