Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 28bf764

Browse files
committedMar 10, 2025·
feat(wallet)_: auto refresh option and last tokens update time columns added to the settings table
Added settings: - `AutoRefreshTokensEnabled` - `true` by default - `LastTokensUpdate`
1 parent de0da7b commit 28bf764

15 files changed

+126
-9
lines changed
 

‎api/defaults.go

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ func defaultSettings(keyUID string, address string, derivedAddresses map[string]
117117

118118
s.TestNetworksEnabled = false
119119

120+
s.AutoRefreshTokensEnabled = true
121+
120122
// Default user status
121123
currentUserStatus, err := json.Marshal(protocol.UserStatus{
122124
PublicKey: chatKeyString,

‎api/geth_backend.go

+1
Original file line numberDiff line numberDiff line change
@@ -1759,6 +1759,7 @@ func (b *GethStatusBackend) prepareSettings(request *requests.CreateAccount, inp
17591759
settings.PreviewPrivacy = request.PreviewPrivacy
17601760
settings.CurrentNetwork = request.CurrentNetwork
17611761
settings.TestNetworksEnabled = request.TestNetworksEnabled
1762+
settings.AutoRefreshTokensEnabled = request.AutoRefreshTokensEnabled
17621763
if !input.restoringAccount {
17631764
settings.Mnemonic = &input.mnemonic
17641765
// TODO(rasom): uncomment it as soon as address will be properly
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ALTER TABLE settings ADD COLUMN auto_refresh_tokens_enabled BOOLEAN DEFAULT TRUE;
2+
ALTER TABLE settings ADD COLUMN last_tokens_update TIMESTAMP;
3+
4+
UPDATE settings SET auto_refresh_tokens_enabled = 1;
5+
6+
ALTER TABLE settings_sync_clock ADD COLUMN auto_refresh_tokens_enabled INTEGER NOT NULL DEFAULT 0;

‎cmd/ping-community/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ func defaultSettings(generatedAccountInfo generator.GeneratedAccountInfo, derive
301301

302302
defaultSettings.TestNetworksEnabled = false
303303

304+
defaultSettings.AutoRefreshTokensEnabled = true
305+
304306
visibleTokens := make(map[string][]string)
305307
visibleTokens["mainnet"] = []string{"SNT"}
306308
visibleTokensJSON, err := json.Marshal(visibleTokens)

‎cmd/populate-db/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ func defaultSettings(generatedAccountInfo generator.GeneratedAccountInfo, derive
349349

350350
defaultSettings.TestNetworksEnabled = false
351351

352+
defaultSettings.AutoRefreshTokensEnabled = true
353+
352354
visibleTokens := make(map[string][]string)
353355
visibleTokens["mainnet"] = []string{"SNT"}
354356
visibleTokensJSON, err := json.Marshal(visibleTokens)

‎multiaccounts/settings/columns.go

+18
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,22 @@ var (
501501
dBColumnName: "peer_syncing_enabled",
502502
valueHandler: BoolHandler,
503503
}
504+
AutoRefreshTokensEnabled = SettingField{
505+
reactFieldName: "auto-refresh-tokens-enabled?",
506+
dBColumnName: "auto_refresh_tokens_enabled",
507+
valueHandler: BoolHandler,
508+
syncProtobufFactory: &SyncProtobufFactory{
509+
fromInterface: autoRefreshTokensEnabledProtobufFactory,
510+
fromStruct: autoRefreshTokensEnabledProtobufFactoryStruct,
511+
valueFromProtobuf: BoolFromSyncProtobuf,
512+
protobufType: protobuf.SyncSetting_AUTO_REFRESH_TOKENS_ENABLED,
513+
},
514+
}
515+
LastTokensUpdate = SettingField{
516+
reactFieldName: "last-tokens-update",
517+
dBColumnName: "last_tokens_update",
518+
valueHandler: TimeHandler,
519+
}
504520
SettingFieldRegister = []SettingField{
505521
AnonMetricsShouldSend,
506522
Appearance,
@@ -577,6 +593,8 @@ var (
577593
WalletSetUpPassed,
578594
WalletVisibleTokens,
579595
WebviewAllowPermissionRequests,
596+
AutoRefreshTokensEnabled,
597+
LastTokensUpdate,
580598
}
581599
)
582600

‎multiaccounts/settings/columns_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"strings"
66
"testing"
7+
"time"
78

89
"github.com/stretchr/testify/require"
910

@@ -84,6 +85,15 @@ func TestValueHandler(t *testing.T) {
8485
handledInt64Value, err := boolSetting.ValueHandler()(int64Value)
8586
require.Error(t, err)
8687
require.True(t, handledInt64Value == int64Value)
88+
89+
// Test time handler
90+
timeSetting := SettingField{
91+
valueHandler: TimeHandler,
92+
}
93+
timeValue := time.Now()
94+
handledTimeValue, err := timeSetting.ValueHandler()(timeValue)
95+
require.NoError(t, err)
96+
require.True(t, timeValue == handledTimeValue)
8797
}
8898

8999
func TestValueCastHandler(t *testing.T) {

‎multiaccounts/settings/database.go

+39-4
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,11 @@ INSERT INTO settings (
146146
wallet_collectible_preferences_group_by_collection,
147147
wallet_collectible_preferences_group_by_community,
148148
test_networks_enabled,
149-
fleet
149+
fleet,
150+
auto_refresh_tokens_enabled
150151
) VALUES (
151152
?,?,?,?,?,?,?,?,?,?,?,?,?,?,
152-
?,?,?,?,?,?,?,?,?,'id',?,?,?,?,?,?,?,?,?,?)`,
153+
?,?,?,?,?,?,?,?,?,'id',?,?,?,?,?,?,?,?,?,?,?)`,
153154
s.Address,
154155
s.Currency,
155156
s.CurrentNetwork,
@@ -183,6 +184,7 @@ INSERT INTO settings (
183184
s.CollectibleGroupByCommunity,
184185
s.TestNetworksEnabled,
185186
s.Fleet,
187+
s.AutoRefreshTokensEnabled,
186188
)
187189
if err != nil {
188190
return err
@@ -369,7 +371,10 @@ func (db *Database) SetSettingLastSynced(setting SettingField, clock uint64) err
369371
}
370372

371373
func (db *Database) GetSettings() (Settings, error) {
372-
var s Settings
374+
var (
375+
s Settings
376+
lastTokensUpdate sql.NullTime
377+
)
373378
err := db.db.QueryRow(`
374379
SELECT
375380
address, anon_metrics_should_send, chaos_mode, currency, current_network,
@@ -387,7 +392,7 @@ func (db *Database) GetSettings() (Settings, error) {
387392
test_networks_enabled, mutual_contact_enabled, profile_migration_needed, wallet_token_preferences_group_by_community, url_unfurling_mode,
388393
mnemonic_was_not_shown, wallet_show_community_asset_when_sending_tokens, wallet_display_assets_below_balance,
389394
wallet_display_assets_below_balance_threshold, wallet_collectible_preferences_group_by_collection, wallet_collectible_preferences_group_by_community,
390-
peer_syncing_enabled
395+
peer_syncing_enabled, auto_refresh_tokens_enabled, last_tokens_update
391396
FROM
392397
settings
393398
WHERE
@@ -470,8 +475,18 @@ func (db *Database) GetSettings() (Settings, error) {
470475
&s.CollectibleGroupByCollection,
471476
&s.CollectibleGroupByCommunity,
472477
&s.PeerSyncingEnabled,
478+
&s.AutoRefreshTokensEnabled,
479+
&lastTokensUpdate,
473480
)
474481

482+
if err != nil {
483+
return s, err
484+
}
485+
486+
if lastTokensUpdate.Valid {
487+
s.LastTokensUpdate = lastTokensUpdate.Time
488+
}
489+
475490
return s, err
476491
}
477492

@@ -843,3 +858,23 @@ func (db *Database) postChangesToSubscribers(change *SyncSettingField) {
843858
func (db *Database) MnemonicWasShown() error {
844859
return db.SaveSettingField(MnemonicWasNotShown, false)
845860
}
861+
862+
func (db *Database) AutoRefreshTokensEnabled() (result bool, err error) {
863+
err = db.makeSelectRow(AutoRefreshTokensEnabled).Scan(&result)
864+
if err == sql.ErrNoRows {
865+
return result, nil
866+
}
867+
return result, err
868+
}
869+
870+
func (db *Database) LastTokensUpdate() (result time.Time, err error) {
871+
var lastTokensUpdate sql.NullTime
872+
err = db.makeSelectRow(LastTokensUpdate).Scan(&lastTokensUpdate)
873+
if err == sql.ErrNoRows {
874+
return result, nil
875+
}
876+
if lastTokensUpdate.Valid {
877+
result = lastTokensUpdate.Time
878+
}
879+
return
880+
}

‎multiaccounts/settings/database_settings_manager.go

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package settings
55
import (
66
"database/sql"
77
"encoding/json"
8+
"time"
89

910
"github.com/status-im/status-go/eth-node/types"
1011
"github.com/status-im/status-go/params"
@@ -80,4 +81,6 @@ type DatabaseSettingsManager interface {
8081
SubscribeToChanges() chan *SyncSettingField
8182
MnemonicWasShown() error
8283
GetPeerSyncingEnabled() (result bool, err error)
84+
AutoRefreshTokensEnabled() (result bool, err error)
85+
LastTokensUpdate() (result time.Time, err error)
8386
}

‎multiaccounts/settings/structs.go

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package settings
33
import (
44
"encoding/json"
55
"reflect"
6+
"time"
67

78
accountJson "github.com/status-im/status-go/account/json"
89
"github.com/status-im/status-go/eth-node/types"
@@ -222,6 +223,8 @@ type Settings struct {
222223
CollectibleGroupByCommunity bool `json:"collectible-group-by-community?,omitempty"`
223224
URLUnfurlingMode URLUnfurlingModeType `json:"url-unfurling-mode,omitempty"`
224225
PeerSyncingEnabled bool `json:"peer-syncing-enabled?,omitempty"`
226+
AutoRefreshTokensEnabled bool `json:"auto-refresh-tokens-enabled?,omitempty"`
227+
LastTokensUpdate time.Time `json:"last-tokens-update,omitempty"`
225228
}
226229

227230
func (s Settings) MarshalJSON() ([]byte, error) {

‎multiaccounts/settings/sync_protobuf_factories.go

+23
Original file line numberDiff line numberDiff line change
@@ -618,3 +618,26 @@ func displayAssetsBelowBalanceThresholdProtobufFactory(value any, clock uint64,
618618
func displayAssetsBelowBalanceThresholdProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) {
619619
return buildRawDisplayAssetsBelowBalanceThresholdSyncMessage(s.DisplayAssetsBelowBalanceThreshold, clock, chatID)
620620
}
621+
622+
func buildRawAutoRefreshTokensEnabledSyncMessage(v bool, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) {
623+
pb := &protobuf.SyncSetting{
624+
Type: protobuf.SyncSetting_AUTO_REFRESH_TOKENS_ENABLED,
625+
Value: &protobuf.SyncSetting_ValueBool{ValueBool: v},
626+
Clock: clock,
627+
}
628+
rm, err := buildRawSyncSettingMessage(pb, chatID)
629+
return rm, pb, err
630+
}
631+
632+
func autoRefreshTokensEnabledProtobufFactory(value any, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) {
633+
v, err := assertBool(value)
634+
if err != nil {
635+
return nil, nil, err
636+
}
637+
638+
return buildRawAutoRefreshTokensEnabledSyncMessage(v, clock, chatID)
639+
}
640+
641+
func autoRefreshTokensEnabledProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) {
642+
return buildRawAutoRefreshTokensEnabledSyncMessage(s.AutoRefreshTokensEnabled, clock, chatID)
643+
}

‎multiaccounts/settings/value_handlers.go

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package settings
22

33
import (
44
"encoding/json"
5+
"time"
56

67
"github.com/status-im/status-go/eth-node/types"
78
"github.com/status-im/status-go/multiaccounts/errors"
@@ -81,3 +82,11 @@ func Float64ToInt64Handler(value interface{}) (interface{}, error) {
8182
}
8283
return int64(floatValue), nil
8384
}
85+
86+
func TimeHandler(value interface{}) (interface{}, error) {
87+
timeValue, ok := value.(time.Time)
88+
if !ok {
89+
return value, errors.ErrInvalidConfig
90+
}
91+
return timeValue, nil
92+
}

‎protocol/protobuf/sync_settings.proto

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ message SyncSetting {
3939
SHOW_COMMUNITY_ASSET_WHEN_SENDING_TOKENS = 19;
4040
DISPLAY_ASSETS_BELOW_BALANCE = 20;
4141
DISPLAY_ASSETS_BELOW_BALANCE_THRESHOLD = 21;
42+
AUTO_REFRESH_TOKENS_ENABLED = 22;
4243
}
4344
}
4445

‎protocol/requests/create_account.go

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ type CreateAccount struct {
7070

7171
TestNetworksEnabled bool `json:"testNetworksEnabled"`
7272

73+
AutoRefreshTokensEnabled bool `json:"autoRefreshTokensEnabled"`
74+
7375
WalletSecretsConfig
7476

7577
TorrentConfigEnabled *bool

‎services/wallet/api_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"github.com/status-im/status-go/services/wallet/onramp"
2929
mock_onramp "github.com/status-im/status-go/services/wallet/onramp/mock"
3030
"github.com/status-im/status-go/services/wallet/requests"
31-
tokenTypes "github.com/status-im/status-go/services/wallet/token/types"
31+
tokentypes "github.com/status-im/status-go/services/wallet/token/types"
3232
"github.com/status-im/status-go/services/wallet/walletconnect"
3333
"github.com/status-im/status-go/t/helpers"
3434
"github.com/status-im/status-go/walletdatabase"
@@ -252,13 +252,13 @@ func TestAPI_FetchOrGetCachedWalletBalances(t *testing.T) {
252252

253253
testTokenAddress1 := common.Address{0x34}
254254
testAccAddress1 := common.Address{0x12}
255-
storageToken := tokenTypes.StorageToken{
256-
Token: tokenTypes.Token{
255+
storageToken := tokentypes.StorageToken{
256+
Token: tokentypes.Token{
257257
Name: "USD Tether",
258258
Symbol: "USDT",
259259
Decimals: 18,
260260
},
261-
BalancesPerChain: map[uint64]tokenTypes.ChainBalance{
261+
BalancesPerChain: map[uint64]tokentypes.ChainBalance{
262262
1: {
263263
RawBalance: "1000000000000000000",
264264
Balance: nil,
@@ -268,7 +268,7 @@ func TestAPI_FetchOrGetCachedWalletBalances(t *testing.T) {
268268
},
269269
},
270270
}
271-
expectedTokens := map[common.Address][]tokenTypes.StorageToken{
271+
expectedTokens := map[common.Address][]tokentypes.StorageToken{
272272
testAccAddress1: {storageToken},
273273
}
274274

0 commit comments

Comments
 (0)
Please sign in to comment.