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();
}
}
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 + ".");
}
}
}
Aggregations