Exemplo n.º 1
0
  /**
   * @param event The hardware wallet event (e.g. SHOW_DEVICE_FAILED etc)
   * @return An alert model suitable for use for displaying the information
   */
  public static AlertModel newHardwareWalletAlertModel(HardwareWalletEvent event) {

    WalletMode walletMode = WalletMode.of(event);

    switch (event.getEventType()) {
      case SHOW_DEVICE_READY:
        String label = "";
        if (event.getMessage().isPresent()) {
          Features features = (Features) event.getMessage().get();
          label = features.getLabel();
        }

        // Provide action to allow user to see a wizard

        JButton button =
            Buttons.newAlertPanelButton(
                getAlertButtonAction(),
                // Considered using Shield + Trezor tools wizard message but screen
                // gets cluttered with shields everywhere and looks confused
                MessageKey.YES,
                MessageKey.YES_TOOLTIP,
                AwesomeIcon.CHECK);

        return Models.newAlertModel(
            Languages.safeText(MessageKey.HARDWARE_ATTACHED_ALERT, walletMode.brand(), label),
            RAGStatus.GREEN,
            button);
      case SHOW_DEVICE_FAILED:
        return Models.newAlertModel(
            Languages.safeText(MessageKey.HARDWARE_FAILURE_ALERT, walletMode.brand()),
            RAGStatus.RED);
      default:
        throw new IllegalStateException("Unknown hardware wallet system event");
    }
  }
Exemplo n.º 2
0
  /**
   * @param bitcoinURI A Bitcoin URI
   * @return An alert model suitable for use for displaying the information, absent if the Bitcoin
   *     URI does not contain sufficient information
   */
  public static Optional<AlertModel> newBitcoinURIAlertModel(final BitcoinURI bitcoinURI) {

    // Action to show the "send Bitcoin" wizard
    AbstractAction action =
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {

            ControllerEvents.fireRemoveAlertEvent();

            SendBitcoinParameter parameter = new SendBitcoinParameter(bitcoinURI, null);

            Panels.showLightBox(Wizards.newSendBitcoinWizard(parameter).getWizardScreenHolder());
          }
        };
    JButton button =
        Buttons.newAlertPanelButton(
            action, MessageKey.YES, MessageKey.YES_TOOLTIP, AwesomeIcon.CHECK);

    // Attempt to decode the Bitcoin URI
    Optional<String> alertMessage = Formats.formatAlertMessage(bitcoinURI);

    // If there is sufficient information in the Bitcoin URI display it to the user as an alert
    if (alertMessage.isPresent()) {

      return Optional.of(Models.newAlertModel(alertMessage.get(), RAGStatus.PINK, button));
    }

    return Optional.absent();
  }
Exemplo n.º 3
0
  /**
   * @param transactionSeenEvent The transaction seen event
   * @return An alert model suitable for use for displaying the information, absent if the Bitcoin
   *     URI does not contain sufficient information
   */
  public static AlertModel newPaymentReceivedAlertModel(TransactionSeenEvent transactionSeenEvent) {

    // Attempt to decode the "transaction seen" event
    String alertMessage = Formats.formatAlertMessage(transactionSeenEvent);

    return Models.newAlertModel(alertMessage, RAGStatus.GREEN);
  }
Exemplo n.º 4
0
  /**
   * @param paymentSessionSummary The payment session summary providing meta data
   * @return An alert model suitable for use for displaying the payment request information, absent
   *     if the payment session summary does not contain sufficient information
   */
  public static Optional<AlertModel> newPaymentRequestAlertModel(
      final PaymentSessionSummary paymentSessionSummary) {

    // Action to show the "payment request details" wizard
    AbstractAction action =
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {

            ControllerEvents.fireRemoveAlertEvent();

            // The user has indicated that the payment request is of interest so persist it
            Preconditions.checkState(WalletManager.INSTANCE.getCurrentWalletSummary().isPresent());
            Preconditions.checkNotNull(paymentSessionSummary);

            WalletService walletService =
                CoreServices.getOrCreateWalletService(
                    WalletManager.INSTANCE.getCurrentWalletSummary().get().getWalletId());
            if (paymentSessionSummary.hasPaymentSession()) {

              // Build a PaymentRequestData for persistence
              PaymentRequestData paymentRequestData = new PaymentRequestData(paymentSessionSummary);

              // Add the localised trust status
              paymentRequestData.setTrustStatus(paymentSessionSummary.getStatus());
              paymentRequestData.setTrustErrorMessage(
                  Languages.safeText(
                      paymentSessionSummary.getMessageKey(),
                      paymentSessionSummary.getMessageData()));

              // Store it (in memory) in the wallet service
              walletService.addPaymentRequestData(paymentRequestData);

              // The wallet has changed so UI will need updating
              ViewEvents.fireWalletDetailChangedEvent(new WalletDetail());

              // Show the wizard and provide the PaymentRequestData to the model
              Panels.showLightBox(
                  Wizards.newPaymentsWizard(paymentRequestData).getWizardScreenHolder());
            }
          }
        };
    JButton button =
        Buttons.newAlertPanelButton(
            action, MessageKey.YES, MessageKey.YES_TOOLTIP, AwesomeIcon.CHECK);

    // Attempt to decode the Bitcoin URI
    Optional<String> alertMessage = Formats.formatAlertMessage(paymentSessionSummary);

    // If there is sufficient information in the payment request display it to the user as an alert
    if (alertMessage.isPresent()) {

      return Optional.of(Models.newAlertModel(alertMessage.get(), RAGStatus.PINK, button));
    }

    return Optional.absent();
  }