Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
// SPDX-License-Identifier: MIT
import { action, observable } from 'mobx';
import { post$ } from '@parity/light.js';
import parityStore from './parityStore';
import tokensStore from './tokensStore';
class SendStore {
@observable txStatus; // Status of the tx, see wiki for details
constructor () {
this.api = parityStore.api;
}
acceptRequest = password => {
if (!this.requestId) {
return Promise.reject(
new Error('The requestId has not been generated yet.')
);
}
return this.api.signer.confirmRequest(this.requestId, null, password);
};
postTx = tx => {
if (!tx) {
return;
}
this.setTx(tx);
// Subscribe to this transaction's status
post$(tx).subscribe(txStatus => {
if (txStatus.requested) {
this.requestId = txStatus.requested;
}
this.setTxStatus(txStatus);
});
};
rejectRequest = (requestId, password) => {
if (!this.requestId) {
return Promise.reject(
new Error('The requestId has not been generated yet.')
);
}
return this.api.signer.rejectRequest(this.requestId);
};
setTokenFromAddress = tokenAddress => {
this.token = tokensStore.tokens.get(tokenAddress);
};
setTx = tx => {
this.tx = tx;
};
@action
setTxStatus = txStatus => {
this.txStatus = txStatus;
};
}
export default new SendStore();