Example #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");
    }
  }
  @Override
  public void execute(Map<String, Object> parameters) {

    // Click on "labs"
    window.button(MessageKey.SHOW_LABS_WIZARD.getKey()).click();

    // Allow time for component to change
    pauseForComponentReset();

    // Verify the "labs" wizard appears
    assertLabelText(MessageKey.LABS_SETTINGS_TITLE);

    // Verify Apply is present
    window.button(MessageKey.APPLY.getKey()).requireVisible().requireEnabled();

    // Verify Cancel is present
    window.button(MessageKey.CANCEL.getKey()).requireVisible().requireEnabled();

    // Verify Trezor "Yes" is selected (0) then select "No"
    window
        .comboBox(MessageKey.SELECT_HARDWARE_WALLET.getKey())
        .requireSelection(0)
        .selectItem(Languages.safeText(MessageKey.NO));

    // Click Apply
    window.button(MessageKey.APPLY.getKey()).click();

    pauseForComponentReset();

    // Verify the underlying screen is back
    window.button(MessageKey.SHOW_LANGUAGE_WIZARD.getKey()).requireVisible().requireEnabled();

    // Verify configuration has changed
    assertThat(Configurations.currentConfiguration.isTrezor()).isFalse();

    // Click on "labs"
    window.button(MessageKey.SHOW_LABS_WIZARD.getKey()).click();

    // Allow time for component to change
    pauseForComponentReset();

    // Verify "No" is selected (1) then select "Yes"
    window
        .comboBox(MessageKey.SELECT_HARDWARE_WALLET.getKey())
        .requireSelection(1)
        .selectItem(Languages.safeText(MessageKey.YES));

    // Click Apply
    window.button(MessageKey.APPLY.getKey()).click();

    pauseForViewReset();

    // Verify the underlying screen is back
    window.button(MessageKey.SHOW_LANGUAGE_WIZARD.getKey()).requireVisible().requireEnabled();

    // Verify configuration has changed
    assertThat(Configurations.currentConfiguration.isTrezor()).isTrue();
  }
  @Override
  public void execute(Map<String, Object> parameters) {

    // Get the initial row count
    int rowCount1 = window.table(MessageKey.HISTORY.getKey()).rowCount();

    // Find "Password verified" row
    int pvRow =
        window
            .table(MessageKey.HISTORY.getKey())
            .cell(Languages.safeText(MessageKey.PASSWORD_VERIFIED))
            .row;

    // Get the history
    String[][] history = window.table(MessageKey.HISTORY.getKey()).contents();

    ensureCheckboxIsSelected(MessageKey.HISTORY, pvRow, HistoryTableModel.CHECKBOX_COLUMN_INDEX);

    // Click on Edit
    window.button(MessageKey.EDIT.getKey()).click();

    // Verify the single history edit wizard appears
    assertLabelText(MessageKey.EDIT_HISTORY_ENTRY_TITLE);

    window.button(MessageKey.CANCEL.getKey()).requireVisible().requireEnabled();

    // Update credentials entry private notes
    window
        .textBox(MessageKey.DESCRIPTION_READ_ONLY.getKey())
        .requireText(Languages.safeText(MessageKey.PASSWORD_VERIFIED))
        .requireNotEditable();

    // Private notes
    window.textBox(MessageKey.PRIVATE_NOTES.getKey()).setText("First login to wallet");

    verifyCancel();

    // Click Apply
    window.button(MessageKey.APPLY.getKey()).click();

    // Verify the underlying screen is back
    window.button(MessageKey.EDIT.getKey()).requireVisible().requireEnabled();

    // Get an updated row count
    int rowCount2 = window.table(MessageKey.HISTORY.getKey()).rowCount();

    // Verify that no new row has been added
    assertThat(rowCount2).isEqualTo(rowCount1);

    // Verify that the private notes are visible
    window.table(MessageKey.HISTORY.getKey()).cell("First login to wallet");
  }
  @Override
  public void execute(Map<String, Object> parameters) {

    // Get the initial row count
    int rowCount1 = window.table(MessageKey.PAYMENTS.getKey()).rowCount();

    // Select the first 7 rows in turn
    for (int i = 0; i < Math.min(rowCount1, 7); i++) {
      // Get the payment data

      String[][] payments = window.table(MessageKey.PAYMENTS.getKey()).contents();

      // See if it is a payment request or a transaction
      boolean isPaymentRequest =
          Languages.safeText(CoreMessageKey.PAYMENT_REQUESTED)
              .equals(WhitespaceTrimmer.trim(payments[i][PaymentTableModel.TYPE_COLUMN_INDEX]));

      window.table(MessageKey.PAYMENTS.getKey()).selectRows(i);

      // Show the details
      window.button(MessageKey.DETAILS.getKey()).click();

      if (isPaymentRequest) {
        // Verify the payment details wizard appears, showing a payment request
        assertLabelText(MessageKey.PAYMENT_REQUEST);

        window.button(MessageKey.CANCEL.getKey()).requireVisible().requireEnabled();

        // Verify bitcoin address is shown
        window.textBox(MessageKey.BITCOIN_ADDRESS.getKey()).requireVisible();

        // Click finish
        window.button(MessageKey.FINISH.getKey()).click();

        // Verify the underlying screen is back
        window.button(MessageKey.DETAILS.getKey()).requireVisible().requireEnabled();
      } else {

        // Verify the payment details wizard appears, showing a transaction overview panel
        assertLabelText(MessageKey.TRANSACTION_OVERVIEW);

        window.button(MessageKey.NEXT.getKey()).requireVisible().requireEnabled();

        // Click next
        window.button(MessageKey.NEXT.getKey()).click();

        // Verify showing the transaction amount panel
        assertLabelText(MessageKey.TRANSACTION_AMOUNT);

        // Click next
        window.button(MessageKey.NEXT.getKey()).click();

        // Verify showing the transaction details panel
        assertLabelText(MessageKey.TRANSACTION_DETAIL);

        // Click next
        window.button(MessageKey.NEXT.getKey()).click();

        // Verify showing the choose payment request
        assertLabelText(MessageKey.CHOOSE_PAYMENT_REQUEST);

        // Click next
        window.button(MessageKey.NEXT.getKey()).click();

        // Verify showing payment request details
        assertLabelText(MessageKey.PAYMENT_REQUEST);

        // Click finish
        window.button(MessageKey.FINISH.getKey()).click();

        // Verify the underlying screen is back
        window.button(MessageKey.DETAILS.getKey()).requireVisible().requireEnabled();
      }
    }
  }
  /**
   * Create a wallet from a seed phrase, timestamp and credentials
   *
   * @param seedPhrase the seed phrase to use in the restore
   * @param walletTypeToRestore the type of wallet to restore (one of the WalletType enum values)
   * @param timestamp the string format of the timestamp to use in the restore. May be blank in
   *     which case the earliest HD birth date is used
   * @param password the password to use to secure the newly created wallet
   */
  private boolean createWalletFromSeedPhraseAndTimestamp(
      List<String> seedPhrase, WalletType walletTypeToRestore, String timestamp, String password) {

    if (!verifySeedPhrase(seedPhrase)) {
      return false;
    }

    try {
      byte[] entropy = MnemonicCode.INSTANCE.toEntropy(seedPhrase);

      SeedPhraseGenerator seedGenerator = new Bip39SeedPhraseGenerator();
      byte[] seed = seedGenerator.convertToSeed(seedPhrase);

      // Locate the user data directory
      File applicationDataDirectory = InstallationManager.getOrCreateApplicationDataDirectory();

      if (Strings.isNullOrEmpty(timestamp)) {
        // Use the earliest possible HD wallet birthday
        timestamp = EARLIEST_HD_TIMESTAMP;
      }

      DateTime replayDate = Dates.parseSeedTimestamp(timestamp);

      // Provide some default text
      String name = Languages.safeText(MessageKey.WALLET);

      // Display in the system timezone
      String notes =
          Languages.safeText(
              MessageKey.WALLET_DEFAULT_NOTES,
              Dates.formatDeliveryDateLocal(
                  Dates.nowUtc(), Configurations.currentConfiguration.getLocale()));

      switch (walletTypeToRestore) {
        case TREZOR_SOFT_WALLET:
          {
            // Create Trezor soft wallet
            WalletManager.INSTANCE.getOrCreateTrezorSoftWalletSummaryFromSeedPhrase(
                applicationDataDirectory,
                Joiner.on(" ").join(seedPhrase),
                Dates.thenInSeconds(replayDate),
                password,
                name,
                notes,
                true);
            return true;
          }
        case MBHD_SOFT_WALLET_BIP32:
          {
            // BIP32 compliant soft wallet
            WalletManager.INSTANCE.getOrCreateMBHDSoftWalletSummaryFromEntropy(
                applicationDataDirectory,
                entropy,
                seed,
                Dates.thenInSeconds(replayDate),
                password,
                name,
                notes,
                true);

            return true;
          }
        case MBHD_SOFT_WALLET:
          {
            // Beta 7 MBHD wallet - not BIP32 compliant
            WalletManager.INSTANCE.badlyGetOrCreateMBHDSoftWalletSummaryFromSeed(
                applicationDataDirectory,
                seed,
                Dates.thenInSeconds(replayDate),
                password,
                name,
                notes,
                true);
            return true;
          }
        default:
          {
            throw new IllegalArgumentException(
                "Cannot restore the wallet with unknown type " + walletTypeToRestore);
          }
      }
    } catch (Exception e) {
      log.error("Failed to restore wallet.", e);
      return false;
    }
  }
  @Override
  public String[] convertEntry(PaymentRequestData PaymentRequestData) {
    String[] columns = new String[12];

    // Date
    columns[0] = Languages.safeText(MessageKey.DATE);

    // Type
    columns[1] = Languages.safeText(MessageKey.TYPE);

    // UUID
    columns[2] = Languages.safeText(MessageKey.UUID);

    // Description
    columns[3] = Languages.safeText(MessageKey.DESCRIPTION);

    // Private notes
    columns[4] = Languages.safeText(MessageKey.PRIVATE_NOTES);

    // Amount in satoshi
    columns[5] =
        Languages.safeText(MessageKey.LOCAL_AMOUNT) + " " + BitcoinSymbol.SATOSHI.getTextSymbol();

    // Fiat currency symbol
    columns[6] = Languages.safeText(MessageKey.FIAT_CURRENCY);

    // Fiat currency amount
    columns[7] = Languages.safeText(MessageKey.FIAT_AMOUNT);

    // Exchange rate
    columns[8] = Languages.safeText(MessageKey.EXCHANGE_RATE_LABEL);

    // Exchange rate provider
    columns[9] = Languages.safeText(MessageKey.EXCHANGE_RATE_PROVIDER);

    // Matching transaction hash
    columns[10] = Languages.safeText(MessageKey.TRANSACTION_HASH);

    // Identity
    columns[11] = Languages.safeText(MessageKey.IDENTITY);

    return columns;
  }