Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor send asset function code #405

Merged
merged 4 commits into from
Dec 10, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions app/modules/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,19 @@ export const sendTransaction = (sendAddress: string, sendAmount: string, symbol:

const isHardwareSend = !!publicKey
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better check for this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can define the type of the login? Feels like this condition is only known to us..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that makes sense. I will incorporate those changes for the ledger login page as well


// TODO: Consolidate this
const asyncSigningFunction = isHardwareSend ? signingFunction : null
const publicKeyOrWif = isHardwareSend ? publicKey : wif

let sendAssetFn
if (isHardwareSend) {
dispatch(showInfoNotification({ message: 'Please sign the transaction on your hardware device', autoDismiss: 0 }))
if (symbol === ASSETS.NEO || symbol === ASSETS.GAS) {
sendAssetFn = () => api.neonDB.doSendAsset(net, sendAddress, publicKey, sendAsset, signingFunction)
} else {
const scriptHash = getScriptHashForNetwork(net, symbol)
sendAssetFn = () => api.nep5.doTransferToken(net, scriptHash, publicKey, sendAddress, adjustDecimalAmountForTokenTransfer(parsedSendAmount), 0, signingFunction)
}
if (symbol === ASSETS.NEO || symbol === ASSETS.GAS) {
sendAssetFn = () => api.neonDB.doSendAsset(net, sendAddress, publicKeyOrWif, sendAsset, asyncSigningFunction)
} else {
if (symbol === ASSETS.NEO || symbol === ASSETS.GAS) {
sendAssetFn = () => api.neonDB.doSendAsset(net, sendAddress, wif, sendAsset)
} else {
const scriptHash = getScriptHashForNetwork(net, symbol)
sendAssetFn = () => api.nep5.doTransferToken(net, scriptHash, wif, sendAddress, adjustDecimalAmountForTokenTransfer(parsedSendAmount))
}
const scriptHash = getScriptHashForNetwork(net, symbol)
sendAssetFn = () => api.nep5.doTransferToken(net, scriptHash, publicKeyOrWif, sendAddress, adjustDecimalAmountForTokenTransfer(parsedSendAmount), 0, asyncSigningFunction)
}

if (isHardwareSend) dispatch(showInfoNotification({ message: 'Please sign the transaction on your hardware device', autoDismiss: 0 }))

const [err, response] = await asyncWrap(sendAssetFn())
if (err || response.result === undefined || response.result === false) {
console.log(err)
Expand Down