make or take offer applies wallet funds and computes remaining amount

This commit is contained in:
woodser 2024-11-26 13:40:11 -05:00
parent e05ab6f7ed
commit 71987400c7
20 changed files with 77 additions and 59 deletions

View file

@ -107,7 +107,7 @@ shared.chooseTradingAccount=Choose trading account
shared.faq=Visit FAQ page
shared.yesCancel=Yes, cancel
shared.nextStep=Next step
shared.fundFromSavingsWalletButton=Transfer funds from Haveno wallet
shared.fundFromSavingsWalletButton=Apply funds from Haveno wallet
shared.fundFromExternalWalletButton=Open your external wallet for funding
shared.openDefaultWalletFailed=Failed to open a Monero wallet application. Are you sure you have one installed?
shared.belowInPercent=Below % from market price

View file

@ -103,7 +103,7 @@ shared.faq=Navštívit stránku FAQ
shared.yesCancel=Ano, zrušit
shared.nextStep=Další krok
shared.selectTradingAccount=Vyberte obchodní účet
shared.fundFromSavingsWalletButton=Přesunout finance z Haveno peněženky
shared.fundFromSavingsWalletButton=Použít prostředky z peněženky Haveno
shared.fundFromExternalWalletButton=Otevřít vaši externí peněženku pro financování
shared.openDefaultWalletFailed=Nepodařilo se otevřít aplikaci moneroové peněženky. Jste si jisti, že máte nějakou nainstalovanou?
shared.belowInPercent=% pod tržní cenou

View file

@ -103,7 +103,7 @@ shared.faq=Zur FAQ Seite
shared.yesCancel=Ja, abbrechen
shared.nextStep=Nächster Schritt
shared.selectTradingAccount=Handelskonto auswählen
shared.fundFromSavingsWalletButton=Gelder aus Haveno-Wallet überweisen
shared.fundFromSavingsWalletButton=Wenden Sie Gelder aus der Haveno-Wallet an
shared.fundFromExternalWalletButton=Ihre externe Wallet zum Finanzieren öffnen
shared.openDefaultWalletFailed=Das Öffnen des Standardprogramms für Monero-Wallets ist fehlgeschlagen. Sind Sie sicher, dass Sie eines installiert haben?
shared.belowInPercent=% unter dem Marktpreis

View file

@ -103,7 +103,7 @@ shared.faq=Visitar web preguntas frecuentes
shared.yesCancel=Sí, cancelar
shared.nextStep=Siguiente paso
shared.selectTradingAccount=Selecionar cuenta de intercambio
shared.fundFromSavingsWalletButton=Transferir fondos desde la cartera Haveno
shared.fundFromSavingsWalletButton=Aplicar fondos desde la billetera de Haveno
shared.fundFromExternalWalletButton=Abrir su monedero externo para agregar fondos
shared.openDefaultWalletFailed=Fallo al abrir la aplicación de cartera predeterminada. ¿Tal vez no tenga una instalada?
shared.belowInPercent=% por debajo del precio de mercado

View file

@ -103,7 +103,7 @@ shared.faq=Visit FAQ page
shared.yesCancel=بله، لغو شود
shared.nextStep=گام بعدی
shared.selectTradingAccount=حساب معاملات را انتخاب کنید
shared.fundFromSavingsWalletButton=انتقال وجه از کیف Haveno
shared.fundFromSavingsWalletButton=اعمال وجه از کیف پول هاونو
shared.fundFromExternalWalletButton=برای تهیه پول، کیف پول بیرونی خود را باز کنید
shared.openDefaultWalletFailed=Failed to open a Monero wallet application. Are you sure you have one installed?
shared.belowInPercent= ٪ زیر قیمت بازار

View file

@ -103,7 +103,7 @@ shared.faq=Visitez la page FAQ
shared.yesCancel=Oui, annuler
shared.nextStep=Étape suivante
shared.selectTradingAccount=Sélectionner le compte de trading
shared.fundFromSavingsWalletButton=Transférer des fonds depuis le portefeuille Haveno
shared.fundFromSavingsWalletButton=Appliquer les fonds depuis le portefeuille Haveno
shared.fundFromExternalWalletButton=Ouvrez votre portefeuille externe pour provisionner
shared.openDefaultWalletFailed=L'ouverture de l'application de portefeuille Monero par défaut a échoué. Êtes-vous sûr de l'avoir installée?
shared.belowInPercent=% sous le prix du marché

View file

@ -103,7 +103,7 @@ shared.faq=Visit FAQ page
shared.yesCancel=Si, annulla
shared.nextStep=Passo successivo
shared.selectTradingAccount=Seleziona conto di trading
shared.fundFromSavingsWalletButton=Trasferisci fondi dal portafoglio Haveno
shared.fundFromSavingsWalletButton=Applica fondi dal portafoglio Haveno
shared.fundFromExternalWalletButton=Apri il tuo portafoglio esterno per aggiungere fondi
shared.openDefaultWalletFailed=Failed to open a Monero wallet application. Are you sure you have one installed?
shared.belowInPercent=Sotto % del prezzo di mercato

View file

@ -103,7 +103,7 @@ shared.faq=FAQを参照する
shared.yesCancel=はい、取り消します
shared.nextStep=次へ
shared.selectTradingAccount=取引アカウントを選択
shared.fundFromSavingsWalletButton=Havenoウォレットから資金を移動する
shared.fundFromSavingsWalletButton=Havenoウォレットから資金を適用
shared.fundFromExternalWalletButton=外部のwalletを開く
shared.openDefaultWalletFailed=ビットコインウォレットのアプリを開けませんでした。インストールされているか確認して下さい。
shared.belowInPercent=市場価格から%以下

View file

@ -103,7 +103,7 @@ shared.faq=Visit FAQ page
shared.yesCancel=Sim, cancelar
shared.nextStep=Próximo passo
shared.selectTradingAccount=Selecionar conta de negociação
shared.fundFromSavingsWalletButton=Transferir fundos da carteira Haveno
shared.fundFromSavingsWalletButton=Aplicar fundos da carteira Haveno
shared.fundFromExternalWalletButton=Abrir sua carteira externa para prover fundos
shared.openDefaultWalletFailed=Failed to open a Monero wallet application. Are you sure you have one installed?
shared.belowInPercent=% abaixo do preço de mercado

View file

@ -103,7 +103,7 @@ shared.faq=Visit FAQ page
shared.yesCancel=Sim, cancelar
shared.nextStep=Próximo passo
shared.selectTradingAccount=Selecionar conta de negociação
shared.fundFromSavingsWalletButton=Transferir fundos da carteira Haveno
shared.fundFromSavingsWalletButton=Aplicar fundos da carteira Haveno
shared.fundFromExternalWalletButton=Abrir sua carteira externa para o financiamento
shared.openDefaultWalletFailed=Failed to open a Monero wallet application. Are you sure you have one installed?
shared.belowInPercent=Abaixo % do preço de mercado

View file

@ -103,7 +103,7 @@ shared.faq=Visit FAQ page
shared.yesCancel=Да, отменить
shared.nextStep=Далее
shared.selectTradingAccount=Выбрать торговый счёт
shared.fundFromSavingsWalletButton=Перевести средства с кошелька Haveno
shared.fundFromSavingsWalletButton=Применить средства из кошелька Haveno
shared.fundFromExternalWalletButton=Открыть внешний кошелёк для пополнения
shared.openDefaultWalletFailed=Failed to open a Monero wallet application. Are you sure you have one installed?
shared.belowInPercent=% ниже рыночного курса

View file

@ -103,7 +103,7 @@ shared.faq=Visit FAQ page
shared.yesCancel=ใช่ ยกเลิก
shared.nextStep=ขั้นถัดไป
shared.selectTradingAccount=เลือกบัญชีการซื้อขาย
shared.fundFromSavingsWalletButton=โอนเงินจาก Haveno wallet
shared.fundFromSavingsWalletButton=ใช้เงินจากกระเป๋าเงิน Haveno
shared.fundFromExternalWalletButton=เริ่มทำการระดมเงินทุนหาแหล่งเงินจากกระเป๋าสตางค์ภายนอกของคุณ
shared.openDefaultWalletFailed=Failed to open a Monero wallet application. Are you sure you have one installed?
shared.belowInPercent=ต่ำกว่า % จากราคาตลาด

View file

@ -107,7 +107,7 @@ shared.chooseTradingAccount=İşlem hesabını seç
shared.faq=SSS sayfasını ziyaret et
shared.yesCancel=Evet, iptal et
shared.nextStep=Sonraki adım
shared.fundFromSavingsWalletButton=Haveno cüzdanından fon transfer et
shared.fundFromSavingsWalletButton=Haveno cüzdanından fonları uygula
shared.fundFromExternalWalletButton=Fonlama için harici cüzdanını
shared.openDefaultWalletFailed=Bir Monero cüzdan uygulamasıılamadı. Yüklü olduğundan emin misiniz?
shared.belowInPercent=Piyasa fiyatının altında %

View file

@ -103,7 +103,7 @@ shared.faq=Visit FAQ page
shared.yesCancel=Có, hủy
shared.nextStep=Bước tiếp theo
shared.selectTradingAccount=Chọn tài khoản giao dịch
shared.fundFromSavingsWalletButton=Chuyển tiền từ Ví Haveno
shared.fundFromSavingsWalletButton=Áp dụng tiền từ ví Haveno
shared.fundFromExternalWalletButton=Mở ví ngoài để nộp tiền
shared.openDefaultWalletFailed=Failed to open a Monero wallet application. Are you sure you have one installed?
shared.belowInPercent=Thấp hơn % so với giá thị trường

View file

@ -103,7 +103,7 @@ shared.faq=访问 FAQ 页面
shared.yesCancel=是的,取消
shared.nextStep=下一步
shared.selectTradingAccount=选择交易账户
shared.fundFromSavingsWalletButton=从 Haveno 钱包资金划转
shared.fundFromSavingsWalletButton=从 Haveno 钱包申请资金
shared.fundFromExternalWalletButton=从您的外部钱包充值
shared.openDefaultWalletFailed=打开默认的比特币钱包应用程序失败了。您确定您安装了吗?
shared.belowInPercent=低于市场价格 %

View file

@ -103,7 +103,7 @@ shared.faq=訪問 FAQ 頁面
shared.yesCancel=是的,取消
shared.nextStep=下一步
shared.selectTradingAccount=選擇交易賬户
shared.fundFromSavingsWalletButton=從 Haveno 錢包資金劃轉
shared.fundFromSavingsWalletButton=從 Haveno 錢包申請資金
shared.fundFromExternalWalletButton=從您的外部錢包充值
shared.openDefaultWalletFailed=打開默認的比特幣錢包應用程序失敗了。您確定您安裝了嗎?
shared.belowInPercent=低於市場價格 %

View file

@ -20,6 +20,8 @@ package haveno.desktop.main.offer;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import haveno.common.UserThread;
import haveno.common.handlers.ErrorMessageHandler;
import haveno.common.util.MathUtils;
import haveno.common.util.Utilities;
@ -176,7 +178,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel {
if (isTabSelected)
priceFeedService.setCurrencyCode(tradeCurrencyCode.get());
updateBalance();
updateBalances();
}
@Override
@ -205,7 +207,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel {
xmrBalanceListener = new XmrBalanceListener(getAddressEntry().getSubaddressIndex()) {
@Override
public void onBalanceChanged(BigInteger balance) {
updateBalance();
updateBalances();
}
};
@ -246,7 +248,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel {
calculateVolume();
calculateTotalToPay();
updateBalance();
updateBalances();
setSuggestedSecurityDeposit(getPaymentAccount());
return true;
@ -273,6 +275,19 @@ public abstract class MutableOfferDataModel extends OfferDataModel {
priceFeedService.setCurrencyCode(tradeCurrencyCode.get());
}
protected void updateBalances() {
super.updateBalances();
// update remaining balance
UserThread.await(() -> {
missingCoin.set(offerUtil.getBalanceShortage(totalToPay.get(), balance.get()));
isXmrWalletFunded.set(offerUtil.isBalanceSufficient(totalToPay.get(), balance.get()));
if (totalToPay.get() != null && isXmrWalletFunded.get() && !showWalletFundedNotification.get()) {
showWalletFundedNotification.set(true);
}
});
}
///////////////////////////////////////////////////////////////////////////////////////////
// UI actions
///////////////////////////////////////////////////////////////////////////////////////////
@ -393,11 +408,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel {
void fundFromSavingsWallet() {
this.useSavingsWallet = true;
updateBalance();
if (!isXmrWalletFunded.get()) {
this.useSavingsWallet = false;
updateBalance();
}
updateBalances();
}
protected void setMarketPriceMarginPct(double marketPriceMargin) {
@ -492,7 +503,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel {
}
}
updateBalance();
updateBalances();
}
void calculateMinVolume() {
@ -545,7 +556,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel {
BigInteger feeAndSecDeposit = getSecurityDeposit().add(makerFee);
BigInteger total = isBuyOffer() ? feeAndSecDeposit : feeAndSecDeposit.add(amount.get());
totalToPay.set(total);
updateBalance();
updateBalances();
}
}

View file

@ -65,29 +65,7 @@ public abstract class OfferDataModel extends ActivatableDataModel {
this.offerUtil = offerUtil;
}
protected void updateBalance() {
updateBalances();
UserThread.await(() -> {
missingCoin.set(offerUtil.getBalanceShortage(totalToPay.get(), balance.get()));
isXmrWalletFunded.set(offerUtil.isBalanceSufficient(totalToPay.get(), balance.get()));
if (totalToPay.get() != null && isXmrWalletFunded.get() && !showWalletFundedNotification.get()) {
showWalletFundedNotification.set(true);
}
});
}
protected void updateAvailableBalance() {
updateBalances();
UserThread.await(() -> {
missingCoin.set(offerUtil.getBalanceShortage(totalToPay.get(), availableBalance.get()));
isXmrWalletFunded.set(offerUtil.isBalanceSufficient(totalToPay.get(), availableBalance.get()));
if (totalToPay.get() != null && isXmrWalletFunded.get() && !showWalletFundedNotification.get()) {
showWalletFundedNotification.set(true);
}
});
}
private void updateBalances() {
protected void updateBalances() {
BigInteger tradeWalletBalance = xmrWalletService.getBalanceForSubaddress(addressEntry.getSubaddressIndex());
BigInteger tradeWalletAvailableBalance = xmrWalletService.getAvailableBalanceForSubaddress(addressEntry.getSubaddressIndex());
BigInteger walletBalance = xmrWalletService.getBalance();
@ -101,6 +79,8 @@ public abstract class OfferDataModel extends ActivatableDataModel {
availableBalance.set(totalToPay.get().min(totalAvailableBalance));
}
} else {
totalBalance = tradeWalletBalance;
totalAvailableBalance = tradeWalletAvailableBalance;
balance.set(tradeWalletBalance);
availableBalance.set(tradeWalletAvailableBalance);
}

View file

@ -20,6 +20,7 @@ package haveno.desktop.main.offer.takeoffer;
import com.google.inject.Inject;
import haveno.common.ThreadUtils;
import haveno.common.UserThread;
import haveno.common.handlers.ErrorMessageHandler;
import haveno.core.account.witness.AccountAgeWitnessService;
import haveno.core.filter.FilterManager;
@ -131,7 +132,7 @@ class TakeOfferDataModel extends OfferDataModel {
addListeners();
updateAvailableBalance();
updateBalances();
// TODO In case that we have funded but restarted, or canceled but took again the offer we would need to
// store locally the result when we received the funding tx(s).
@ -192,7 +193,7 @@ class TakeOfferDataModel extends OfferDataModel {
balanceListener = new XmrBalanceListener(addressEntry.getSubaddressIndex()) {
@Override
public void onBalanceChanged(BigInteger balance) {
updateAvailableBalance();
updateBalances();
}
};
@ -227,6 +228,19 @@ class TakeOfferDataModel extends OfferDataModel {
ThreadUtils.submitToPool(() -> xmrWalletService.resetAddressEntriesForOpenOffer(offer.getId()));
}
protected void updateBalances() {
super.updateBalances();
// update remaining balance
UserThread.await(() -> {
missingCoin.set(offerUtil.getBalanceShortage(totalToPay.get(), balance.get()));
isXmrWalletFunded.set(offerUtil.isBalanceSufficient(totalToPay.get(), availableBalance.get()));
if (totalToPay.get() != null && isXmrWalletFunded.get() && !showWalletFundedNotification.get()) {
showWalletFundedNotification.set(true);
}
});
}
///////////////////////////////////////////////////////////////////////////////////////////
// UI actions
@ -287,11 +301,7 @@ class TakeOfferDataModel extends OfferDataModel {
void fundFromSavingsWallet() {
useSavingsWallet = true;
updateAvailableBalance();
if (!isXmrWalletFunded.get()) {
this.useSavingsWallet = false;
updateAvailableBalance();
}
updateBalances();
}
@ -369,7 +379,7 @@ class TakeOfferDataModel extends OfferDataModel {
volume.set(volumeByAmount);
updateAvailableBalance();
updateBalances();
}
}
@ -391,7 +401,7 @@ class TakeOfferDataModel extends OfferDataModel {
totalToPay.set(feeAndSecDeposit.add(amount.get()));
else
totalToPay.set(feeAndSecDeposit);
updateAvailableBalance();
updateBalances();
log.debug("totalToPay {}", totalToPay.get());
}
}

View file

@ -154,6 +154,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
showTransactionPublishedScreenSubscription, showWarningInvalidBtcDecimalPlacesSubscription,
isWaitingForFundsSubscription, offerWarningSubscription, errorMessageSubscription,
isOfferAvailableSubscription;
private ChangeListener<BigInteger> missingCoinListener;
private int gridRow = 0;
private final HashMap<String, Boolean> paymentAccountWarningDisplayed = new HashMap<>();
@ -191,6 +192,8 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
addAmountPriceGroup();
addOptionsGroup();
createListeners();
addButtons();
addOfferAvailabilityLabel();
addFundingGroup();
@ -489,6 +492,10 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
}
}
updateQrCode();
}
private void updateQrCode() {
final byte[] imageBytes = QRCode
.from(getMoneroURI())
.withSize(300, 300)
@ -675,7 +682,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
}
});
balanceSubscription = EasyBind.subscribe(model.dataModel.getBalance(), balanceTextField::setBalance);
balanceSubscription = EasyBind.subscribe(model.dataModel.getAvailableBalance(), balanceTextField::setBalance);
}
private void removeSubscriptions() {
@ -689,14 +696,24 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
balanceSubscription.unsubscribe();
}
private void createListeners() {
missingCoinListener = (observable, oldValue, newValue) -> {
if (!newValue.toString().equals("")) {
updateQrCode();
}
};
}
private void addListeners() {
amountTextField.focusedProperty().addListener(amountFocusedListener);
model.dataModel.getShowWalletFundedNotification().addListener(getShowWalletFundedNotificationListener);
model.dataModel.getMissingCoin().addListener(missingCoinListener);
}
private void removeListeners() {
amountTextField.focusedProperty().removeListener(amountFocusedListener);
model.dataModel.getShowWalletFundedNotification().removeListener(getShowWalletFundedNotificationListener);
model.dataModel.getMissingCoin().removeListener(missingCoinListener);
}
///////////////////////////////////////////////////////////////////////////////////////////