Skip to content

Commit

Permalink
Re-throw node not configured error to action class
Browse files Browse the repository at this point in the history
Issue #1
  • Loading branch information
satran004 committed Nov 5, 2020
1 parent 30fcde5 commit ba145a7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,38 @@ public class TransferAction extends AlgoBaseAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getProject();
if(project == null)
if (project == null)
return;

AlgoConsole console = AlgoConsole.getConsole(project);
console.clearAndshow();

TransferDialog transferDialog = new TransferDialog(project);
boolean ok = transferDialog.showAndGet();
try {
TransferDialog transferDialog = new TransferDialog(project);
boolean ok = transferDialog.showAndGet();

if(!ok) {
IdeaUtil.showNotification(project, getTitle(), String.format("%s cancelled", getTxnCommand()), NotificationType.WARNING, null);
return;
}
if (!ok) {
IdeaUtil.showNotification(project, getTitle(), String.format("%s cancelled", getTxnCommand()), NotificationType.WARNING, null);
return;
}

TransferTxnParamEntryForm txnEntryForm = transferDialog.getTransferTxnEntryForm();
Account fromAccount = txnEntryForm.getFromAccount();
Address toAddress = txnEntryForm.getToAccount();
Tuple<BigDecimal, BigInteger> amountTuple = txnEntryForm.getAmount();
if(amountTuple == null) {
IdeaUtil.showNotification(project, getTitle(), "Invalid amount", NotificationType.ERROR, null);
return;
}
TransferTxnParamEntryForm txnEntryForm = transferDialog.getTransferTxnEntryForm();
Account fromAccount = txnEntryForm.getFromAccount();
Address toAddress = txnEntryForm.getToAccount();
Tuple<BigDecimal, BigInteger> amountTuple = txnEntryForm.getAmount();
if (amountTuple == null) {
IdeaUtil.showNotification(project, getTitle(), "Invalid amount", NotificationType.ERROR, null);
return;
}

final AccountAsset asset = txnEntryForm.getAsset();
String assetName = "Algo";
final AccountAsset asset = txnEntryForm.getAsset();
String assetName = "Algo";

if (asset != null) {
assetName = asset.getAssetName();
}
final String finalAssetName = assetName;

if(asset != null) {
assetName = asset.getAssetName();
}
final String finalAssetName = assetName;
try {
TransactionDtlsEntryForm transactionDtlsEntryForm = transferDialog.getTransactionDtlsEntryForm();

TxnDetailsParameters txnDetailsParameters = transactionDtlsEntryForm.getTxnDetailsParameters();
Expand All @@ -84,22 +85,22 @@ public void run(@NotNull ProgressIndicator indicator) {
String amountInDecimal = String.valueOf(amountTuple._1());
//Get formatted amount string
try {
if(transferDialog.isAlgoTransfer()) {
if (transferDialog.isAlgoTransfer()) {
amountInDecimal = AlgoConversionUtil.mAlgoToAlgoFormatted(amountTuple._2());
} else {
amountInDecimal = AlgoConversionUtil.toAssetDecimalAmtFormatted(amountTuple._2(), (int)asset.getDecimals());
amountInDecimal = AlgoConversionUtil.toAssetDecimalAmtFormatted(amountTuple._2(), (int) asset.getDecimals());
}
} catch (Exception e) {

}

if(transferDialog.isAlgoTransfer()) {
if (transferDialog.isAlgoTransfer()) {
status = transactionService.transfer(fromAccount, toAddress.toString(), amountTuple._2().longValue(), txnDetailsParameters);
} else { //asset transfer
status = assetTransactionService.assetTransfer(fromAccount, toAddress.toString(), asset, amountTuple._2(), txnDetailsParameters);
}

if(status) {
if (status) {
console.showInfoMessage(String.format("Successfully transferred %s %s from %s to %s ", amountInDecimal,
finalAssetName, fromAccount.getAddress().toString(), toAddress.toString()));
IdeaUtil.showNotification(project, getTitle(), String.format("%s was successful", getTxnCommand()),
Expand All @@ -109,7 +110,7 @@ public void run(@NotNull ProgressIndicator indicator) {
IdeaUtil.showNotification(project, getTitle(), String.format("%s failed", getTxnCommand()), NotificationType.ERROR, null);
}
} catch (Exception exception) {
if(LOG.isDebugEnabled()) {
if (LOG.isDebugEnabled()) {
LOG.warn(exception);
}

Expand All @@ -126,7 +127,7 @@ public void run(@NotNull ProgressIndicator indicator) {
//deploymentTargetNotConfigured.printStackTrace();
warnDeploymentTargetNotConfigured(project, getTitle());
} catch (Exception ex) {
if(LOG.isDebugEnabled()) {
if (LOG.isDebugEnabled()) {
LOG.error(ex);
}
console.showErrorMessage(ex.getMessage());
Expand All @@ -135,7 +136,6 @@ public void run(@NotNull ProgressIndicator indicator) {
}



public String getTitle() {
return "Transfer Transaction";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bloxbean.algodea.idea.transaction.ui;

import com.bloxbean.algodea.idea.nodeint.service.LogListener;
import com.bloxbean.algodea.idea.nodeint.exception.DeploymentTargetNotConfigured;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.ValidationInfo;
Expand All @@ -14,7 +14,7 @@ public class TransferDialog extends DialogWrapper {
private TransactionDtlsEntryForm transactionDtlsEntryForm;
private JTabbedPane tabbedPane1;

public TransferDialog(@Nullable Project project) {
public TransferDialog(@Nullable Project project) throws DeploymentTargetNotConfigured {
super(project, true);
transferTxnForm.initializeData(project);
transactionDtlsEntryForm.initializeData(project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,19 @@
import com.bloxbean.algodea.idea.account.model.AlgoMultisigAccount;
import com.bloxbean.algodea.idea.account.service.AccountChooser;
import com.bloxbean.algodea.idea.common.Tuple;
import com.bloxbean.algodea.idea.configuration.action.ConfigurationAction;
import com.bloxbean.algodea.idea.nodeint.exception.DeploymentTargetNotConfigured;
import com.bloxbean.algodea.idea.nodeint.model.AccountAsset;
import com.bloxbean.algodea.idea.nodeint.service.AlgoAccountService;
import com.bloxbean.algodea.idea.nodeint.service.LogListenerAdapter;
import com.bloxbean.algodea.idea.toolwindow.AlgoConsole;
import com.bloxbean.algodea.idea.util.AlgoConversionUtil;
import com.bloxbean.algodea.idea.util.IdeaUtil;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.ValidationInfo;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
Expand Down Expand Up @@ -66,14 +60,12 @@ public TransferTxnParamEntryForm() {
enableOtherAssetPanel(false);
}

public void initializeData(Project project) {
public void initializeData(Project project) throws DeploymentTargetNotConfigured {
console = AlgoConsole.getConsole(project);
try {
algoAccountService = new AlgoAccountService(project, new LogListenerAdapter(console));
} catch (DeploymentTargetNotConfigured deploymentTargetNotConfigured) {
IdeaUtil.showNotification(project, "Transfer", "Algorand Node for deployment node is not configured. Click here to configure.",
NotificationType.ERROR, ConfigurationAction.ACTION_ID);
return;
throw deploymentTargetNotConfigured;
}

fromAccChooserBtn.addActionListener(e -> {
Expand Down

0 comments on commit ba145a7

Please sign in to comment.