diff --git a/src/coin/skycoin/config/config.go b/src/coin/skycoin/config/config.go index 1fbac8c8..edaf42ad 100644 --- a/src/coin/skycoin/config/config.go +++ b/src/coin/skycoin/config/config.go @@ -5,6 +5,7 @@ import ( "os" "os/user" "path/filepath" + "strconv" "strings" local "github.com/fibercrypto/fibercryptowallet/src/main" @@ -65,6 +66,30 @@ func getValues(prefix string) ([]string, error) { return sectionManager.GetValues(strings.Split(prefix, "/")) } +func GetDataRefreshTimeout() uint64 { + cm := local.GetConfigManager() + sm := cm.GetSectionManager("global") + value, err := sm.GetValue("cache", nil) + if err != nil { + return 0 + } + + keyValue := make(map[string]string) + err = json.Unmarshal([]byte(value), &keyValue) + if err != nil { + return 0 + } + strVal, ok := keyValue["lifeTime"] + if !ok { + return 0 + } + val, err := strconv.ParseUint(strVal, 10, 64) + if err != nil { + return 0 + } + return val +} + func GetWalletSources() ([]*walletSource, error) { wltsString, err := getValues(SettingPathToWalletSource) if err != nil { diff --git a/src/coin/skycoin/models/main.go b/src/coin/skycoin/models/main.go index 04d263c1..af1ecdc2 100644 --- a/src/coin/skycoin/models/main.go +++ b/src/coin/skycoin/models/main.go @@ -6,7 +6,6 @@ import ( "github.com/fibercrypto/fibercryptowallet/src/core" "github.com/fibercrypto/fibercryptowallet/src/errors" //local "github.com/fibercrypto/fibercryptowallet/src/main" - appParams "github.com/fibercrypto/fibercryptowallet/src/params" ) // SkyFiberPlugin provide support for SkyFiber coins @@ -100,7 +99,7 @@ func (p *SkyFiberPlugin) LoadTransactionAPI(netType string) (core.BlockchainTran if netType != "MainNet" { return nil, errors.ErrInvalidNetworkType } - return NewSkycoinBlockchain(appParams.DataRefreshTimeout), nil + return NewSkycoinBlockchain(config.GetDataRefreshTimeout()), nil } // LoadSignService sign service entry point diff --git a/src/main/config.go b/src/main/config.go index 68f235ff..76b3172f 100644 --- a/src/main/config.go +++ b/src/main/config.go @@ -2,8 +2,10 @@ package local import ( "encoding/json" + "strconv" "github.com/fibercrypto/fibercryptowallet/src/errors" + "github.com/fibercrypto/fibercryptowallet/src/params" qtcore "github.com/therecipe/qt/core" ) @@ -24,6 +26,17 @@ func init() { sections: make(map[string]*SectionManager), } + valueLifeTime := strconv.FormatUint(params.DataRefreshTimeout, 10) + + cache := map[string]string{"lifeTime": valueLifeTime} + + cacheBytes, err := json.Marshal(cache) + if err != nil { + return + } + cacheOpt := NewOption("cache", []string{}, false, string(cacheBytes)) + + _ = confManager.RegisterSection("global", []*Option{cacheOpt}) } type ConfigManager struct { diff --git a/src/ui/Settings.qml b/src/ui/Settings.qml index 625cd2e3..ded57eba 100644 --- a/src/ui/Settings.qml +++ b/src/ui/Settings.qml @@ -22,6 +22,7 @@ Page { readonly property string defaultWalletPath: configManager.getDefaultValue("skycoin/walletSource/1/Source") readonly property bool defaultIsLocalWalletEnv: configManager.getDefaultValue("skycoin/walletSource/1/SourceType") === "local" readonly property string defaultNodeUrl: configManager.getDefaultValue("skycoin/node/address") + readonly property var defaultCacheLifeTime: configManager.getDefaultValue("global/cache/lifeTime") // These are the saved settings, must be applied when the settings are opened or when // the user clicks "RESET" and updated when the user clicks "APPLY" @@ -29,12 +30,14 @@ Page { property string savedWalletPath: configManager.getValue("skycoin/walletSource/1/Source") property bool savedIsLocalWalletEnv: configManager.getValue("skycoin/walletSource/1/SourceType") === "local" property url savedNodeUrl: configManager.getValue("skycoin/node/address") + property var savedLifeTime: configManager.getValue("global/cache/lifeTime") // These are the properties that are actually set, so they are aliases of the respective // control's properties property alias walletPath: textFieldWalletPath.text property alias isLocalWalletEnv: switchLocalWalletEnv.checked property alias nodeUrl: textFieldNodeUrl.text + property alias cacheLifeTime: textFieldCacheLifeTime.text Component.onCompleted: { loadSavedSettings() @@ -44,6 +47,7 @@ Page { configManager.setValue("skycoin/walletSource/1/Source", walletPath) configManager.setValue("skycoin/walletSource/1/SourceType", isLocalWalletEnv ? "local" : "remote") configManager.setValue("skycoin/node/address", nodeUrl) + configManager.setValue("global/cache/lifeTime", cacheLifeTime) loadSavedSettings() } @@ -51,6 +55,7 @@ Page { walletPath = savedWalletPath = configManager.getValue("skycoin/walletSource/1/Source") isLocalWalletEnv = savedIsLocalWalletEnv = configManager.getValue("skycoin/walletSource/1/SourceType") === "local" nodeUrl = savedNodeUrl = configManager.getValue("skycoin/node/address") + cacheLifeTime = savedLifeTime = configManager.getValue("global/cache/lifeTime") updateFooterButtonsStatus() } @@ -59,13 +64,14 @@ Page { walletPath = defaultWalletPath isLocalWalletEnv = defaultIsLocalWalletEnv nodeUrl = defaultNodeUrl + cacheLifeTime = defaultCacheLifeTime saveCurrentSettings() } function updateFooterButtonsStatus() { - var configChanged = (walletPath !== savedWalletPath || isLocalWalletEnv !== savedIsLocalWalletEnv || nodeUrl != savedNodeUrl) - var noDefaultConfig = (walletPath !== defaultWalletPath || isLocalWalletEnv !== defaultIsLocalWalletEnv || nodeUrl !== defaultNodeUrl) + var configChanged = (walletPath !== savedWalletPath || isLocalWalletEnv !== savedIsLocalWalletEnv || nodeUrl != savedNodeUrl || cacheLifeTime != savedLifeTime) + var noDefaultConfig = (walletPath !== defaultWalletPath || isLocalWalletEnv !== defaultIsLocalWalletEnv || nodeUrl !== defaultNodeUrl || cacheLifeTime || defaultCacheLifeTime) footer.standardButton(Dialog.Apply).enabled = configChanged footer.standardButton(Dialog.Discard).enabled = configChanged footer.standardButton(Dialog.RestoreDefaults).enabled = noDefaultConfig @@ -162,6 +168,21 @@ Page { } } // GroupBox (network settings) + GroupBox { + Layout.fillWidth: true + title: qsTr("Global settings") + + TextField { + id: textFieldCacheLifeTime + anchors.fill: parent + selectByMouse: true + placeholderText: qsTr("Cache life time") + onTextChanged: { + updateFooterButtonsStatus(); + } + } + } // GroupBox (global settings) + GroupBox { enabled:abm.hasInit() AddrsBookModel{