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

Eg mergeinputs #195

Merged
merged 11 commits into from
Sep 15, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ of the License (see COPYING and COPYING.addendum).
import org.kordamp.ikonli.javafx.FontIcon;
import org.unigrid.janus.model.ExternalVersion;
import org.unigrid.janus.model.signal.Navigate;
import org.unigrid.janus.model.signal.OverlayRequest;

import static org.unigrid.janus.model.signal.Navigate.Location.*;
import org.unigrid.janus.model.signal.UnlockRequest;

Expand All @@ -51,7 +53,8 @@ public class MainWindowController implements Initializable, PropertyChangeListen
@Inject private Wallet wallet;
@Inject private ExternalVersion externalVersion;
@Inject private Event<ExternalVersion> versionEvent;

@Inject
private Event<OverlayRequest> overlayRequest;
@Inject private Event<UnlockRequest> unlockRequestEvent;

// @FXML private Label lblBlockCount;
Expand Down Expand Up @@ -266,7 +269,7 @@ private void onLockPressed(MouseEvent event) {
}

unlockRequestEvent.fire(UnlockRequest.builder().type(UnlockRequest.Type.ORDINARY).build());
pnlOverlay.setVisible(true);
overlayRequest.fire(OverlayRequest.OPEN);
}

@FXML
Expand All @@ -289,13 +292,15 @@ private void onCoinsPressed(MouseEvent event) {
}

unlockRequestEvent.fire(UnlockRequest.builder().type(UnlockRequest.Type.FOR_STAKING).build());
pnlOverlay.setVisible(true);
overlayRequest.fire(OverlayRequest.OPEN);
}

private void eventNavigate(@Observes Navigate navigate) {
switch (navigate.getLocation()) {
case ADDRESS_TAB -> select(pnlAddress, btnAddress);
case WALLET_TAB -> select(pnlWallet, btnWallet);
case ADDRESS_TAB ->
select(pnlAddress, btnAddress);
case WALLET_TAB ->
select(pnlWallet, btnWallet);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ of the License (see COPYING and COPYING.addendum).
import org.unigrid.janus.model.service.RPCService;
import org.unigrid.janus.model.Wallet;
import org.unigrid.janus.model.rpc.entity.UnlockWallet;
import org.unigrid.janus.model.signal.MergeInputsRequest;
import org.unigrid.janus.model.signal.NodeRequest;
import org.unigrid.janus.model.signal.OverlayRequest;
import org.unigrid.janus.model.signal.State;
Expand All @@ -48,35 +49,50 @@ of the License (see COPYING and COPYING.addendum).

@ApplicationScoped
public class OverlayController implements Initializable {
@Inject private DebugService debug;
@Inject private RPCService rpc;
@Inject private Wallet wallet;

@Inject private Event<NodeRequest> nodeRequestEvent;
@Inject private Event<WalletRequest> walletRequestEvent;
@Inject private Event<State> stateEvent;

@FXML private GridPane pnlUnlock;
@FXML private PasswordField passphraseInput;
@FXML private Text errorTxt;
@FXML private ImageView spinnerIcon;
@FXML private Button submitBtn;
@FXML private Text unlockCopy;
@Inject
private DebugService debug;
@Inject
private RPCService rpc;
@Inject
private Wallet wallet;

@Inject
private Event<NodeRequest> nodeRequestEvent;
@Inject
private Event<WalletRequest> walletRequestEvent;
@Inject
private Event<State> stateEvent;
@Inject
private Event<MergeInputsRequest> mergeInputsEvent;
@FXML
private GridPane pnlUnlock;
@FXML
private PasswordField passphraseInput;
@FXML
private Text errorTxt;
@FXML
private ImageView spinnerIcon;
@FXML
private Button submitBtn;
@FXML
private Text unlockCopy;
private UnlockRequest currentUnlockRequest; // Instance variable to store the current UnlockRequest

@Override
public void initialize(URL url, ResourceBundle rb) {
/* Empty on purpose */
}

private void eventUnlockRequest(@Observes UnlockRequest unlockRequest) {
debug.log("Unlock request fired");
debug.print("Unlock request fired", OverlayController.class.getSimpleName());

submitBtn.setText(unlockRequest.getType().getAction());
wallet.setUnlockState(unlockRequest.getType().getState());
//wallet.setUnlockState(unlockRequest.getType().getState());
unlockCopy.setText(unlockRequest.getType().getDescription());
pnlUnlock.setVisible(true);

Platform.runLater(() -> passphraseInput.requestFocus());
currentUnlockRequest = unlockRequest;
}

@FXML
Expand Down Expand Up @@ -104,18 +120,19 @@ private void submit() {
long stakingStartTime = wallet.getStakingStartTime();
stateEvent.fire(State.builder().working(true).build());

// TODO: What exactly do these numbers mean ? Please change this to an enum and explain it.
switch (wallet.getUnlockState()) {
case 1:
UnlockRequest.Type unlockType = currentUnlockRequest.getType();
switch (unlockType) {
case FOR_STAKING:
sendArgs = new Object[]{passphraseInput.getText(), stakingStartTime, true};
break;
case 2:
case ORDINARY:
case FOR_MERGING:
sendArgs = new Object[]{passphraseInput.getText(), 0};
break;
case 3:
case 4:
case 5:
// unlock for 30 seconds only
case FOR_SEND:
case FOR_GRIDNODE:
case FOR_DUMP:
// Unlock for 30 seconds only
sendArgs = new Object[]{passphraseInput.getText(), 30};
break;
default:
Expand All @@ -128,7 +145,8 @@ private void submit() {
stateEvent.fire(State.builder().working(false).build());
} else {
try {
final UnlockWallet call = rpc.call(new UnlockWallet.Request(sendArgs), UnlockWallet.class);
final UnlockWallet call = rpc.call(new UnlockWallet.Request(sendArgs),
UnlockWallet.class);
Jsonb jsonb = JsonbBuilder.create();

if (call.getError() != null) {
Expand All @@ -140,15 +158,15 @@ private void submit() {
passphraseInput.setText("");

debug.print("Error unlocking wallet: ".concat(result),
OverlayController.class.getSimpleName()
);
OverlayController.class.getSimpleName());
}
} else {
errorTxt.setText("Wallet unlocked!");
debug.print("Successfuly unlocked wallet", OverlayController.class.getSimpleName());
debug.print("Successfuly unlocked wallet",
OverlayController.class.getSimpleName());
passphraseInput.setText("");

//TODO: Get rid of these numbers and use an enum instead!
// TODO: Get rid of these numbers and use an enum instead!
if (wallet.getUnlockState() == 3) {
walletRequestEvent.fire(WalletRequest.SEND_TRANSACTION);
} else if (wallet.getUnlockState() == 4) {
Expand All @@ -157,6 +175,15 @@ private void submit() {
walletRequestEvent.fire(WalletRequest.DUMP_KEYS);
}

if (currentUnlockRequest.getType() == UnlockRequest.Type.FOR_MERGING) {
mergeInputsEvent.fire(MergeInputsRequest.builder()
.type(MergeInputsRequest.Type.MERGE)
.address(currentUnlockRequest.getAddress())
.amount(currentUnlockRequest.getAmount())
.utxos(currentUnlockRequest.getUtxos())
.build());
}

if (wallet.getUnlockState() != 1) {
wallet.setLocked(Boolean.FALSE);
}
Expand Down
Loading