Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
issue_asset(
to_account,
from_account,
asset_id,
amount,
memo,
encrypt_memo = true,
optional_nonce = null
) {
let unlock_promise = WalletUnlockActions.unlock();
return Promise.all([
FetchChain("getAccount", from_account),
FetchChain("getAccount", to_account),
unlock_promise
]).then((res)=> {
let [chain_memo_sender, chain_to] = res;
let memo_from_public, memo_to_public;
if( memo && encrypt_memo ) {
memo_from_public = chain_memo_sender.getIn(["options","memo_key"]);
// The 1s are base58 for all zeros (null)
if( /111111111111111111111/.test(memo_from_public)) {
memo_from_public = null;
}
memo_to_public = chain_to.getIn(["options","memo_key"])
if( /111111111111111111111/.test(memo_to_public)) {
AccountActions.setPasswordAccount(name);
// User registering his own account
if (this.state.registrar_account) {
FetchChain("getAccount", name, undefined, {
[name]: true
}).then(() => {
this.setState({
step: 2,
loading: false
});
this._unlockAccount(name, password);
});
TransactionConfirmStore.listen(this.onFinishConfirm);
} else {
// Account registered by the faucet
FetchChain("getAccount", name, undefined, {
[name]: true
}).then(() => {
this.setState({
step: 2
});
this._unlockAccount(name, password);
});
}
})
.catch(error => {
.then(() => {
// User registering his own account
FetchChain("getAccount", name, undefined, {
[name]: true
}).then(() => {
this.props.continue();
if (this.unmounted) {
return;
}
this.setState({
loading: false
});
});
if (this.state.registrarAccount) {
TransactionConfirmStore.listen(this.onFinishConfirm);
}
})
.catch(error => {
to_account,
amount,
asset,
memo,
broadcast = true,
encrypt_memo = true,
optional_nonce = null,
propose_account = null,
fee_asset_id = "1.3.0"
}) {
let memo_sender = propose_account || from_account;
let unlock_promise = WalletUnlockActions.unlock();
return Promise.all([
FetchChain("getAccount", from_account),
FetchChain("getAccount", to_account),
FetchChain("getAccount", memo_sender),
FetchChain("getAccount", propose_account),
FetchChain("getAsset", asset),
FetchChain("getAsset", fee_asset_id),
unlock_promise
]).then((res)=> {
let [
chain_from, chain_to, chain_memo_sender, chain_propose_account,
chain_asset, chain_fee_asset
] = res;
let memo_from_public, memo_to_public;
if( memo && encrypt_memo ) {
return new Promise(res => {
if (assetID === "1.3.0") {
res(true);
} else {
Promise.all([
estimateFeeAsync(type, options, data),
FetchChain("getAsset", assetID)
])
.then(result => {
const [fee, feeAsset] = result;
res(parseInt(feeAsset.getIn(["dynamic", "fee_pool"]), 10) >= fee);
});
}
});
}
return new Promise((res, rej) => {
FetchChain("getObject", "2.0.0").then(obj => {
res(estimateFee(type, options, obj, data));
}).catch(rej);
});
}
.then(() => {
AccountActions.setPasswordAccount(name);
if (this.state.registrarAccount) {
FetchChain("getAccount", name).then(() => {
this.unlockAccount(name, password);
});
TransactionConfirmStore.listen(this.onFinishConfirm);
} else {
FetchChain("getAccount", name).then(() => {});
this.unlockAccount(name, password);
this.props.history.push("/");
}
})
.catch(error => {
return new Promise((res, rej) => {
Promise.all([
estimateFeeAsync(type, options, data),
checkFeePoolAsync({assetID: feeID, type, options, data}),
FetchChain("getAccount", accountID),
FetchChain("getAsset", "1.3.0"),
feeID !== "1.3.0" ? FetchChain("getAsset", feeID) : null
])
.then(result => {
let [coreFee, hasPoolBalance, account, coreAsset, feeAsset] = result;
let hasBalance = false;
if (feeID === "1.3.0") feeAsset = coreAsset;
let coreBalanceID = account.getIn(["balances", "1.3.0"]),
feeBalanceID = account.getIn(["balances", feeID]);
if (feeID === "1.3.0" && !coreBalanceID) return res({fee: new Asset({amount: coreFee}), hasBalance, hasPoolBalance});
Promise.all([
coreBalanceID ? FetchChain("getObject", coreBalanceID) : null,
feeBalanceID ? FetchChain("getObject", feeBalanceID) : null
])
onFinishConfirm(confirmStoreState) {
if (
confirmStoreState.included &&
confirmStoreState.broadcasted_transaction
) {
TransactionConfirmStore.unlisten(this.onFinishConfirm);
TransactionConfirmStore.reset();
FetchChain("getAccount", this.state.accountName).then(() => {
this.props.history.push(
"/wallet/backup/create?newAccount=true"
);
});
}
}