Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit a1046cd
Merge: 9fcac2d 7199fec
Author: jadzeidan <[email protected]>
Date:   Fri Oct 28 17:36:19 2022 +0200

    Merge branch 'color_variables_patch' of https://github.com/jadzeidan/bitbox-wallet-app into color_variables_patch

commit 7199fec
Merge: c95a1ee 6e4e2a7
Author: Jad <[email protected]>
Date:   Fri Oct 28 17:34:59 2022 +0200

    Merge branch 'digitalbitbox:master' into color_variables_patch

commit 9fcac2d
Author: jadzeidan <[email protected]>
Date:   Mon Oct 3 21:09:12 2022 +0200

    frontends: color variables refactoring

    Seperated text and background colors into their own variables. This makes colors easier to maintain because now it's possible to change text and background colors without affecting each other.

    Also some text used --color-softblack instead of a designated /* font colors */ variable. Changed this text to --color-default so it is consistant with the other text colors.

    changed text using color-grey to color-secondary

commit c95a1ee
Author: jadzeidan <[email protected]>
Date:   Fri Oct 28 17:32:43 2022 +0200

    changed text using color-grey to color-secondary

commit 6e4e2a7
Merge: c535485 13f2c0b
Author: Marko Bencun <[email protected]>
Date:   Thu Oct 27 12:43:24 2022 +0200

    Merge branch 'bb02-sats'

commit 13f2c0b
Author: Marko Bencun <[email protected]>
Date:   Wed Oct 26 09:55:27 2022 +0200

    backend/bitbox02: format BTC as sats if the setting is turned on

    Also bitbox02-api-go is updated to make use of the new protobuf
    messages:

    go get github.com/digitalbitbox/bitbox02-api-go@8c31f23
    go mod vendor
    go mod tidy

commit c535485
Merge: a634dd4 0fe0d16
Author: Marko Bencun <[email protected]>
Date:   Thu Oct 27 12:22:54 2022 +0200

    Merge remote-tracking branch 'benma/cansend'

commit a634dd4
Merge: 55e2b7e 09741c6
Author: thisconnect <[email protected]>
Date:   Thu Oct 27 10:48:45 2022 +0200

    Merge branch 'frontend-sats-guide'

commit 09741c6
Author: thisconnect <[email protected]>
Date:   Wed Oct 26 14:47:03 2022 +0200

    frontend: update label and add guide entry for sats

    Added 'What is a Satoshi' guide entry on the settings page, as not
    all users might know what it is.

    Also reordered settings entry and moved which exchange rates up as
    second entry.

commit 0fe0d16
Author: Marko Bencun <[email protected]>
Date:   Wed Oct 26 15:58:52 2022 +0200

    frontend/account: fix CanSend and Buy call to action

    Since recently, BTC amounts are returned with trailing zeroes, so the
    `'0'` string comparison stopped working to check if there is a
    balance.

    Similar to `hasAvailable`, the backend should deliver the information.

commit 55e2b7e
Merge: c7a1d22 8e2add6
Author: Marko Bencun <[email protected]>
Date:   Wed Oct 26 14:00:56 2022 +0200

    Merge remote-tracking branch 'benma/btcunit'

commit c7a1d22
Merge: 0f9a4f0 771366b
Author: thisconnect <[email protected]>
Date:   Wed Oct 26 13:48:43 2022 +0200

    Merge branch 'frontend-translation-feedback'

commit 8e2add6
Author: Marko Bencun <[email protected]>
Date:   Wed Oct 26 11:14:17 2022 +0200

    ci: remove gocyclo linter

    It has not really forced us to refactor big functions, we kept bumping
    the min-complexity. Of course we should refactor where reasonable, but
    the linter wasn't so useful.

commit 630dd1b
Author: Marko Bencun <[email protected]>
Date:   Wed Oct 26 10:56:06 2022 +0200

    backend: add a BtcUnit type and use it everywhere to format sats

    Instead of 'BTC' | 'sat', we use 'default' | 'sat', to avoid confusion
    with BTC coin units which also include 'TBTC' for testnet.

    This helps with readability of the code, as the type and possible
    values are clear at every step.

commit 0f9a4f0
Merge: d45103a 2cdd792
Author: Marko Bencun <[email protected]>
Date:   Wed Oct 26 13:24:23 2022 +0200

    Merge branch 'attestation-nil'

commit 2cdd792
Author: Marko Bencun <[email protected]>
Date:   Wed Oct 26 11:46:20 2022 +0200

    frontend/bitbox02/settings: handle attestation==null

    The backend can in theory return nil/null in the attestation endpoint,
    if the endpoint is called before the device.Init() function has
    finished, where the attesation check is performed.

    The bb02 init is a bit messy, in the above state probably most/all
    other bb02 calls would be broken too. For now, we simply adjust the
    return type of `verifyAttestation()` to match the backend.

commit d45103a
Merge: 7268244 593aedc
Author: thisconnect <[email protected]>
Date:   Wed Oct 26 11:09:44 2022 +0200

    Merge branch 'frontend-txoverview-styling'

commit 593aedc
Author: thisconnect <[email protected]>
Date:   Mon Oct 3 13:36:40 2022 +0200

    frontend: fix coin and unit styling in tx overview

    Sometimes the unit breaks onto a separate line, this happens with
    large amounts or coins with lots of decimal for example with ETH.

    Changed styling so that very large amounts are cut off with "…",
    but only visually so that copy/paste contains takes the whole
    amount. This should also fix the issue with large amounts on
    small screen, in extreme cases the fiat amount should squeeze
    the coin amount together.

    Also added "font-variant: tabular-nums" definition for the amount
    so that all numbers take equal space, without using a monospace
    font.

commit 771366b
Author: thisconnect <[email protected]>
Date:   Thu Sep 29 09:33:37 2022 +0200

    frontend: add translation feedback link

    As we are continuously adding and updating translations, we should
    have a way to give feedback for the translations to help us catch
    translation errors.

    Added a mailto link at the bottom of the guide and allow mailto
    links to be opened by the backend.

    Keeping the translation feedback english-only for now, as it is
    better if we get feedback in english than in the native language.

commit 7268244
Merge: c147a51 9107a09
Author: beerosagos <[email protected]>
Date:   Tue Oct 25 17:59:26 2022 +0200

    Merge branch 'app-version'

commit 9107a09
Author: beerosagos <[email protected]>
Date:   Wed Sep 28 17:58:13 2022 +0200

    frontend: add available updates check in settings

    This adds a new `Info` section in settings, which states the current
    version of the App and, in case of available updates, offers a
    download link.

commit c147a51
Merge: 9976026 fdc9da2
Author: thisconnect <[email protected]>
Date:   Tue Oct 25 16:37:00 2022 +0200

    Merge branch 'frontend-nicer-pairing'

commit fdc9da2
Author: thisconnect <[email protected]>
Date:   Thu Oct 20 18:03:57 2022 +0200

    frontend: show point-to-device graphic on pairing step

    Before there was a disabled grayed out continue button on the
    pairing step when the user should focus on the device and
    confirm the code.

    Changed so that the is a point-to-device graphic without
    a disabled button. Once the pairing is confirmed it changes
    to a continue button.

commit 9976026
Merge: dd390f9 f5a2a82
Author: beerosagos <[email protected]>
Date:   Tue Oct 25 15:22:38 2022 +0200

    Merge branch 'sats-coin'

commit dd390f9
Merge: 169be46 bc63d73
Author: shonsirsha <[email protected]>
Date:   Tue Oct 25 12:38:35 2022 +0200

    Merge branch 'frontend-refactor-sdcardcheck'

commit bc63d73
Author: shonsirsha <[email protected]>
Date:   Mon Oct 24 16:03:46 2022 +0200

    frontend: converted SDCardCheck to a functional component

    as a part of the refactoring process and to follow the latest
    conventions in the frontend, class components need to be converted
    into functional components whenever possible.

commit 169be46
Merge: 47620fb 2880f90
Author: Marko Bencun <[email protected]>
Date:   Tue Oct 25 11:32:48 2022 +0200

    Merge remote-tracking branch 'benma/electrum-tsx'

commit 47620fb
Merge: b49cb73 b8d81a7
Author: thisconnect <[email protected]>
Date:   Tue Oct 25 10:53:09 2022 +0200

    Merge branch 'frontend-generic-continuebtn'

commit f5a2a82
Author: beerosagos <[email protected]>
Date:   Tue Sep 20 17:18:07 2022 +0200

    frontend: enable sats unit option for bitcoin accounts

    The main unit displayed in the app for bitcoin accounts is Bitcoin
    (BTC), but sometimes it can be easier to think in terms of Satoshi
    (sat), especially for lower amounts.

    This allows the user to choose the preferred unit using a
    switch in the expert settings section of the frontend.

commit 2880f90
Author: Marko Bencun <[email protected]>
Date:   Wed Oct 12 13:11:36 2022 +0200

    frontend/electrum: convert electrum-servers to a FunctionalComponent

commit a6f9cc4
Author: Marko Bencun <[email protected]>
Date:   Wed Oct 12 12:21:57 2022 +0200

    frontend/electrum: use api functions instead of apiGet/apiPost

commit 95eddbd
Author: Marko Bencun <[email protected]>
Date:   Wed Oct 12 12:08:09 2022 +0200

    frontend/electrum: convert to TypeScript and FunctionalComponent

commit b49cb73
Merge: bd70f6c eb761c9
Author: thisconnect <[email protected]>
Date:   Tue Oct 25 10:38:52 2022 +0200

    Merge branch 'frontend-eslint-commaspacing'

commit b8d81a7
Author: thisconnect <[email protected]>
Date:   Mon Oct 24 16:02:08 2022 +0200

    frontend: use generic continue translation

    The same translation for 'Continue' is used in various components,
    changed to use the same generic text everywhere instead of custom
    translation key.

commit eb761c9
Author: thisconnect <[email protected]>
Date:   Tue Oct 25 08:41:30 2022 +0200

    frontend: enable comma-spacing

    Ensure space after comma, e.g. `fn(a, b)` for better readability
    and consistency.

    Updated code with `make webfix`.

commit bd70f6c
Merge: ff6fada c2a7e1d
Author: Marko Bencun <[email protected]>
Date:   Mon Oct 24 10:02:01 2022 +0200

    Merge remote-tracking branch 'benma/bb02abort'

commit ff6fada
Merge: dd1cabb 2fbc8f0
Author: Marko Bencun <[email protected]>
Date:   Wed Oct 19 17:00:58 2022 +0200

    Merge remote-tracking branch 'benma/qttransport'

commit dd1cabb
Merge: 37c5587 d008aeb
Author: Marko Bencun <[email protected]>
Date:   Wed Oct 19 17:00:40 2022 +0200

    Merge remote-tracking branch 'benma/functional-entry'

commit 37c5587
Merge: 1e1e2c6 d739c60
Author: Marko Bencun <[email protected]>
Date:   Wed Oct 19 17:00:19 2022 +0200

    Merge remote-tracking branch 'benma/rem-envvar'

commit d739c60
Author: Marko Bencun <[email protected]>
Date:   Wed Oct 12 14:02:58 2022 +0200

    qt: remove unused QT_BITBOX_ALLOW_EXTERNAL_URLS

    Introduced in 8a27bfe to enable the
    in-app lociz editor, which was removed again in 29a0764.

commit d008aeb
Author: Marko Bencun <[email protected]>
Date:   Wed Oct 12 13:55:55 2022 +0200

    frontend/guide/entry: convert to FunctionalComponent

    The entry property was also changed from `EntryProp | string` to
    `EntryProp`, as the locize in-app editor (`cimode`) does not exist
    anymore (removed in 29a0764).

commit fdbcbf2
Author: Marko Bencun <[email protected]>
Date:   Wed Oct 12 13:42:12 2022 +0200

    frontend/guide/entry: remove unused property 'highlighted'

commit a4b75af
Author: Marko Bencun <[email protected]>
Date:   Wed Oct 12 11:48:01 2022 +0200

    frontend/settings: split electrum.jsx into one file per component

    Easier to convert to typescript piece by piece.

commit 2fbc8f0
Author: Marko Bencun <[email protected]>
Date:   Wed Oct 12 11:04:06 2022 +0200

    frontend/qttransport: fully initialize channel before returning it

    I didn't observe a bug, but it is probably good to fully initialize
    the channel before returning it.

commit 2475d8e
Author: Marko Bencun <[email protected]>
Date:   Wed Oct 12 10:39:58 2022 +0200

    frontend/qttransport: make initTransport more readable

    Use async/wait instead of Promises for greater readability. This also
    removes the need for using the `cache` variable, which was only used
    to indicate that we were waiting for the webchannel to be initialized.

commit 1e1e2c6
Merge: 4e4e78d cf5b493
Author: beerosagos <[email protected]>
Date:   Tue Oct 11 08:13:25 2022 +0200

    Merge branch 'android-link'

commit c2a7e1d
Author: Marko Bencun <[email protected]>
Date:   Thu Sep 8 14:18:55 2022 +0200

    frontend/bitbox02: abort SetPassword when the user aborts

    Before, the error was always assumed to be the password mismatch
    error, and the SetPassword workflow was invoked again immediately.

    Now we go back to the initial screen if the user aborts.

    The BitBox02 only returns the user abot error from this API endpoint
    from v9.13.0, before the two types of errors can not be distinguished.

commit 4e4e78d
Merge: b453ea3 bf91c80
Author: Marko Bencun <[email protected]>
Date:   Tue Oct 11 01:02:33 2022 +0200

    Merge remote-tracking branch 'benma/android-zimezone'

commit b453ea3
Merge: 93eee08 3d361b4
Author: Marko Bencun <[email protected]>
Date:   Tue Oct 11 00:49:46 2022 +0200

    Merge remote-tracking branch 'benma/android-31'

commit cf5b493
Author: beerosagos <[email protected]>
Date:   Mon Oct 10 15:03:46 2022 +0200

    android: add external link queries for Android 11 permissions

    With Android 11 the visibility of the installed packages has been
    filtered to offer a higher privacy level to the user. This commit add
    to AndroidManifest.xml the `queries` elements needed to open external
    links for web pages and `mailto` urls.

    Queries support is not granted in all Gradle versions. For this reason,
    the latter has been updated to v3.5.4.

commit 93eee08
Merge: 64d1fe5 071e65b
Author: thisconnect <[email protected]>
Date:   Thu Oct 6 16:17:25 2022 +0200

    Merge branch 'frontend-type-transports'

commit 071e65b
Author: thisconnect <[email protected]>
Date:   Mon Sep 19 13:01:31 2022 +0200

    frontend: type qt and android transport

    - updated global qt definition
    - added global definitions related to android
    - removed some unnecessary @ts-ignore related global android
    - moved common types to transport.common.ts to be able to share it
      (same types in qttransport.ts and androidtransport.ts)
    - typed request.ts but exact return type has to be defined in api,
      request just returns Promise<any> for now
    - the common types currently contains TMsgCallback, that is a call
      back type containing the payload pushed from the backend, temp.
      set to any but will be typed in the next PR with both legacy and
      new events

commit 64d1fe5
Merge: addf34b 4359eb5
Author: beerosagos <[email protected]>
Date:   Thu Oct 6 14:53:32 2022 +0200

    Merge branch 'android-build'

commit 4359eb5
Author: beerosagos <[email protected]>
Date:   Thu Oct 6 09:39:20 2022 +0200

    docs/BUILD.md: update instructions for Android build and deploy

    Updated BUILD.md with up to date instructions for Android build and
    deploy.

commit addf34b
Merge: 0ba090e aacd2d3
Author: beerosagos <[email protected]>
Date:   Wed Oct 5 15:54:52 2022 +0200

    Merge branch 'btc-formatting'

commit aacd2d3
Author: beerosagos <[email protected]>
Date:   Wed Sep 21 12:11:50 2022 +0200

    frontend: adding trailing zeroes to BTC and LTC formatting

    Added trailing zeroes when displaying BTC/LTC amounts in the frontend,
    with the exception of the balances displayed in the header of account and
    accountsummary views.

commit 0ba090e
Merge: 69a1d52 762add1
Author: beerosagos <[email protected]>
Date:   Wed Oct 5 13:29:49 2022 +0200

    Merge branch 'eth-testnet'

commit 762add1
Author: beerosagos <[email protected]>
Date:   Tue Oct 4 16:22:21 2022 +0200

    vendor: update bitbox02-api-go dependency

    ```
    go get github.com/digitalbitbox/bitbox02-api-go@2c29561c5a4ca7f943f9d40b5ecd4e28da10fb17
    go mod tidy
    go mod vendor
    ```

commit ff44918
Author: beerosagos <[email protected]>
Date:   Tue Sep 27 09:42:42 2022 +0200

    backend: add Goerli ETH testnet network

    ETH merge happened recently, and Ropsten and Rinkeby testnets will soon
    be deprecated from Etherscan. This add support for the new Goerli testnet.

commit 69a1d52
Merge: c9674d4 32387d1
Author: beerosagos <[email protected]>
Date:   Wed Oct 5 13:15:54 2022 +0200

    Merge branch 'rates-error'

commit c9674d4
Merge: cae608e 6cd7d12
Author: thisconnect <[email protected]>
Date:   Wed Oct 5 12:40:34 2022 +0200

    Merge branch 'frontend-refactor-account-III'

commit 32387d1
Author: beerosagos <[email protected]>
Date:   Wed Oct 5 12:18:36 2022 +0200

    backend/conversions: fix nil conversions when rates not available

    Unexpected errors from coingecko service were causing the backend to send
    amounts with nil conversions field, which caused runtime errors on the
    frontend. With this update, a != nil conversions field should always be
    available even when coingecko errors accour, allowing the frontend to
    handle the situation without blocks.

commit 6cd7d12
Author: thisconnect <[email protected]>
Date:   Wed Oct 5 12:00:34 2022 +0200

    frontend: remove old account type information

    This was used before unified accounts were introduced. Removing.

commit f28a897
Author: thisconnect <[email protected]>
Date:   Wed Jul 27 09:29:49 2022 +0200

    frontend: refactor account to functional component

    Ongoing effort to rewrite all class based components to functional
    components so we can use hooks.

    - typed check-sdcard api
    - typed buy-supported api
    - remove load decorator and load config directly

commit cae608e
Merge: 1b6370c e730b19
Author: beerosagos <[email protected]>
Date:   Wed Oct 5 11:28:32 2022 +0200

    Merge branch 'fiat-historical'

commit e730b19
Author: beerosagos <[email protected]>
Date:   Wed Sep 21 15:07:25 2022 +0200

    frontend: modify fiat historical value placeholder in tx

    Fiat historical value is shown in tx detail. If the transaction is
    recent the value could be not available. The placeholder we used was
    '---' which led to poorly readable results for incoming/outgoing txs
    ('+---' or '----'). Now, if the amount is not available the placeholder
    is shown without the sign, which should be more readable.

    In the future it would be nice to refactor the FiatConversion component
    and limit the `sign` prop to '+' | '-'.

commit bf91c80
Author: Marko Bencun <[email protected]>
Date:   Tue Oct 4 21:20:40 2022 +0200

    android: fix timezone so the BitBox02 shows the correct time

    On Android, due to a bug in
    Go (golang/go#20455), the local timezone is
    not correct. It is always UTC.

    As a result, when restoring a backup on the BitBox02, the BitBox02
    displays the current time in UTC instead of the local time.

    This commit contains a workaround to fix the timezone on Android.

    Alternative considered: getting the timezone offset in native Android code and sending it
    to Go-land via backend.Environment. I did not pursue this as a quick
    search didn't turn up an easy way to get the timezone offset on
    Android which takes into account daylight-savings etc.

commit 1b6370c
Merge: 6054a36 47810e4
Author: thisconnect <[email protected]>
Date:   Tue Oct 4 16:23:09 2022 +0200

    Merge branch 'frontend-account-guide'

commit 47810e4
Author: thisconnect <[email protected]>
Date:   Tue Oct 4 16:00:32 2022 +0200

    frontend: remove old split account specific guide entries

    These were used in the settings page when we used to have separate
    accounts per script type, with toggles for each one. this is also
    all gone now with unified accounts and the multi-accounts feature.

    Also: there is now a script type guide in the receive screen.

commit b1a2e72
Author: thisconnect <[email protected]>
Date:   Tue Jul 26 17:36:29 2022 +0200

    frontend: move account guide to its own component

    Moved isBTCScriptType to utils and the account guide to its own
    component so that account.tsx is slightly simpler and easier to
    refactor.

commit 3d361b4
Author: Marko Bencun <[email protected]>
Date:   Tue Oct 4 10:51:02 2022 +0200

    android: target api level 31, enforced by Google Play

    According to
    https://support.google.com/googleplay/android-developer/answer/11926878,
    the requirements as of now is that updating an app requires API level
    31 (Android 12) by November 1st 2022.

    The exported attribute is set according to
    https://developer.android.com/about/versions/12/behavior-changes-12#exported:

    > If your app targets Android 12 or higher and contains activities,
    services, or broadcast receivers that use intent filters, you must
    explicitly declare the android:exported attribute for these app
    components.

commit 094abeb
Author: jadzeidan <[email protected]>
Date:   Mon Oct 3 21:09:12 2022 +0200

    frontends: color variables refactoring

    Seperated text and background colors into their own variables. This makes colors easier to maintain because now it's possible to change text and background colors without affecting each other.

    Also some text used --color-softblack instead of a designated /* font colors */ variable. Changed this text to --color-default so it is consistant with the other text colors.
  • Loading branch information
jadzeidan committed Oct 28, 2022
1 parent 6054a36 commit acd0fb0
Show file tree
Hide file tree
Showing 128 changed files with 2,249 additions and 1,403 deletions.
4 changes: 1 addition & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ linters-settings:
- underef
- unlambda
- unslice
gocyclo:
min-complexity: 27
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
Expand Down Expand Up @@ -132,6 +130,7 @@ linters:
- forbidigo
- makezero
- nolintlint
- gocyclo
disable-all: false

issues:
Expand All @@ -150,7 +149,6 @@ issues:
- path: _test\.go
linters:
- errcheck
- gocyclo
- godot
- gosec
- testpackage
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
- Render number of blocks scanned and percentage progress using fixed-width digits for a more stable UI
- Transaction details: show fiat value at time of transaction
- Android: more modern look by changing the status bar color to white while the app is running
- Android: fix time shown on BitBox02 when restoring a backup (it was shown in UTC instead of local time)
- Fix update balance after transaction sent
- Fix missing utxos update after new transaction is sent
- Add attestation check on device setting
- Fix unsufficient gas funds error message on erc20 transactions
- Display trailing zeroes for BTC/LTC amount formatting
- Fix broken links on Android 11+
- Add 'sat' unit for Bitcoin accounts, available in Settings view
- Add version number and available updates check in settings
- Add translation feedback link in the guide

## 4.34.0
- Bundle BitBox02 firmware version v9.12.0
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,5 @@ Get Litecoin Testnet coins here: https://tltc.bitaps.com/
Get Ethereum Rinkeby coins here: http://rinkeby-faucet.com/

Get Ethereum Ropsten coins here: https://faucet.ropsten.be/

Get Ethereum Goerli coins here: https://goerlifaucet.com/
22 changes: 12 additions & 10 deletions backend/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ const accountsHardLimit = 5
func sortAccounts(accounts []*config.Account) {
compareCoin := func(coin1, coin2 coinpkg.Code) int {
order := map[coinpkg.Code]int{
coinpkg.CodeBTC: 0,
coinpkg.CodeTBTC: 1,
coinpkg.CodeLTC: 2,
coinpkg.CodeTLTC: 3,
coinpkg.CodeETH: 4,
coinpkg.CodeTETH: 5,
coinpkg.CodeRETH: 6,
coinpkg.CodeBTC: 0,
coinpkg.CodeTBTC: 1,
coinpkg.CodeLTC: 2,
coinpkg.CodeTLTC: 3,
coinpkg.CodeETH: 4,
coinpkg.CodeTETH: 5,
coinpkg.CodeRETH: 6,
coinpkg.CodeGOETH: 7,
}
order1, ok1 := order[coin1]
order2, ok2 := order[coin2]
Expand Down Expand Up @@ -116,7 +117,7 @@ func (backend *Backend) SupportedCoins(keystore keystore.Keystore) []coinpkg.Cod
allCoins := []coinpkg.Code{
coinpkg.CodeBTC, coinpkg.CodeTBTC, coinpkg.CodeRBTC,
coinpkg.CodeLTC, coinpkg.CodeTLTC,
coinpkg.CodeETH, coinpkg.CodeTETH, coinpkg.CodeRETH,
coinpkg.CodeETH, coinpkg.CodeTETH, coinpkg.CodeRETH, coinpkg.CodeGOETH,
}
var availableCoins []coinpkg.Code
for _, coinCode := range allCoins {
Expand Down Expand Up @@ -221,7 +222,7 @@ func (backend *Backend) createAndPersistAccountConfig(
},
accountsConfig,
)
case coinpkg.CodeETH, coinpkg.CodeRETH, coinpkg.CodeTETH:
case coinpkg.CodeETH, coinpkg.CodeRETH, coinpkg.CodeTETH, coinpkg.CodeGOETH:
bip44Coin := "1'"
if coinCode == coinpkg.CodeETH {
bip44Coin = "60'"
Expand Down Expand Up @@ -406,6 +407,7 @@ func (backend *Backend) createAndAddAccount(
},
GetSaveFilename: backend.environment.GetSaveFilename,
UnsafeSystemOpen: backend.environment.SystemOpen,
BtcCurrencyUnit: backend.config.AppConfig().Backend.BtcUnit,
}

switch specificCoin := coin.(type) {
Expand Down Expand Up @@ -672,7 +674,7 @@ func (backend *Backend) persistDefaultAccountConfigs(keystore keystore.Keystore,
}
}
} else {
for _, coinCode := range []coinpkg.Code{coinpkg.CodeTBTC, coinpkg.CodeTLTC, coinpkg.CodeTETH, coinpkg.CodeRETH} {
for _, coinCode := range []coinpkg.Code{coinpkg.CodeTBTC, coinpkg.CodeTLTC, coinpkg.CodeTETH, coinpkg.CodeRETH, coinpkg.CodeGOETH} {
if backend.config.AppConfig().Backend.DeprecatedCoinActive(coinCode) {
if _, err := backend.createAndPersistAccountConfig(coinCode, 0, "", keystore, nil, accountsConfig); err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions backend/accounts/baseaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ type AccountConfig struct {
GetSaveFilename func(suggestedFilename string) string
// Opens a file in a default application. The filename is not checked.
UnsafeSystemOpen func(filename string) error
// BtcCurrencyUnit is the unit which should be used to format fiat amounts values expressed in BTC..
BtcCurrencyUnit coin.BtcUnit
}

// BaseAccount is an account struct with common functionality to all coin accounts.
Expand Down
2 changes: 1 addition & 1 deletion backend/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func TestSupportedCoins(t *testing.T) {
b := newBackend(t, testnetEnabled, regtestDisabled)
defer b.Close()
require.Equal(t,
[]coinpkg.Code{coinpkg.CodeTBTC, coinpkg.CodeTLTC, coinpkg.CodeTETH, coinpkg.CodeRETH},
[]coinpkg.Code{coinpkg.CodeTBTC, coinpkg.CodeTLTC, coinpkg.CodeTETH, coinpkg.CodeRETH, coinpkg.CodeGOETH},
b.SupportedCoins(&keystoremock.KeystoreMock{
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
return true
Expand Down
19 changes: 14 additions & 5 deletions backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ var fixedURLWhitelist = []string{
"https://etherscan.io/tx/",
"https://rinkeby.etherscan.io/tx/",
"https://ropsten.etherscan.io/tx/",
"https://goerli.etherscan.io/tx/",
// Moonpay onramp
"https://www.moonpay.com/",
"https://support.moonpay.com/",
Expand All @@ -87,6 +88,7 @@ var fixedURLWhitelist = []string{
"https://en.bitcoin.it/wiki/Bech32_adoption",
// Others
"https://cointracking.info/import/bitbox/",
"mailto:[email protected]?",
}

type backendEvent struct {
Expand Down Expand Up @@ -342,25 +344,26 @@ func (backend *Backend) Coin(code coinpkg.Code) (coinpkg.Coin, error) {
dbFolder := backend.arguments.CacheDirectoryPath()

erc20Token := erc20TokenByCode(code)
btcFormatUnit := backend.config.AppConfig().Backend.BtcUnit
switch {
case code == coinpkg.CodeRBTC:
servers := backend.defaultElectrumXServers(code)
coin = btc.NewCoin(coinpkg.CodeRBTC, "Bitcoin Regtest", "RBTC", &chaincfg.RegressionNetParams, dbFolder, servers, "", backend.socksProxy)
coin = btc.NewCoin(coinpkg.CodeRBTC, "Bitcoin Regtest", "RBTC", coinpkg.BtcUnitDefault, &chaincfg.RegressionNetParams, dbFolder, servers, "", backend.socksProxy)
case code == coinpkg.CodeTBTC:
servers := backend.defaultElectrumXServers(code)
coin = btc.NewCoin(coinpkg.CodeTBTC, "Bitcoin Testnet", "TBTC", &chaincfg.TestNet3Params, dbFolder, servers,
coin = btc.NewCoin(coinpkg.CodeTBTC, "Bitcoin Testnet", "TBTC", btcFormatUnit, &chaincfg.TestNet3Params, dbFolder, servers,
"https://blockstream.info/testnet/tx/", backend.socksProxy)
case code == coinpkg.CodeBTC:
servers := backend.defaultElectrumXServers(code)
coin = btc.NewCoin(coinpkg.CodeBTC, "Bitcoin", "BTC", &chaincfg.MainNetParams, dbFolder, servers,
coin = btc.NewCoin(coinpkg.CodeBTC, "Bitcoin", "BTC", btcFormatUnit, &chaincfg.MainNetParams, dbFolder, servers,
"https://blockstream.info/tx/", backend.socksProxy)
case code == coinpkg.CodeTLTC:
servers := backend.defaultElectrumXServers(code)
coin = btc.NewCoin(coinpkg.CodeTLTC, "Litecoin Testnet", "TLTC", &ltc.TestNet4Params, dbFolder, servers,
coin = btc.NewCoin(coinpkg.CodeTLTC, "Litecoin Testnet", "TLTC", coinpkg.BtcUnitDefault, &ltc.TestNet4Params, dbFolder, servers,
"http://explorer.litecointools.com/tx/", backend.socksProxy)
case code == coinpkg.CodeLTC:
servers := backend.defaultElectrumXServers(code)
coin = btc.NewCoin(coinpkg.CodeLTC, "Litecoin", "LTC", &ltc.MainNetParams, dbFolder, servers,
coin = btc.NewCoin(coinpkg.CodeLTC, "Litecoin", "LTC", coinpkg.BtcUnitDefault, &ltc.MainNetParams, dbFolder, servers,
"https://insight.litecore.io/tx/", backend.socksProxy)
case code == coinpkg.CodeETH:
etherScan := etherscan.NewEtherScan("https://api.etherscan.io/api", backend.etherScanHTTPClient)
Expand All @@ -380,6 +383,12 @@ func (backend *Backend) Coin(code coinpkg.Code) (coinpkg.Coin, error) {
"https://ropsten.etherscan.io/tx/",
etherScan,
nil)
case code == coinpkg.CodeGOETH:
etherScan := etherscan.NewEtherScan("https://api-goerli.etherscan.io/api", backend.etherScanHTTPClient)
coin = eth.NewCoin(etherScan, code, "Ethereum Goerli", "GOETH", "GOETH", params.GoerliChainConfig,
"https://goerli.etherscan.io/tx/",
etherScan,
nil)
case code == coinpkg.CodeERC20TEST:
etherScan := etherscan.NewEtherScan("https://api-ropsten.etherscan.io/api", backend.etherScanHTTPClient)
coin = eth.NewCoin(etherScan, code, "ERC20 TEST", "TEST", "TETH", params.RopstenChainConfig,
Expand Down
17 changes: 13 additions & 4 deletions backend/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (

"github.com/digitalbitbox/bitbox-wallet-app/backend/accounts"
"github.com/digitalbitbox/bitbox-wallet-app/backend/accounts/errors"
"github.com/digitalbitbox/bitbox-wallet-app/backend/coins/btc/util"
"github.com/digitalbitbox/bitbox-wallet-app/backend/coins/coin"
"github.com/digitalbitbox/bitbox-wallet-app/backend/rates"
"github.com/digitalbitbox/bitbox-wallet-app/util/errp"
)

Expand Down Expand Up @@ -124,6 +126,8 @@ func (backend *Backend) ChartData() (*Chart, error) {
}
isUpToDate := time.Since(until) < 2*time.Hour

formatBtcAsSat := util.FormatBtcAsSat(backend.Config().AppConfig().Backend.BtcUnit)

currentTotal := new(big.Rat)
currentTotalMissing := false
// Total number of transactions across all active accounts.
Expand Down Expand Up @@ -254,7 +258,7 @@ func (backend *Backend) ChartData() (*Chart, error) {
result[i] = ChartEntry{
Time: entry.Time,
Value: floatValue,
FormattedValue: coin.FormatAsCurrency(entry.RatValue, fiat),
FormattedValue: coin.FormatAsCurrency(entry.RatValue, fiat, formatBtcAsSat),
}
i++
}
Expand All @@ -270,7 +274,7 @@ func (backend *Backend) ChartData() (*Chart, error) {
result = append(result, ChartEntry{
Time: time.Now().Unix(),
Value: total,
FormattedValue: coin.FormatAsCurrency(currentTotal, fiat),
FormattedValue: coin.FormatAsCurrency(currentTotal, fiat, formatBtcAsSat),
})
}

Expand All @@ -292,18 +296,23 @@ func (backend *Backend) ChartData() (*Chart, error) {
chartDataMissing = false
}

chartFiat := fiat
if fiat == rates.BTC.String() && backend.Config().AppConfig().Backend.BtcUnit == coin.BtcUnitSats {
chartFiat = "sat"
}

var chartTotal *float64
var formattedChartTotal string
if !currentTotalMissing {
tot, _ := currentTotal.Float64()
chartTotal = &tot
formattedChartTotal = coin.FormatAsCurrency(currentTotal, fiat)
formattedChartTotal = coin.FormatAsCurrency(currentTotal, fiat, formatBtcAsSat)
}
return &Chart{
DataMissing: chartDataMissing,
DataDaily: toSortedSlice(chartEntriesDaily, fiat),
DataHourly: toSortedSlice(chartEntriesHourly, fiat),
Fiat: fiat,
Fiat: chartFiat,
Total: chartTotal,
FormattedTotal: formattedChartTotal,
IsUpToDate: isUpToDate,
Expand Down
2 changes: 1 addition & 1 deletion backend/coins/btc/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestAccount(t *testing.T) {
defer func() { _ = os.RemoveAll(dbFolder) }()

coin := btc.NewCoin(
code, "Bitcoin Testnet", unit, net, dbFolder, nil, explorer, socksproxy.NewSocksProxy(false, ""))
code, "Bitcoin Testnet", unit, coin.BtcUnitDefault, net, dbFolder, nil, explorer, socksproxy.NewSocksProxy(false, ""))

blockchainMock := &blockchainMock.BlockchainMock{}
blockchainMock.MockRegisterOnConnectionErrorChangedEvent = func(f func(error)) {}
Expand Down
54 changes: 46 additions & 8 deletions backend/coins/btc/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"math/big"
"os"
"path"
"strings"
"sync"

"github.com/btcsuite/btcd/btcutil"
Expand All @@ -42,10 +41,13 @@ import (

// Coin models a Bitcoin-related coin.
type Coin struct {
initOnce sync.Once
code coinpkg.Code
name string
unit string
initOnce sync.Once
code coinpkg.Code
name string
// unit is the main unit of the coin, e.g. 'BTC'
unit string
// formatUnit keeps track of the unit used, e.g. 'BTC' or 'sat' depening on if sat mode is enabled
formatUnit coinpkg.BtcUnit
net *chaincfg.Params
dbFolder string
makeBlockchain func() blockchain.Interface
Expand All @@ -64,6 +66,7 @@ func NewCoin(
code coinpkg.Code,
name string,
unit string,
formatUnit coinpkg.BtcUnit,
net *chaincfg.Params,
dbFolder string,
servers []*config.ServerInfo,
Expand All @@ -75,6 +78,7 @@ func NewCoin(
code: code,
name: name,
unit: unit,
formatUnit: formatUnit,
net: net,
dbFolder: dbFolder,
blockExplorerTxPrefix: blockExplorerTxPrefix,
Expand Down Expand Up @@ -151,15 +155,36 @@ func (coin *Coin) Unit(bool) string {
return coin.unit
}

// SetFormatUnit implements coin.Coin.
func (coin *Coin) SetFormatUnit(unit coinpkg.BtcUnit) {
coin.formatUnit = unit
}

// GetFormatUnit implements coin.Coin.
func (coin *Coin) GetFormatUnit() string {
if coin.formatUnit == coinpkg.BtcUnitSats {
switch coin.code {
case coinpkg.CodeBTC:
return "sat"
case coinpkg.CodeTBTC:
return "tsat"
}
}

return coin.unit
}

// Decimals implements coinpkg.Coin.
func (coin *Coin) Decimals(isFee bool) uint {
return 8
}

// FormatAmount implements coinpkg.Coin.
func (coin *Coin) FormatAmount(amount coinpkg.Amount, isFee bool) string {
s := new(big.Rat).SetFrac(amount.BigInt(), big.NewInt(unitSatoshi)).FloatString(8)
return strings.TrimRight(strings.TrimRight(s, "0"), ".")
if coin.formatUnit == coinpkg.BtcUnitSats {
return amount.BigInt().String()
}
return new(big.Rat).SetFrac(amount.BigInt(), big.NewInt(unitSatoshi)).FloatString(8)
}

// ToUnit implements coinpkg.Coin.
Expand All @@ -170,11 +195,24 @@ func (coin *Coin) ToUnit(amount coinpkg.Amount, isFee bool) float64 {

// SetAmount implements coinpkg.Coin.
func (coin *Coin) SetAmount(amount *big.Rat, isFee bool) coinpkg.Amount {
satsAmount := new(big.Rat).Mul(amount, new(big.Rat).SetFloat64(unitSatoshi))
satsAmount := coinpkg.Btc2Sat(amount)
intSatsAmount, _ := new(big.Int).SetString(satsAmount.FloatString(0), 0)
return coinpkg.NewAmount(intSatsAmount)
}

// ParseAmount implements coinpkg.Coin.
func (coin *Coin) ParseAmount(amount string) (coinpkg.Amount, error) {
amountRat, valid := new(big.Rat).SetString(amount)
if !valid {
return coinpkg.Amount{}, errp.New("Invalid amount")
}

if coin.formatUnit == coinpkg.BtcUnitSats {
amountRat = coinpkg.Sat2Btc(amountRat)
}
return coin.SetAmount(amountRat, false), nil
}

// Blockchain connects to a blockchain backend.
func (coin *Coin) Blockchain() blockchain.Interface {
return coin.blockchain
Expand Down
Loading

0 comments on commit acd0fb0

Please sign in to comment.