diff --git a/decred/decred/wallet/accounts.py b/decred/decred/wallet/accounts.py index bb47ffa5..6f070b9d 100644 --- a/decred/decred/wallet/accounts.py +++ b/decred/decred/wallet/accounts.py @@ -145,6 +145,18 @@ def setNode(self, node): for acct in self.accounts.values(): acct.setNode(node) + def setRelayFee(self, idx, fee): + """ + Save the relay fee for account at index. + + Args: + idx (int): The account's index. + fee (int): The relay fee in smallest unit/kb. + """ + acct = self.acctDB[idx] + acct.relayFee = fee + self.acctDB[idx] = acct + def coinKey(self, cryptoKey): """ Decrypt the coin-type extended key. diff --git a/tinywallet/tinywallet/screens.py b/tinywallet/tinywallet/screens.py index 1ed85627..1e746866 100644 --- a/tinywallet/tinywallet/screens.py +++ b/tinywallet/tinywallet/screens.py @@ -477,7 +477,7 @@ def __init__(self, acctMgr, acct, assetScreen): self.ticketStats = None self.balance = None self.settingsScreen = AccountSettingsScreen( - self.account.relayFee, self.saveName, self.saveRelayFee + self.account.relayFee, self.saveName, self.setRelayFee ) self.stakeScreen = StakingScreen(acct) self.wgt.setFixedSize( @@ -719,15 +719,14 @@ def saveName(self, newName): self.assetScreen.doButtons() app.home() - def saveRelayFee(self, relayFee): + def setRelayFee(self, relayFee): """ Changes and saves the relayFee of the account. Args: int: The new relayFee. """ - self.account.relayFee = relayFee - self.acctMgr.saveAccount(self.account.idx) + self.acctMgr.setRelayFee(self.account.idx, relayFee) def stackAndSync(self): """ @@ -1845,7 +1844,7 @@ class AccountSettingsScreen(Screen): Account settings screen. """ - def __init__(self, relayFee, saveName, saveRelayFee): + def __init__(self, relayFee, saveName, setRelayFee): """ Args: saveName (function): A callback function to be called after the user @@ -1859,7 +1858,7 @@ def __init__(self, relayFee, saveName, saveRelayFee): TinyDialog.maxHeight * 0.9 - TinyDialog.topMenuHeight, ) self.saveName = saveName - self.saveRelayFee = saveRelayFee + self.setRelayFee = setRelayFee gear = SVGWidget("gear", h=20) lbl = Q.makeLabel("Account Settings", 22) @@ -1868,6 +1867,11 @@ def __init__(self, relayFee, saveName, saveRelayFee): self.layout.addStretch(1) + def insertSpace(): + spacer = Q.makeLabel("", 5) + spacer.setContentsMargins(0, 5, 0, 0) + grid.addWidget(spacer, row, 0, 1, 4) + # ACCOUNT NAME wgt, grid = Q.makeWidget(QtWidgets.QWidget, Q.GRID) @@ -1894,7 +1898,7 @@ def __init__(self, relayFee, saveName, saveRelayFee): self.feeRates = { self.lowStr: 4000, self.defaultStr: int(DefaultRelayFeePerKb), - self.highStr: 114000, + self.highStr: 50000, } self.feeLvl = "" @@ -1913,15 +1917,24 @@ def setChecked(btn): btn.setChecked(True) row += 1 - grid.addWidget(Q.makeLabel("Relay Fee", 14, Q.ALIGN_LEFT), row, 0) + insertSpace() + row += 1 + lbl = Q.makeLabel("Relay Fee", 14, Q.ALIGN_LEFT) + grid.addWidget(lbl, row, 0) + self.feeLbl = lbl = Q.makeLabel("", 14, Q.ALIGN_LEFT) + self.setFeeLbl(relayFee) + grid.addWidget(lbl, row, 1) row += 1 btn1 = QtWidgets.QRadioButton(self.lowStr) + Q.setProperties(btn1, fontFamily="Roboto", fontSize=14) setChecked(btn1) btn1.toggled.connect(lambda: self.relayFeeChangeClicked(self.lowStr)) btn2 = QtWidgets.QRadioButton(self.defaultStr) + Q.setProperties(btn2, fontFamily="Roboto", fontSize=14) setChecked(btn2) btn2.toggled.connect(lambda: self.relayFeeChangeClicked(self.defaultStr)) btn3 = QtWidgets.QRadioButton(self.highStr) + Q.setProperties(btn3, fontFamily="Roboto", fontSize=14) setChecked(btn3) btn3.toggled.connect(lambda: self.relayFeeChangeClicked(self.highStr)) wgt, _ = Q.makeRow(btn1, btn2, btn3) @@ -1929,6 +1942,9 @@ def setChecked(btn): self.layout.addStretch(1) + def setFeeLbl(self, fee): + self.feeLbl.setText(f"{fee//1000} atoms/byte") + def nameChangeClicked(self, e): """ Qt slot for nameField.clicked signal. @@ -1940,7 +1956,7 @@ def nameChangeClicked(self, e): self.nameField.setText("") self.saveName(newName) - def relayFeeChangeClicked(self, feeLvl, e=None): + def relayFeeChangeClicked(self, feeLvl): """ Qt slot connected to relay fee radio button clicked signal. Changes the relay fee to feeLvl. @@ -1949,7 +1965,8 @@ def relayFeeChangeClicked(self, feeLvl, e=None): return self.feeLvl = feeLvl fee = self.feeRates[feeLvl] - self.saveRelayFee(fee) + self.setRelayFee(fee) + self.setFeeLbl(fee) log.info(f"relay fee changed to {fee} atoms/kb") app.appWindow.showSuccess(f"using {feeLvl} fees")