Skip to content
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

client,webserver: Use the app build version as Version in UI. #3096

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dex/testing/loadbot/loadbot
bin/
bin-v*/
client/webserver/site/template-builder/template-builder
client/webserver/site/webpack-build-id.txt
dex/testing/btc/harnesschain.tar.gz
client/asset/btc/electrum/example/server/server
client/asset/btc/electrum/example/wallet/wallet
Expand Down
4 changes: 3 additions & 1 deletion client/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ type Config struct {
// Web creates a configuration for the webserver. This is a Config method
// instead of a WebConfig method because Language is an app-level setting used
// by both core and rpcserver.
func (cfg *Config) Web(c *core.Core, mm *mm.MarketMaker, log dex.Logger, utc bool) *webserver.Config {
func (cfg *Config) Web(c *core.Core, mm *mm.MarketMaker, log dex.Logger, utc bool, appVersion string) *webserver.Config {
addr := cfg.WebAddr
host, _, err := net.SplitHostPort(addr)
if err == nil && host != "" {
Expand Down Expand Up @@ -196,6 +196,7 @@ func (cfg *Config) Web(c *core.Core, mm *mm.MarketMaker, log dex.Logger, utc boo
NoEmbed: cfg.NoEmbedSite,
HttpProf: cfg.HTTPProfile,
Language: cfg.Language,
AppVersion: appVersion,
}
}

Expand Down Expand Up @@ -348,6 +349,7 @@ func ResolveConfig(appData string, cfg *Config) error {
if cfg.MMConfig.EventLogDBPath == "" {
cfg.MMConfig.EventLogDBPath = defaultMMEventLogDBPath
}

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion client/cmd/bisonw-desktop/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func mainCore() error {
}()
}

webSrv, err := webserver.New(cfg.Web(clientCore, marketMaker, logMaker.Logger("WEB"), utc))
webSrv, err := webserver.New(cfg.Web(clientCore, marketMaker, logMaker.Logger("WEB"), utc, app.Version))
if err != nil {
return fmt.Errorf("failed creating web server: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion client/cmd/bisonw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func runCore(cfg *app.Config) error {
}

if !cfg.NoWeb {
webSrv, err := webserver.New(cfg.Web(clientCore, marketMaker, logMaker.Logger("WEB"), utc))
webSrv, err := webserver.New(cfg.Web(clientCore, marketMaker, logMaker.Logger("WEB"), utc, app.Version))
if err != nil {
return fmt.Errorf("failed creating web server: %w", err)
}
Expand Down
2 changes: 2 additions & 0 deletions client/webserver/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,15 @@ func (s *WebServer) handleSettings(w http.ResponseWriter, r *http.Request) {
FiatCurrency string
Exchanges map[string]*core.Exchange
IsInitialized bool
AppVersion string
}{
CommonArguments: *common,
KnownExchanges: s.knownUnregisteredExchanges(xcs),
FiatCurrency: core.DefaultFiatCurrency,
FiatRateSources: s.core.FiatRateSources(),
Exchanges: xcs,
IsInitialized: s.core.IsInitialized(),
AppVersion: s.appVersion,
dev-warrior777 marked this conversation as resolved.
Show resolved Hide resolved
}
s.sendTemplate(w, "settings", data)
}
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/locales/ar.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ var Ar = map[string]*intl.Translation{
"Export Account": {T: "تصدير الحساب"},
"simultaneous_servers_msg": {T: "يدعم عميل منصة المبادلات اللامركزية لديكريد الاستخدام المتزامن لأي عدد من خوادم منصة المبادلات اللامركزية DEX."},
"Change App Password": {T: "تغيير كلمة مرور التطبيق"},
"Build ID": {T: "معرف البنية"},
"Version": {T: "معرف البنية"},
"Connect": {T: "اتصل"},
"Send": {T: "ارسال"},
"Deposit": {T: "إيداع"},
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/locales/de-de.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ var DeDE = map[string]*intl.Translation{
"Export Account": {T: "Account exportieren"},
"simultaneous_servers_msg": {T: "Der <span class=brand></span> unterstützt die gleichzeitige Nutzung einer beliebigen Anzahl von DEX-Servern."},
"Change App Password": {T: "App-Passwort ändern"},
"Build ID": {T: "Build ID"},
"Version": {T: "Version"},
"Connect": {T: "Verbinden"},
"Send": {T: "Senden"},
"Deposit": {T: "Einzahlen"},
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/locales/en-us.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ var EnUS = map[string]*intl.Translation{
"browser_ntfn_blocked": {T: "Browser notifications are currently blocked. Please unblock this site in your browser to receive notifications."},
"enable_browser_ntfn_info": {T: "Desktop notifications appear even when this window is not active. When you have other applications open this can be helpful as you will be notified on DCRDEX events. Customize below the types of notifications you would like to receive."},
"Save Notifications": {T: "Save Notifications"},
"Build ID": {T: "Build ID"},
"Version": {T: "Version"},
"Connect": {T: "Connect"},
"Send": {T: "Send"},
"Deposit": {T: "Deposit"}, // unused
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/locales/pl-pl.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ var PlPL = map[string]*intl.Translation{
"Export Account": {T: "Eksportuj konto"},
"simultaneous_servers_msg": {T: "Klient Decred DEX wspiera jednoczesne korzystanie z wielu serwerów DEX."},
"Change App Password": {T: "Zmień hasło aplikacji"},
"Build ID": {T: "ID builda"},
"Version": {T: "Wersja"},
"Connect": {T: "Połącz"},
"Withdraw": {T: "Wypłać"},
"Deposit": {T: "Zdeponuj"},
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/locales/pt-br.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ var PtBr = map[string]*intl.Translation{
"Export Account": {T: "Exportar Conta"},
"simultaneous_servers_msg": {T: "O cliente da DEX suporta simultâneos números de servidores DEX."},
"Change App Password": {T: "Trocar Senha do aplicativo"},
"Build ID": {T: "ID da Build"},
"Version": {T: "Versão"},
"Connect": {T: "Conectar"},
"Withdraw": {T: "Retirar"},
"Deposit": {T: "Depositar"},
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/locales/zh-cn.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ var ZhCN = map[string]*intl.Translation{
"Export Account": {T: "退出账户"},
"simultaneous_servers_msg": {T: "Decred DEX 客户端支持同时使用任意数量的 DEX 服务器。"},
"Change App Password": {T: "更改应用程序密码"},
"Build ID": {T: "构建 ID"},
"Version": {T: "版本"},
"Connect": {T: "连接"},
"Send": {T: "发送"},
"Deposit": {T: "存款"},
Expand Down
6 changes: 3 additions & 3 deletions client/webserver/site/src/html/bodybuilder.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<link rel="icon" href="/img/favicon.png?v=AZ4AZX">
<meta name="description" content="Bison Wallet">
<title>{{.Title}}</title>
<link href="/css/style.css?v={{commitHash}}" rel="stylesheet">
<link href="/css/style.css{{webpackBuildIdQuery}}" rel="stylesheet">
</head>
<body {{if .UseDEXBranding}}class="dex-branding"{{end}}>
<div class="popup-notes d-hide" id="popupNotes">
Expand Down Expand Up @@ -97,7 +97,7 @@
<span class="ico-barchart fs16 me-2"></span>
[[[Market Making]]]
</a>
<a href="/settings" class="demi hoverbright plainlink d-flex align-items-center py-1">
<a href="/settings" class="demi hoverbright plainlink d-flex align-items-center py-1 authed-only">
<span class="ico-settings fs16 me-2"></span>
[[[Settings]]]
</a>
Expand Down Expand Up @@ -257,7 +257,7 @@
</div>
</div>

<script src="/js/entry.js?v={{commitHash}}"></script>
<script src="/js/entry.js{{webpackBuildIdQuery}}"></script>
</body>
</html>
{{end}}
3 changes: 2 additions & 1 deletion client/webserver/site/src/html/settings.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
<div id="gameCodeLink" class="py-3 mb-3 border-bottom pointer hoverbg">
<span class="ico-ticket"></span> [[[Redeem game code]]]
</div>
<p class="grey">[[[Build ID]]]: <span id="commitHash" class="mono"></span></p>
{{$version := .AppVersion}}
<p class="grey">[[[Version]]]: <span id="version" class="mono">{{$version}}</span></p>
</div>
</section>

Expand Down
8 changes: 4 additions & 4 deletions client/webserver/site/src/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export default class Application {
authed: boolean
user: User
seedGenTime: number
commitHash: string
webpackBuildID: string
showPopups: boolean
loggers: Record<string, boolean>
recorders: Record<string, LogMessage[]>
Expand All @@ -185,14 +185,14 @@ export default class Application {
this.notes = []
this.pokes = []
this.seedGenTime = 0
this.commitHash = process.env.COMMITHASH || ''
this.webpackBuildID = process.env.WEBPACK_BUILD_ID || ''
this.noteReceivers = []
this.fiatRatesMap = {}
this.showPopups = State.fetchLocal(State.popupsLK) === '1'
this.txHistoryMap = {}
this.requiredActions = {}

console.log('Bison Wallet, Build', this.commitHash.substring(0, 7))
console.log('Bison Wallet', 'Webpack Build Id:', this.webpackBuildID)

// Set Bootstrap dark theme attribute if dark mode is enabled.
if (State.isDark()) {
Expand Down Expand Up @@ -261,7 +261,7 @@ export default class Application {
// Don't fetch the user until we know what page we're on.
await this.fetchUser()
const ignoreCachedLocale = process.env.NODE_ENV === 'development'
await intl.loadLocale(this.lang, this.commitHash, ignoreCachedLocale)
await intl.loadLocale(this.lang, this.webpackBuildID, ignoreCachedLocale)
// The application is free to respond with a page that differs from the
// one requested in the omnibox, e.g. routing though a login page. Set the
// current URL state based on the actual page.
Expand Down
6 changes: 3 additions & 3 deletions client/webserver/site/src/js/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,16 @@ export const ID_DELETE_BOT = 'DELETE_BOT'

let locale: Locale

export async function loadLocale (lang: string, commitHash: string, skipCache: boolean) {
export async function loadLocale (lang: string, buildID: string, skipCache: boolean) {
if (!skipCache) {
const specs = State.fetchLocal(State.localeSpecsKey)
if (specs && specs.lang === lang && specs.commitHash === commitHash) {
if (specs && specs.lang === lang && specs.webpackBuildID === buildID) { // not stale
locale = State.fetchLocal(State.localeKey)
return
}
}
locale = await postJSON('/api/locale', lang)
State.storeLocal(State.localeSpecsKey, { lang, commitHash })
State.storeLocal(State.localeSpecsKey, { lang, buildID })
State.storeLocal(State.localeKey, locale)
}

Expand Down
2 changes: 1 addition & 1 deletion client/webserver/site/src/js/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ export interface Application {
exchanges: Record<string, Exchange>
fiatRatesMap: Record<number, number>
showPopups: boolean
commitHash: string
webpackBuildID: string
authed: boolean
start (): Promise<void>
reconnected (): void
Expand Down
1 change: 0 additions & 1 deletion client/webserver/site/src/js/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export default class SettingsPage extends BasePage {
app().showPopups = show
})

page.commitHash.textContent = app().commitHash.substring(0, 7)
Doc.bind(page.addADex, 'click', () => {
this.dexAddrForm.refresh()
this.showForm(page.dexAddrForm)
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/site/webpack/analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = merge(common, {
rules: [{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/,
exclude: /node_modules/
}]
},
optimization: {
Expand Down
29 changes: 20 additions & 9 deletions client/webserver/site/webpack/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const StyleLintPlugin = require('stylelint-webpack-plugin')
const ESLintPlugin = require('eslint-webpack-plugin')

const child_process = require('child_process')
function git(command) {
return child_process.execSync(`git ${command}`, { encoding: 'utf8' }).trim();
const fs = require('node:fs')
const buildIdFilename = 'webpack-build-id.txt'

function randBuildId () {
const buildID = JSON.stringify(Math.floor(Math.random() * 1000000000)).trim()
console.log('WEBPACK_BUILD_ID:', buildID)
fs.writeFile(buildIdFilename, buildID, err => {
if (err) {
console.error(err)
} else {
console.log(' ', buildID, ' written to ', buildIdFilename)
}
})
return buildID
}

module.exports = {
target: "web",
target: 'web',
module: {
rules: [
{
Expand All @@ -29,7 +40,7 @@ module.exports = {
{
loader: 'sass-loader',
options: {
implementation: require("sass"), // dart-sass
implementation: require('sass'), // dart-sass
sourceMap: true
}
}
Expand All @@ -38,15 +49,15 @@ module.exports = {
]
},
plugins: [
new webpack.EnvironmentPlugin({
COMMITHASH: git('rev-parse HEAD'),
new webpack.DefinePlugin({
'process.env.WEBPACK_BUILD_ID': randBuildId()
}),
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: '../dist/style.css'
}),
new StyleLintPlugin({
threads: true,
threads: true
}),
new ESLintPlugin({
extensions: ['ts'],
Expand All @@ -59,7 +70,7 @@ module.exports = {
publicPath: '/dist/'
},
resolve: {
extensions: ['.ts', ".js"],
extensions: ['.ts', '.js']
},
// Fixes weird issue with watch script. See
// https://github.com/webpack/webpack/issues/2297#issuecomment-289291324
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/site/webpack/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = merge(common, {
rules: [{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/,
exclude: /node_modules/
}]
},
devtool: 'inline-source-map'
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/site/webpack/prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = merge(common, {
usedExports: true,
minimize: true,
minimizer: [
`...`, // extend webpack 5's TerserPlugin
'...', // extend webpack 5's TerserPlugin
new CssMinimizerPlugin({})
]
},
Expand Down
Loading
Loading