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.faq=Visit FAQ page
shared.yesCancel=Yes, cancel shared.yesCancel=Yes, cancel
shared.nextStep=Next step 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.fundFromExternalWalletButton=Open your external wallet for funding
shared.openDefaultWalletFailed=Failed to open a Monero wallet application. Are you sure you have one installed? shared.openDefaultWalletFailed=Failed to open a Monero wallet application. Are you sure you have one installed?
shared.belowInPercent=Below % from market price 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.yesCancel=Ano, zrušit
shared.nextStep=Další krok shared.nextStep=Další krok
shared.selectTradingAccount=Vyberte obchodní účet 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.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.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 shared.belowInPercent=% pod tržní cenou

View file

@ -103,7 +103,7 @@ shared.faq=Zur FAQ Seite
shared.yesCancel=Ja, abbrechen shared.yesCancel=Ja, abbrechen
shared.nextStep=Nächster Schritt shared.nextStep=Nächster Schritt
shared.selectTradingAccount=Handelskonto auswählen 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.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.openDefaultWalletFailed=Das Öffnen des Standardprogramms für Monero-Wallets ist fehlgeschlagen. Sind Sie sicher, dass Sie eines installiert haben?
shared.belowInPercent=% unter dem Marktpreis shared.belowInPercent=% unter dem Marktpreis

View file

@ -103,7 +103,7 @@ shared.faq=Visitar web preguntas frecuentes
shared.yesCancel=Sí, cancelar shared.yesCancel=Sí, cancelar
shared.nextStep=Siguiente paso shared.nextStep=Siguiente paso
shared.selectTradingAccount=Selecionar cuenta de intercambio 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.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.openDefaultWalletFailed=Fallo al abrir la aplicación de cartera predeterminada. ¿Tal vez no tenga una instalada?
shared.belowInPercent=% por debajo del precio de mercado shared.belowInPercent=% por debajo del precio de mercado

View file

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

View file

@ -103,7 +103,7 @@ shared.faq=Visitez la page FAQ
shared.yesCancel=Oui, annuler shared.yesCancel=Oui, annuler
shared.nextStep=Étape suivante shared.nextStep=Étape suivante
shared.selectTradingAccount=Sélectionner le compte de trading 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.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.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é shared.belowInPercent=% sous le prix du marché

View file

@ -103,7 +103,7 @@ shared.faq=Visit FAQ page
shared.yesCancel=Si, annulla shared.yesCancel=Si, annulla
shared.nextStep=Passo successivo shared.nextStep=Passo successivo
shared.selectTradingAccount=Seleziona conto di trading 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.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.openDefaultWalletFailed=Failed to open a Monero wallet application. Are you sure you have one installed?
shared.belowInPercent=Sotto % del prezzo di mercato shared.belowInPercent=Sotto % del prezzo di mercato

View file

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

View file

@ -103,7 +103,7 @@ shared.faq=Visit FAQ page
shared.yesCancel=Sim, cancelar shared.yesCancel=Sim, cancelar
shared.nextStep=Próximo passo shared.nextStep=Próximo passo
shared.selectTradingAccount=Selecionar conta de negociação 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.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.openDefaultWalletFailed=Failed to open a Monero wallet application. Are you sure you have one installed?
shared.belowInPercent=% abaixo do preço de mercado shared.belowInPercent=% abaixo do preço de mercado

View file

@ -103,7 +103,7 @@ shared.faq=Visit FAQ page
shared.yesCancel=Sim, cancelar shared.yesCancel=Sim, cancelar
shared.nextStep=Próximo passo shared.nextStep=Próximo passo
shared.selectTradingAccount=Selecionar conta de negociação 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.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.openDefaultWalletFailed=Failed to open a Monero wallet application. Are you sure you have one installed?
shared.belowInPercent=Abaixo % do preço de mercado shared.belowInPercent=Abaixo % do preço de mercado

View file

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

View file

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

View file

@ -107,7 +107,7 @@ shared.chooseTradingAccount=İşlem hesabını seç
shared.faq=SSS sayfasını ziyaret et shared.faq=SSS sayfasını ziyaret et
shared.yesCancel=Evet, iptal et shared.yesCancel=Evet, iptal et
shared.nextStep=Sonraki adım 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.fundFromExternalWalletButton=Fonlama için harici cüzdanını
shared.openDefaultWalletFailed=Bir Monero cüzdan uygulamasıılamadı. Yüklü olduğundan emin misiniz? shared.openDefaultWalletFailed=Bir Monero cüzdan uygulamasıılamadı. Yüklü olduğundan emin misiniz?
shared.belowInPercent=Piyasa fiyatının altında % 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.yesCancel=Có, hủy
shared.nextStep=Bước tiếp theo shared.nextStep=Bước tiếp theo
shared.selectTradingAccount=Chọn tài khoản giao dịch 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.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.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 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.yesCancel=是的,取消
shared.nextStep=下一步 shared.nextStep=下一步
shared.selectTradingAccount=选择交易账户 shared.selectTradingAccount=选择交易账户
shared.fundFromSavingsWalletButton=从 Haveno 钱包资金划转 shared.fundFromSavingsWalletButton=从 Haveno 钱包申请资金
shared.fundFromExternalWalletButton=从您的外部钱包充值 shared.fundFromExternalWalletButton=从您的外部钱包充值
shared.openDefaultWalletFailed=打开默认的比特币钱包应用程序失败了。您确定您安装了吗? shared.openDefaultWalletFailed=打开默认的比特币钱包应用程序失败了。您确定您安装了吗?
shared.belowInPercent=低于市场价格 % shared.belowInPercent=低于市场价格 %

View file

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

View file

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

View file

@ -65,29 +65,7 @@ public abstract class OfferDataModel extends ActivatableDataModel {
this.offerUtil = offerUtil; this.offerUtil = offerUtil;
} }
protected void updateBalance() { protected void updateBalances() {
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() {
BigInteger tradeWalletBalance = xmrWalletService.getBalanceForSubaddress(addressEntry.getSubaddressIndex()); BigInteger tradeWalletBalance = xmrWalletService.getBalanceForSubaddress(addressEntry.getSubaddressIndex());
BigInteger tradeWalletAvailableBalance = xmrWalletService.getAvailableBalanceForSubaddress(addressEntry.getSubaddressIndex()); BigInteger tradeWalletAvailableBalance = xmrWalletService.getAvailableBalanceForSubaddress(addressEntry.getSubaddressIndex());
BigInteger walletBalance = xmrWalletService.getBalance(); BigInteger walletBalance = xmrWalletService.getBalance();
@ -101,6 +79,8 @@ public abstract class OfferDataModel extends ActivatableDataModel {
availableBalance.set(totalToPay.get().min(totalAvailableBalance)); availableBalance.set(totalToPay.get().min(totalAvailableBalance));
} }
} else { } else {
totalBalance = tradeWalletBalance;
totalAvailableBalance = tradeWalletAvailableBalance;
balance.set(tradeWalletBalance); balance.set(tradeWalletBalance);
availableBalance.set(tradeWalletAvailableBalance); availableBalance.set(tradeWalletAvailableBalance);
} }

View file

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

View file

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