-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
backend/frontend: add option to restart in testnet #3157
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,20 +232,23 @@ type Backend struct { | |
tstCheckAccountUsed func(accounts.Interface) bool | ||
// For unit tests, called when `backend.maybeAddHiddenUnusedAccounts()` has run. | ||
tstMaybeAddHiddenUnusedAccounts func() | ||
|
||
// testing tells us whether the app is in testing mode | ||
testing bool | ||
} | ||
|
||
// NewBackend creates a new backend with the given arguments. | ||
func NewBackend(arguments *arguments.Arguments, environment Environment) (*Backend, error) { | ||
log := logging.Get().WithGroup("backend") | ||
config, err := config.NewConfig(arguments.AppConfigFilename(), arguments.AccountsConfigFilename()) | ||
backendConfig, err := config.NewConfig(arguments.AppConfigFilename(), arguments.AccountsConfigFilename()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. renaming because I later need to use |
||
if err != nil { | ||
return nil, errp.WithStack(err) | ||
} | ||
log.Infof("backend config: %+v", config.AppConfig().Backend) | ||
log.Infof("frontend config: %+v", config.AppConfig().Frontend) | ||
log.Infof("backend config: %+v", backendConfig.AppConfig().Backend) | ||
log.Infof("frontend config: %+v", backendConfig.AppConfig().Frontend) | ||
backendProxy := socksproxy.NewSocksProxy( | ||
config.AppConfig().Backend.Proxy.UseProxy, | ||
config.AppConfig().Backend.Proxy.ProxyAddress, | ||
backendConfig.AppConfig().Backend.Proxy.UseProxy, | ||
backendConfig.AppConfig().Backend.Proxy.ProxyAddress, | ||
) | ||
hclient, err := backendProxy.GetHTTPClient() | ||
if err != nil { | ||
|
@@ -255,7 +258,7 @@ func NewBackend(arguments *arguments.Arguments, environment Environment) (*Backe | |
backend := &Backend{ | ||
arguments: arguments, | ||
environment: environment, | ||
config: config, | ||
config: backendConfig, | ||
events: make(chan interface{}, 1000), | ||
|
||
devices: map[string]device.Interface{}, | ||
|
@@ -271,7 +274,10 @@ func NewBackend(arguments *arguments.Arguments, environment Environment) (*Backe | |
}, | ||
|
||
log: log, | ||
|
||
testing: backendConfig.AppConfig().Backend.StartInTestnet || arguments.Testing(), | ||
} | ||
|
||
notifier, err := NewNotifier(filepath.Join(arguments.MainDirectoryPath(), "notifier.db")) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -540,7 +546,7 @@ func (backend *Backend) Coin(code coinpkg.Code) (coinpkg.Coin, error) { | |
// Calling this is a no-op for coins that are already connected. | ||
func (backend *Backend) ManualReconnect() { | ||
var electrumCoinCodes []coinpkg.Code | ||
if backend.arguments.Testing() { | ||
if backend.Testing() { | ||
electrumCoinCodes = []coinpkg.Code{ | ||
coinpkg.CodeTBTC, | ||
coinpkg.CodeTLTC, | ||
|
@@ -574,7 +580,7 @@ func (backend *Backend) ManualReconnect() { | |
|
||
// Testing returns whether this backend is for testing only. | ||
func (backend *Backend) Testing() bool { | ||
return backend.arguments.Testing() | ||
return backend.testing | ||
} | ||
|
||
// Accounts returns the current accounts of the backend. | ||
|
@@ -638,6 +644,12 @@ func (backend *Backend) Start() <-chan interface{} { | |
backend.configureHistoryExchangeRates() | ||
|
||
backend.environment.OnAuthSettingChanged(backend.config.AppConfig().Backend.Authentication) | ||
|
||
if backend.DefaultAppConfig().Backend.StartInTestnet { | ||
if err := backend.config.ModifyAppConfig(func(c *config.AppConfig) error { c.Backend.StartInTestnet = false; return nil }); err != nil { | ||
backend.log.WithError(err).Error("Can't set StartInTestnet to false") | ||
} | ||
} | ||
return backend.events | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...tends/web/src/routes/settings/components/advanced-settings/restart-in-testnet-setting.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
|
||
/** | ||
* Copyright 2025 Shift Crypto AG | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { ChangeEvent, Dispatch } from 'react'; | ||
import { useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { SettingsItem } from '@/routes/settings/components/settingsItem/settingsItem'; | ||
import { Toggle } from '@/components/toggle/toggle'; | ||
import { TConfig, TBackendConfig } from '@/routes/settings/advanced-settings'; | ||
import { Message } from '@/components/message/message'; | ||
import { setConfig } from '@/utils/config'; | ||
import styles from './enable-tor-proxy-setting.module.css'; | ||
|
||
type TProps = { | ||
backendConfig?: TBackendConfig; | ||
onChangeConfig: Dispatch<TConfig>; | ||
} | ||
|
||
export const RestartInTestnetSetting = ({ backendConfig, onChangeConfig }: TProps) => { | ||
const { t } = useTranslation(); | ||
const [showRestartMessage, setShowRestartMessage] = useState(false); | ||
|
||
|
||
const handleToggleRestartInTestnet = async (e: ChangeEvent<HTMLInputElement>) => { | ||
setShowRestartMessage(e.target.checked); | ||
const config = await setConfig({ | ||
backend: { | ||
'restartInTestnet': e.target.checked | ||
}, | ||
}) as TConfig; | ||
onChangeConfig(config); | ||
}; | ||
return ( | ||
<> | ||
{ showRestartMessage ? ( | ||
<Message type="warning"> | ||
{t('settings.restart')} | ||
</Message> | ||
) : null } | ||
<SettingsItem | ||
className={styles.settingItem} | ||
settingName={t('settings.expert.restartInTestnet')} | ||
secondaryText={t('newSettings.advancedSettings.restartInTestnet.description')} | ||
extraComponent={ | ||
backendConfig !== undefined ? ( | ||
<Toggle | ||
checked={backendConfig?.restartInTestnet || false} | ||
onChange={handleToggleRestartInTestnet} | ||
/> | ||
) : null | ||
} | ||
/> | ||
</> | ||
); | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replaced all occurrences of
backend.arguments.Testing()
withbackend.Testing
. Prior to this PR the two calls are the same (backend.Testing()
callsbackend.arguments.Testing()
) but with this new PR there is more logic inbackend.Testing()
- The alternative would have be to change the fieldarguments.testing
but since everything in arguments is unexported I prefer not to