Skip to content

Commit

Permalink
fix: improve UX by sending major version info (#57)
Browse files Browse the repository at this point in the history
This change improves user experience (UX) by sending over the major
version information. While here, also fixed up an unclear return.

Fixes #50
Fixes #51
  • Loading branch information
odeke-em authored Oct 30, 2023
1 parent c96c0ff commit a4f5d04
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions user_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package ledger_cosmos_go

import (
"errors"
"fmt"
"math"

ledger_go "github.com/zondax/ledger-go"
Expand Down Expand Up @@ -66,7 +67,7 @@ func FindLedgerCosmosUserApp() (_ *LedgerCosmos, rerr error) {
return nil, err
}

return app, err
return app, nil
}

// Close closes a connection with the Cosmos user app
Expand All @@ -81,13 +82,13 @@ func (ledger *LedgerCosmos) CheckVersion(ver VersionInfo) error {
return err
}

switch version.Major {
switch major := version.Major; major {
case 1:
return CheckVersion(ver, VersionInfo{0, 1, 5, 1})
case 2:
return CheckVersion(ver, VersionInfo{0, 2, 1, 0})
default:
return errors.New("App version is not supported")
return fmt.Errorf("App version %d is not supported", major)
}
}

Expand Down Expand Up @@ -118,13 +119,13 @@ func (ledger *LedgerCosmos) GetVersion() (*VersionInfo, error) {
// SIGN_MODE_LEGACY_AMINO_JSON (P2=0) or SIGN_MODE_TEXTUAL (P2=1).
// this command requires user confirmation in the device
func (ledger *LedgerCosmos) SignSECP256K1(bip32Path []uint32, transaction []byte, p2 byte) ([]byte, error) {
switch ledger.version.Major {
switch major := ledger.version.Major; major {
case 1:
return ledger.signv1(bip32Path, transaction)
case 2:
return ledger.signv2(bip32Path, transaction, p2)
default:
return nil, errors.New("App version is not supported")
return nil, fmt.Errorf("App version %d is not supported", major)
}
}

Expand All @@ -150,7 +151,7 @@ func (ledger *LedgerCosmos) GetBip32bytes(bip32Path []uint32, hardenCount int) (
var pathBytes []byte
var err error

switch ledger.version.Major {
switch major := ledger.version.Major; major {
case 1:
pathBytes, err = GetBip32bytesv1(bip32Path, 3)
if err != nil {
Expand All @@ -162,7 +163,7 @@ func (ledger *LedgerCosmos) GetBip32bytes(bip32Path []uint32, hardenCount int) (
return nil, err
}
default:
return nil, errors.New("App version is not supported")
return nil, fmt.Errorf("App version %d is not supported", major)
}

return pathBytes, nil
Expand Down

0 comments on commit a4f5d04

Please sign in to comment.