Skip to content

Commit

Permalink
Merge ec9d0e4 into 58ac495
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricio1802 committed Jan 10, 2020
2 parents 58ac495 + ec9d0e4 commit 48c78fe
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
25 changes: 25 additions & 0 deletions src/coin/skycoin/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"os/user"
"path/filepath"
"strconv"
"strings"

local "github.com/fibercrypto/fibercryptowallet/src/main"
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions src/coin/skycoin/models/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/main/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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 {
Expand Down
25 changes: 23 additions & 2 deletions src/ui/Settings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,22 @@ 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"
// TODO: This should be binded to backend properties
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()
Expand All @@ -44,13 +47,15 @@ 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()
}

function loadSavedSettings() {
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()
}
Expand All @@ -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
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 48c78fe

Please sign in to comment.