Skip to content

Commit 797af2f

Browse files
committed
Merge branch 'duplicate_imports'
2 parents fa03491 + 91fa2b6 commit 797af2f

File tree

4 files changed

+34
-39
lines changed

4 files changed

+34
-39
lines changed

backend/accounts.go

+11-13
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ import (
2424
"time"
2525

2626
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/accounts"
27-
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/accounts/types"
2827
accountsTypes "github.com/BitBoxSwiss/bitbox-wallet-app/backend/accounts/types"
2928
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/bitsurance"
3029
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/btc"
31-
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/coin"
3230
coinpkg "github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/coin"
3331
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/eth"
3432
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/config"
@@ -253,7 +251,7 @@ func (backend *Backend) accountFiatBalance(account accounts.Interface, fiat stri
253251
return nil, err
254252
}
255253

256-
coinDecimals := coin.DecimalsExp(account.Coin())
254+
coinDecimals := coinpkg.DecimalsExp(account.Coin())
257255
price, err := backend.RatesUpdater().LatestPriceForPair(account.Coin().Unit(false), fiat)
258256
if err != nil {
259257
return nil, err
@@ -357,9 +355,9 @@ func (backend *Backend) LookupInsuredAccounts(accountCode accountsTypes.Code) ([
357355
if !ok {
358356
frontendConfig = make(map[string]interface{})
359357
}
360-
canceledAccounts, ok := frontendConfig["bitsuranceNotifyCancellation"].([]types.Code)
358+
canceledAccounts, ok := frontendConfig["bitsuranceNotifyCancellation"].([]accountsTypes.Code)
361359
if !ok {
362-
frontendConfig["bitsuranceNotifyCancellation"] = []types.Code{bitsuranceAccount.AccountCode}
360+
frontendConfig["bitsuranceNotifyCancellation"] = []accountsTypes.Code{bitsuranceAccount.AccountCode}
363361
} else {
364362
canceledAccounts = append(canceledAccounts, bitsuranceAccount.AccountCode)
365363
frontendConfig["bitsuranceNotifyCancellation"] = canceledAccounts
@@ -413,12 +411,12 @@ func (backend *Backend) createAndPersistAccountConfig(
413411
if err != nil {
414412
return "", err
415413
}
416-
coin, err := backend.Coin(coinCode)
414+
accountCoin, err := backend.Coin(coinCode)
417415
if err != nil {
418416
return "", err
419417
}
420418
if name == "" {
421-
name = defaultAccountName(coin, accountNumber)
419+
name = defaultAccountName(accountCoin, accountNumber)
422420
}
423421

424422
// v0 prefix: in case this code turns out to be not unique in the future, we can switch to 'v1-'
@@ -438,7 +436,7 @@ func (backend *Backend) createAndPersistAccountConfig(
438436
if coinCode == coinpkg.CodeBTC {
439437
bip44Coin = hardenedKeystart
440438
}
441-
return accountCode, backend.persistBTCAccountConfig(keystore, coin,
439+
return accountCode, backend.persistBTCAccountConfig(keystore, accountCoin,
442440
accountCode,
443441
hiddenBecauseUnused,
444442
name,
@@ -455,7 +453,7 @@ func (backend *Backend) createAndPersistAccountConfig(
455453
if coinCode == coinpkg.CodeLTC {
456454
bip44Coin = 2 + hardenedKeystart
457455
}
458-
return accountCode, backend.persistBTCAccountConfig(keystore, coin,
456+
return accountCode, backend.persistBTCAccountConfig(keystore, accountCoin,
459457
accountCode,
460458
hiddenBecauseUnused,
461459
name,
@@ -471,7 +469,7 @@ func (backend *Backend) createAndPersistAccountConfig(
471469
bip44Coin = "60'"
472470
}
473471
return accountCode, backend.persistETHAccountConfig(
474-
keystore, coin, accountCode, hiddenBecauseUnused,
472+
keystore, accountCoin, accountCode, hiddenBecauseUnused,
475473
// TODO: Use []uint32 instead of a string keypath
476474
fmt.Sprintf("m/44'/%s/0'/0/%d", bip44Coin, accountNumber),
477475
name,
@@ -1254,11 +1252,11 @@ func (backend *Backend) maybeAddP2TR(keystore keystore.Keystore, accounts []*con
12541252
if account.CoinCode == coinpkg.CodeBTC ||
12551253
account.CoinCode == coinpkg.CodeTBTC ||
12561254
account.CoinCode == coinpkg.CodeRBTC {
1257-
coin, err := backend.Coin(account.CoinCode)
1255+
accountCoin, err := backend.Coin(account.CoinCode)
12581256
if err != nil {
12591257
return err
12601258
}
1261-
if keystore.SupportsAccount(coin, signing.ScriptTypeP2TR) &&
1259+
if keystore.SupportsAccount(accountCoin, signing.ScriptTypeP2TR) &&
12621260
account.SigningConfigurations.FindScriptType(signing.ScriptTypeP2TR) == -1 {
12631261
rootFingerprint, err := backend.keystore.RootFingerprint()
12641262
if err != nil {
@@ -1276,7 +1274,7 @@ func (backend *Backend) maybeAddP2TR(keystore keystore.Keystore, accounts []*con
12761274
86+hdkeychain.HardenedKeyStart,
12771275
bip44Coin,
12781276
uint32(accountNumber)+hdkeychain.HardenedKeyStart)
1279-
extendedPublicKey, err := keystore.ExtendedPublicKey(coin, keypath)
1277+
extendedPublicKey, err := keystore.ExtendedPublicKey(accountCoin, keypath)
12801278
if err != nil {
12811279
return err
12821280
}

backend/coins/eth/coin.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"strings"
2121

2222
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/accounts"
23-
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/coin"
2423
coinpkg "github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/coin"
2524
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/eth/erc20"
2625
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/eth/rpcclient"
@@ -45,7 +44,7 @@ type TransactionsSource interface {
4544
type Coin struct {
4645
observable.Implementation
4746
client rpcclient.Interface
48-
code coin.Code
47+
code coinpkg.Code
4948
name string
5049
unit string
5150
feeUnit string
@@ -65,7 +64,7 @@ type Coin struct {
6564
// For erc20 tokens, provide erc20Token using NewERC20Token() (otherwise keep nil).
6665
func NewCoin(
6766
client rpcclient.Interface,
68-
code coin.Code,
67+
code coinpkg.Code,
6968
name string,
7069
unit string,
7170
feeUnit string,
@@ -117,7 +116,7 @@ func (coin *Coin) Name() string {
117116
}
118117

119118
// Code implements coin.Coin.
120-
func (coin *Coin) Code() coin.Code {
119+
func (coin *Coin) Code() coinpkg.Code {
121120
return coin.code
122121
}
123122

@@ -151,21 +150,21 @@ func (coin *Coin) unitFactor(isFee bool) *big.Int {
151150
}
152151

153152
// FormatAmount implements coin.Coin.
154-
func (coin *Coin) FormatAmount(amount coin.Amount, isFee bool) string {
153+
func (coin *Coin) FormatAmount(amount coinpkg.Amount, isFee bool) string {
155154
factor := coin.unitFactor(isFee)
156155
s := new(big.Rat).SetFrac(amount.BigInt(), factor).FloatString(18)
157156
return strings.TrimRight(strings.TrimRight(s, "0"), ".")
158157
}
159158

160159
// ToUnit implements coin.Coin.
161-
func (coin *Coin) ToUnit(amount coin.Amount, isFee bool) float64 {
160+
func (coin *Coin) ToUnit(amount coinpkg.Amount, isFee bool) float64 {
162161
factor := coin.unitFactor(isFee)
163162
result, _ := new(big.Rat).SetFrac(amount.BigInt(), factor).Float64()
164163
return result
165164
}
166165

167166
// SetAmount implements coin.Coin.
168-
func (coin *Coin) SetAmount(amount *big.Rat, isFee bool) coin.Amount {
167+
func (coin *Coin) SetAmount(amount *big.Rat, isFee bool) coinpkg.Amount {
169168
factor := coin.unitFactor(isFee)
170169
weiAmount := new(big.Rat).Mul(amount, new(big.Rat).SetInt(factor))
171170
intWeiAmount, _ := new(big.Int).SetString(weiAmount.FloatString(0), 0)

backend/devices/bitbox02/device.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package bitbox02
1818

1919
import (
20-
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/devices/device/event"
2120
deviceevent "github.com/BitBoxSwiss/bitbox-wallet-app/backend/devices/device/event"
2221
keystoreInterface "github.com/BitBoxSwiss/bitbox-wallet-app/backend/keystore"
2322
"github.com/BitBoxSwiss/bitbox-wallet-app/util/logging"
@@ -133,7 +132,7 @@ func (device *Device) Keystore() keystoreInterface.Keystore {
133132
}
134133

135134
// SetOnEvent implements device.Device.
136-
func (device *Device) SetOnEvent(onEvent func(event.Event, interface{})) {
135+
func (device *Device) SetOnEvent(onEvent func(deviceevent.Event, interface{})) {
137136
}
138137

139138
// Reset factory resets the device.

backend/handlers/handlers.go

+16-17
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import (
3535
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/btc"
3636
accountHandlers "github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/btc/handlers"
3737
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/btc/util"
38-
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/coin"
3938
coinpkg "github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/coin"
4039
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/eth"
4140
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/config"
@@ -703,17 +702,17 @@ func (handlers *Handlers) postBtcFormatUnit(r *http.Request) interface{} {
703702
// getAccountsBalanceHandler returns the balance of all the accounts, grouped by keystore and coin.
704703
func (handlers *Handlers) getAccountsBalance(*http.Request) interface{} {
705704
type response struct {
706-
Success bool `json:"success"`
707-
Balance map[string]map[coin.Code]accountHandlers.FormattedAmount `json:"balance,omitempty"`
705+
Success bool `json:"success"`
706+
Balance map[string]map[coinpkg.Code]accountHandlers.FormattedAmount `json:"balance,omitempty"`
708707
}
709-
totalAmount := make(map[string]map[coin.Code]accountHandlers.FormattedAmount)
708+
totalAmount := make(map[string]map[coinpkg.Code]accountHandlers.FormattedAmount)
710709
accountsByKeystore, err := handlers.backend.AccountsByKeystore()
711710
if err != nil {
712711
return response{Success: false}
713712
}
714713
for rootFingerprint, accountList := range accountsByKeystore {
715-
totalPerCoin := make(map[coin.Code]*big.Int)
716-
conversionsPerCoin := make(map[coin.Code]map[string]string)
714+
totalPerCoin := make(map[coinpkg.Code]*big.Int)
715+
conversionsPerCoin := make(map[coinpkg.Code]map[string]string)
717716
for _, account := range accountList {
718717
if account.Config().Config.Inactive || account.Config().Config.HiddenBecauseUnused {
719718
continue
@@ -738,22 +737,22 @@ func (handlers *Handlers) getAccountsBalance(*http.Request) interface{} {
738737
totalPerCoin[coinCode] = new(big.Int).Add(totalPerCoin[coinCode], amount.BigInt())
739738
}
740739

741-
conversionsPerCoin[coinCode] = coin.Conversions(
742-
coin.NewAmount(totalPerCoin[coinCode]),
740+
conversionsPerCoin[coinCode] = coinpkg.Conversions(
741+
coinpkg.NewAmount(totalPerCoin[coinCode]),
743742
account.Coin(),
744743
false,
745744
account.Config().RateUpdater,
746745
util.FormatBtcAsSat(handlers.backend.Config().AppConfig().Backend.BtcUnit))
747746
}
748747

749-
totalAmount[rootFingerprint] = make(map[coin.Code]accountHandlers.FormattedAmount)
748+
totalAmount[rootFingerprint] = make(map[coinpkg.Code]accountHandlers.FormattedAmount)
750749
for k, v := range totalPerCoin {
751750
currentCoin, err := handlers.backend.Coin(k)
752751
if err != nil {
753752
return response{Success: false}
754753
}
755754
totalAmount[rootFingerprint][k] = accountHandlers.FormattedAmount{
756-
Amount: currentCoin.FormatAmount(coin.NewAmount(v), false),
755+
Amount: currentCoin.FormatAmount(coinpkg.NewAmount(v), false),
757756
Unit: currentCoin.GetFormatUnit(false),
758757
Conversions: conversionsPerCoin[k],
759758
}
@@ -767,7 +766,7 @@ func (handlers *Handlers) getAccountsBalance(*http.Request) interface{} {
767766
}
768767

769768
type coinFormattedAmount struct {
770-
CoinCode coin.Code `json:"coinCode"`
769+
CoinCode coinpkg.Code `json:"coinCode"`
771770
CoinName string `json:"coinName"`
772771
FormattedAmount accountHandlers.FormattedAmount `json:"formattedAmount"`
773772
}
@@ -779,8 +778,8 @@ func (handlers *Handlers) getCoinsTotalBalance(_ *http.Request) interface{} {
779778
CoinsTotalBalance []coinFormattedAmount `json:"coinsTotalBalance,omitempty"`
780779
}
781780
var coinFormattedAmounts []coinFormattedAmount
782-
var sortedCoins []coin.Code
783-
totalCoinsBalances := make(map[coin.Code]*big.Int)
781+
var sortedCoins []coinpkg.Code
782+
totalCoinsBalances := make(map[coinpkg.Code]*big.Int)
784783

785784
for _, account := range handlers.backend.Accounts() {
786785
if account.Config().Config.Inactive || account.Config().Config.HiddenBecauseUnused {
@@ -817,10 +816,10 @@ func (handlers *Handlers) getCoinsTotalBalance(_ *http.Request) interface{} {
817816
CoinCode: coinCode,
818817
CoinName: currentCoin.Name(),
819818
FormattedAmount: accountHandlers.FormattedAmount{
820-
Amount: currentCoin.FormatAmount(coin.NewAmount(totalCoinsBalances[coinCode]), false),
819+
Amount: currentCoin.FormatAmount(coinpkg.NewAmount(totalCoinsBalances[coinCode]), false),
821820
Unit: currentCoin.GetFormatUnit(false),
822-
Conversions: coin.Conversions(
823-
coin.NewAmount(totalCoinsBalances[coinCode]),
821+
Conversions: coinpkg.Conversions(
822+
coinpkg.NewAmount(totalCoinsBalances[coinCode]),
824823
currentCoin,
825824
false,
826825
handlers.backend.RatesUpdater(),
@@ -1037,7 +1036,7 @@ func (handlers *Handlers) getConvertFromFiat(r *http.Request) interface{} {
10371036
}
10381037

10391038
rate := handlers.backend.RatesUpdater().LatestPrice()[unit][from]
1040-
result := coin.NewAmountFromInt64(0)
1039+
result := coinpkg.NewAmountFromInt64(0)
10411040
if rate != 0.0 {
10421041
amountRat := new(big.Rat).Quo(fiatRat, new(big.Rat).SetFloat64(rate))
10431042
result = currentCoin.SetAmount(amountRat, false)

0 commit comments

Comments
 (0)