fix: allow to update network in app (#2852)
Prevent to override change done via the app
This commit is contained in:
parent
9db69df9a0
commit
9ea2344647
|
@ -124,20 +124,53 @@ func insertNetworkConfig(tx *sql.Tx, c *params.NodeConfig) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func insertNetworkConfigWithChainColorShortName(tx *sql.Tx, c *params.NodeConfig) error {
|
func insertNetworkConfigWithChainColorShortName(tx *sql.Tx, c *params.NodeConfig) error {
|
||||||
for _, network := range c.Networks {
|
rows, err := tx.Query("SELECT chain_id, chain_name, rpc_url, block_explorer_url, icon_url, native_currency_name, native_currency_symbol, native_currency_decimals, is_test, layer, enabled, chain_color, short_name FROM networks")
|
||||||
_, err := tx.Exec(`
|
if err != nil {
|
||||||
INSERT OR REPLACE INTO networks (
|
return err
|
||||||
chain_id, chain_name, rpc_url, block_explorer_url, icon_url, native_currency_name,
|
}
|
||||||
native_currency_symbol, native_currency_decimals, is_test, layer, enabled,
|
var currentNetworks []*params.Network
|
||||||
chain_color, short_name
|
defer rows.Close()
|
||||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
for rows.Next() {
|
||||||
network.ChainID, network.ChainName, network.RPCURL, network.BlockExplorerURL, network.IconURL,
|
network := params.Network{}
|
||||||
network.NativeCurrencyName, network.NativeCurrencySymbol, network.NativeCurrencyDecimals,
|
err := rows.Scan(
|
||||||
network.IsTest, network.Layer, network.Enabled, network.ChainColor, network.ShortName,
|
&network.ChainID, &network.ChainName, &network.RPCURL, &network.BlockExplorerURL, &network.IconURL,
|
||||||
|
&network.NativeCurrencyName, &network.NativeCurrencySymbol,
|
||||||
|
&network.NativeCurrencyDecimals, &network.IsTest, &network.Layer, &network.Enabled, &network.ChainColor, &network.ShortName,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
currentNetworks = append(currentNetworks, &network)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, network := range c.Networks {
|
||||||
|
found := false
|
||||||
|
for _, currentNetwork := range currentNetworks {
|
||||||
|
if currentNetwork.ChainID == network.ChainID {
|
||||||
|
found = true
|
||||||
|
_, err := tx.Exec(`UPDATE networks SET chain_color = ?, short_name = ? WHERE chain_id = ?`, network.ChainColor, network.ShortName, network.ChainID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !found {
|
||||||
|
_, err := tx.Exec(`
|
||||||
|
INSERT OR REPLACE INTO networks (
|
||||||
|
chain_id, chain_name, rpc_url, block_explorer_url, icon_url, native_currency_name,
|
||||||
|
native_currency_symbol, native_currency_decimals, is_test, layer, enabled,
|
||||||
|
chain_color, short_name
|
||||||
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||||
|
network.ChainID, network.ChainName, network.RPCURL, network.BlockExplorerURL, network.IconURL,
|
||||||
|
network.NativeCurrencyName, network.NativeCurrencySymbol, network.NativeCurrencyDecimals,
|
||||||
|
network.IsTest, network.Layer, network.Enabled, network.ChainColor, network.ShortName,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue