Search in sources :

Example 1 with PaymentAccountList

use of bisq.core.payment.PaymentAccountList in project bisq-desktop by bisq-network.

the class GUIUtil method exportAccounts.

public static void exportAccounts(ArrayList<PaymentAccount> accounts, String fileName, Preferences preferences, Stage stage, PersistenceProtoResolver persistenceProtoResolver) {
    if (!accounts.isEmpty()) {
        String directory = getDirectoryFromChooser(preferences, stage);
        if (directory != null && !directory.isEmpty()) {
            Storage<PersistableList<PaymentAccount>> paymentAccountsStorage = new Storage<>(new File(directory), persistenceProtoResolver);
            paymentAccountsStorage.initAndGetPersisted(new PaymentAccountList(accounts), fileName, 100);
            paymentAccountsStorage.queueUpForSave();
            new Popup<>().feedback(Res.get("guiUtil.accountExport.savedToPath", Paths.get(directory, fileName).toAbsolutePath())).show();
        }
    } else {
        new Popup<>().warning(Res.get("guiUtil.accountExport.noAccountSetup")).show();
    }
}
Also used : PaymentAccountList(bisq.core.payment.PaymentAccountList) Storage(bisq.common.storage.Storage) PersistableList(bisq.common.proto.persistable.PersistableList) Popup(bisq.desktop.main.overlays.popups.Popup) File(java.io.File)

Example 2 with PaymentAccountList

use of bisq.core.payment.PaymentAccountList in project bisq-desktop by bisq-network.

the class GUIUtil method importAccounts.

public static void importAccounts(User user, String fileName, Preferences preferences, Stage stage, PersistenceProtoResolver persistenceProtoResolver) {
    FileChooser fileChooser = new FileChooser();
    File initDir = new File(preferences.getDirectoryChooserPath());
    if (initDir.isDirectory()) {
        fileChooser.setInitialDirectory(initDir);
    }
    fileChooser.setTitle(Res.get("guiUtil.accountExport.selectPath", fileName));
    File file = fileChooser.showOpenDialog(stage.getOwner());
    if (file != null) {
        String path = file.getAbsolutePath();
        if (Paths.get(path).getFileName().toString().equals(fileName)) {
            String directory = Paths.get(path).getParent().toString();
            preferences.setDirectoryChooserPath(directory);
            Storage<PaymentAccountList> paymentAccountsStorage = new Storage<>(new File(directory), persistenceProtoResolver);
            PaymentAccountList persisted = paymentAccountsStorage.initAndGetPersistedWithFileName(fileName, 100);
            if (persisted != null) {
                final StringBuilder msg = new StringBuilder();
                persisted.getList().stream().forEach(paymentAccount -> {
                    final String id = paymentAccount.getId();
                    if (user.getPaymentAccount(id) == null) {
                        user.addPaymentAccount(paymentAccount);
                        msg.append(Res.get("guiUtil.accountExport.tradingAccount", id));
                    } else {
                        msg.append(Res.get("guiUtil.accountImport.noImport", id));
                    }
                });
                new Popup<>().feedback(Res.get("guiUtil.accountImport.imported", path, msg)).show();
            } else {
                new Popup<>().warning(Res.get("guiUtil.accountImport.noAccountsFound", path, fileName)).show();
            }
        } else {
            log.error("The selected file is not the expected file for import. The expected file name is: " + fileName + ".");
        }
    }
}
Also used : PaymentAccountList(bisq.core.payment.PaymentAccountList) Storage(bisq.common.storage.Storage) Popup(bisq.desktop.main.overlays.popups.Popup) FileChooser(javafx.stage.FileChooser) File(java.io.File)

Aggregations

Storage (bisq.common.storage.Storage)2 PaymentAccountList (bisq.core.payment.PaymentAccountList)2 Popup (bisq.desktop.main.overlays.popups.Popup)2 File (java.io.File)2 PersistableList (bisq.common.proto.persistable.PersistableList)1 FileChooser (javafx.stage.FileChooser)1