diff --git a/mobile/status.go b/mobile/status.go index 1a0b4e09e..257ca1597 100644 --- a/mobile/status.go +++ b/mobile/status.go @@ -282,9 +282,16 @@ func SaveAccountAndLogin(accountData, password, settingsJSON, configJSON, subacc for _, acc := range subaccs { if acc.Chat { - colorHash, _ := colorhash.GenerateFor(string(acc.PublicKey.Bytes())) - colorID, _ := identityUtils.ToColorID(string(acc.PublicKey.Bytes())) + colorHash, err := colorhash.GenerateFor(string(acc.PublicKey.Bytes())) + if err != nil { + return makeJSONResponse(err) + } account.ColorHash = colorHash + + colorID, err := identityUtils.ToColorID(string(acc.PublicKey.Bytes())) + if err != nil { + return makeJSONResponse(err) + } account.ColorID = colorID break diff --git a/multiaccounts/accounts/account_test.go b/multiaccounts/accounts/account_test.go index c40af8495..02fb3d9bd 100644 --- a/multiaccounts/accounts/account_test.go +++ b/multiaccounts/accounts/account_test.go @@ -1,6 +1,7 @@ package accounts import ( + "encoding/json" "testing" "github.com/stretchr/testify/require" @@ -33,3 +34,28 @@ func TestIsOwnAccount(t *testing.T) { account = Account{} require.False(t, account.IsOwnAccount()) } + +func TestUnmarshal(t *testing.T) { + data := ` +{ + "public-key": "0x0465f6d4f1172524fc057954c8a3f8e34f991558b3d1097189975062f67adda7835da61acb5cda3348b41d211ed0cb07aba668eb12e19e29d98745bebf68d93b61", + "address": "0xf09c9f5Fb9faa22d0C6C593e7157Ceac8B2b0fe4", + "color": "#4360df", + "wallet": true, + "path": "m/44'/60'/0'/0/0", + "name": "Status account", + "derived-from": "0x6f015A79890Dcb38eFeC1D83772d57159D2eb58b" +} +` + var account Account + err := json.Unmarshal([]byte(data), &account) + require.NoError(t, err) + + require.Equal(t, []byte("0x0465f6d4f1172524fc057954c8a3f8e34f991558b3d1097189975062f67adda7835da61acb5cda3348b41d211ed0cb07aba668eb12e19e29d98745bebf68d93b61"), account.PublicKey.Bytes()) + require.Equal(t, "0xf09c9f5Fb9faa22d0C6C593e7157Ceac8B2b0fe4", account.Address.String()) + require.Equal(t, "#4360df", account.Color) + require.Equal(t, true, account.Wallet) + require.Equal(t, "m/44'/60'/0'/0/0", account.Path) + require.Equal(t, "Status account", account.Name) + require.Equal(t, "0x6f015A79890Dcb38eFeC1D83772d57159D2eb58b", account.DerivedFrom) +} diff --git a/multiaccounts/accounts/database.go b/multiaccounts/accounts/database.go index e277da6c7..5bcae9ea8 100644 --- a/multiaccounts/accounts/database.go +++ b/multiaccounts/accounts/database.go @@ -19,20 +19,20 @@ const ( ) type Account struct { - Address types.Address - Wallet bool - Chat bool - Type string - Storage string - Path string - PublicKey types.HexBytes - Name string - Emoji string - Color string - Hidden bool - DerivedFrom string - Clock uint64 - Removed bool + Address types.Address `json:"address"` + Wallet bool `json:"wallet"` + Chat bool `json:"chat"` + Type string `json:"type,omitempty"` + Storage string `json:"storage,omitempty"` + Path string `json:"path,omitempty"` + PublicKey types.HexBytes `json:"public-key,omitempty"` + Name string `json:"name"` + Emoji string `json:"emoji"` + Color string `json:"color"` + Hidden bool `json:"hidden"` + DerivedFrom string `json:"derived-from,omitempty"` + Clock uint64 `json:"clock,omitempty"` + Removed bool `json:"removed,omitempty"` } const (