Skip to content

Commit 0bd48ab

Browse files
Bugfix: Fix float issue (#1900)
Co-authored-by: moneymanolis <[email protected]>
1 parent 92c12d3 commit 0bd48ab

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

cypress/integration/spec_wallet_send.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,28 @@ describe('Test sending transactions', () => {
3131
})
3232
})
3333

34-
// Skipped for now, will only work reliably once the the Cypress tests run without mining loop
34+
//
3535
it('Open up transaction details', () => {
3636
cy.selectWallet("Test Hot Wallet 1")
3737
cy.get('#btn_transactions').click()
38-
// Click on the txid in the first row
39-
cy.get('tbody.tx-tbody').find('tr').eq(0).find('#column-txid').find('.explorer-link').click()
40-
cy.get('.tx-data-info').contains('Input #0')
41-
cy.get('.tx-data-info').contains('Transaction id:')
42-
cy.get('.tx-data-info').contains('Output index:') // Not sure whether it is always 1 - output ordering is random in Core ...
43-
cy.get('.tx-data-info').contains('Address #0')
38+
// Click on the txid of the (hopefully) only send tx
39+
cy.get('tbody.tx-tbody').find('tr').find('.svg-send').parent().parent().parent().find('#column-txid').find('.explorer-link').click()
40+
// Input
4441
cy.get('.tx-data-info').contains('Value: 20 tBTC')
45-
cy.get('.tx-data-info').contains('Output #0')
46-
cy.get('.tx-data-info').contains('Burn address')
47-
cy.get('.tx-data-info').contains('Value: 19.9999989 tBTC') // Fees should always be the same
42+
// Output
43+
cy.get('.tx-data-info').contains(/Value:\s19\.9999\d{3}/) // The amount from the raw tx has 7 decimals, fees change apparently
4844
cy.get('#page_overlay_popup_cancel_button').click()
4945
// Change to sats and check amounts and units
5046
cy.get('[href="/settings/"]').click()
5147
cy.get('[name="unit"]').select('sats')
5248
cy.contains('Save').click()
5349
cy.selectWallet("Test Hot Wallet 1")
5450
cy.get('#btn_transactions').click()
55-
cy.get('tbody.tx-tbody').find('tr').eq(0).find('#column-txid').find('.explorer-link').click()
51+
cy.get('tbody.tx-tbody').find('tr').find('.svg-send').parent().parent().parent().find('#column-txid').find('.explorer-link').click()
52+
// Input
5653
cy.get('.tx-data-info').contains('Value: 2,000,000,000 tsat')
57-
cy.get('.tx-data-info').contains('Value: 1,999,999,890 tsat')
54+
// Output
55+
cy.get('.tx-data-info').contains(/Value:\s1,999,99\d,\d{3}\stsat/) // Fees change apparently
5856
cy.get('#page_overlay_popup_cancel_button').click()
5957
// Change back to btc
6058
cy.get('[href="/settings/"]').click()

src/cryptoadvance/specter/templates/includes/helpers.jinja

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@
3434
function formatBtcAmount(valueInBTC, unitLabel, convertToSat){
3535
var formattedUnitLabel = formatUnitLabel(unitLabel, convertToSat);
3636
var formattedValue = valueInBTC;
37-
if (valueInBTC) {
38-
value = parseFloat(valueInBTC.toFixed(8));
37+
if (formattedValue) {
3938
// The second condition in the if clause if True if formattedUnitLabel is equal to any element of the array
4039
if (convertToSat && (["Lsat", "sat", "tLsat", "tsat"].indexOf(formattedUnitLabel) > -1)) {
41-
formattedValue = parseInt(value * 1e8)
40+
// if it is sat, then format at integer
41+
formattedValue = parseInt(parseFloat(valueInBTC) * 1e8);
42+
}
43+
else{
44+
// else, then cut off at 8 digits
45+
formattedValue = parseFloat(valueInBTC).toFixed(8);
4246
}
4347
formattedValue = `${numberWithCommas(formattedValue)}`;
4448
}

0 commit comments

Comments
 (0)