Skip to content

Commit 1c989f7

Browse files
y.kuretsyurakurets
y.kurets
authored and
yurakurets
committed
bitshares#2944. refactoring
1 parent e60b01a commit 1c989f7

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

app/components/Modal/SendModal.jsx

+40-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22
import ZfApi from "react-foundation-apps/src/utils/foundation-api";
33
import Translate from "react-translate-component";
4-
import {ChainStore} from "bitsharesjs";
4+
import {ChainStore, FetchChain} from "bitsharesjs";
55
import AmountSelector from "../Utility/AmountSelectorStyleGuide";
66
import FeeAssetSelector from "../Utility/FeeAssetSelector";
77
import AccountStore from "stores/AccountStore";
@@ -168,19 +168,47 @@ class SendModal extends React.Component {
168168
});
169169
}
170170

171+
fetchToAccount(toName) {
172+
if (!this.state.to_account ||
173+
(this.state.to_account && this.state.to_account.size &&
174+
this.state.to_account.get("name") !== toName)) {
175+
FetchChain("getAccount", toName, false).then(account => {
176+
this.setState({
177+
to_account: account
178+
});
179+
}).catch(err => {
180+
console.log(err);
181+
});
182+
}
183+
}
184+
185+
fetchFromAccount(fromName) {
186+
if (!this.state.from_account ||
187+
(this.state.from_account && this.state.from_account.size &&
188+
this.state.from_account.get("name") !== fromName)) {
189+
FetchChain("getAccount", fromName, false).then(account => {
190+
this.setState({
191+
from_account: account
192+
});
193+
}).catch(err => {
194+
console.log(err);
195+
});
196+
}
197+
}
198+
171199
_initForm() {
172-
if (this.props.to_name != this.props.from_name) {
200+
if (this.props.to_name !== this.props.from_name) {
173201
this.setState({
174-
to_name: this.props.to_name,
175-
to_account: ChainStore.getAccount(this.props.to_name)
202+
to_name: this.props.to_name
176203
});
204+
this.fetchToAccount(this.props.to_name);
177205
}
178206

179207
if (this.props.from_name) {
180208
this.setState({
181-
from_name: this.props.from_name,
182-
from_account: ChainStore.getAccount(this.props.from_name)
209+
from_name: this.props.from_name
183210
});
211+
this.fetchFromAccount(this.props.from_name);
184212
}
185213

186214
let {currentAccount} = this.props;
@@ -225,13 +253,15 @@ class SendModal extends React.Component {
225253
) {
226254
this.setState({
227255
from_name: np.from_name,
228-
from_account: ChainStore.getAccount(np.from_name),
229256
to_name: np.to_name ? np.to_name : "",
230-
to_account: np.to_name
231-
? ChainStore.getAccount(np.to_name)
232-
: null,
233257
feeAmount: getUninitializedFeeAmount()
234258
});
259+
this.fetchFromAccount(np.from_name);
260+
if (np.to_name) {
261+
this.fetchToAccount(np.to_name);
262+
} else {
263+
this.setState({ to_account: null });
264+
}
235265
}
236266
}
237267

0 commit comments

Comments
 (0)