|
1 | 1 | import React from "react";
|
2 | 2 | import ZfApi from "react-foundation-apps/src/utils/foundation-api";
|
3 | 3 | import Translate from "react-translate-component";
|
4 |
| -import {ChainStore} from "bitsharesjs"; |
| 4 | +import {ChainStore, FetchChain} from "bitsharesjs"; |
5 | 5 | import AmountSelector from "../Utility/AmountSelectorStyleGuide";
|
6 | 6 | import FeeAssetSelector from "../Utility/FeeAssetSelector";
|
7 | 7 | import AccountStore from "stores/AccountStore";
|
@@ -168,19 +168,47 @@ class SendModal extends React.Component {
|
168 | 168 | });
|
169 | 169 | }
|
170 | 170 |
|
| 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 | + |
171 | 199 | _initForm() {
|
172 |
| - if (this.props.to_name != this.props.from_name) { |
| 200 | + if (this.props.to_name !== this.props.from_name) { |
173 | 201 | 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 |
176 | 203 | });
|
| 204 | + this.fetchToAccount(this.props.to_name); |
177 | 205 | }
|
178 | 206 |
|
179 | 207 | if (this.props.from_name) {
|
180 | 208 | 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 |
183 | 210 | });
|
| 211 | + this.fetchFromAccount(this.props.from_name); |
184 | 212 | }
|
185 | 213 |
|
186 | 214 | let {currentAccount} = this.props;
|
@@ -225,13 +253,15 @@ class SendModal extends React.Component {
|
225 | 253 | ) {
|
226 | 254 | this.setState({
|
227 | 255 | from_name: np.from_name,
|
228 |
| - from_account: ChainStore.getAccount(np.from_name), |
229 | 256 | to_name: np.to_name ? np.to_name : "",
|
230 |
| - to_account: np.to_name |
231 |
| - ? ChainStore.getAccount(np.to_name) |
232 |
| - : null, |
233 | 257 | feeAmount: getUninitializedFeeAmount()
|
234 | 258 | });
|
| 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 | + } |
235 | 265 | }
|
236 | 266 | }
|
237 | 267 |
|
|
0 commit comments