Skip to content

Commit

Permalink
client: add login notes to show present task during login
Browse files Browse the repository at this point in the history
  • Loading branch information
ukane-philemon committed Dec 19, 2022
1 parent 38fb1d4 commit 265ec3b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 3 deletions.
4 changes: 4 additions & 0 deletions client/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -4268,6 +4268,7 @@ func (c *Core) Login(pw []byte) error {
return fmt.Errorf("cannot log in because app has not been initialized")
}

c.notify(newLoginNote("Verifying credentials..."))
if len(creds.EncInnerKey) == 0 {
err := c.initializePrimaryCredentials(pw, creds.OuterKeyParams)
if err != nil {
Expand All @@ -4293,8 +4294,11 @@ func (c *Core) Login(pw []byte) error {
// resolveActiveTrades. We won't try to unlock here, but if the wallet
// is needed for active trades, it will be unlocked in resolveActiveTrades
// and the balance updated there.
c.notify(newLoginNote("Connecting wallets..."))
c.connectWallets()
c.notify(newLoginNote("Resuming active trades..."))
c.resolveActiveTrades(crypter)
c.notify(newLoginNote("Connecting to DEX servers..."))
c.initializeDEXConnections(crypter)
if err = c.loadBotPrograms(); err != nil {
c.log.Errorf("Error loading bot programs: %v", err)
Expand Down
14 changes: 14 additions & 0 deletions client/core/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
NoteTypeDEXAuth = "dex_auth"
NoteTypeFiatRates = "fiatrateupdate"
NoteTypeCreateWallet = "createwallet"
NoteTypeLogin = "login"
)

var noteChanCounter uint64
Expand Down Expand Up @@ -613,3 +614,16 @@ func newBotNote(topic Topic, subject, details string, severity db.Severity, repo
Report: report,
}
}

// LoginNote is a notification with the recent login status.
type LoginNote struct {
db.Notification
}

const TopicLoginStatus Topic = "LoginStatus"

func newLoginNote(message string) *LoginNote {
return &LoginNote{
Notification: db.NewNotification(NoteTypeLogin, TopicLoginStatus, "", message, db.Data),
}
}
4 changes: 4 additions & 0 deletions client/webserver/site/src/css/forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ button.form-button {

#loginForm {
width: 250px;

#loader {
backdrop-filter: blur(4px);
}
}

#unlockWalletForm,
Expand Down
3 changes: 2 additions & 1 deletion client/webserver/site/src/html/bodybuilder.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
</div>
<div id="loader" class="fill-abs flex-center d-hide">
<div class="ico-spinner spinner"></div>
<div id="loaderMsg" class="mx-2"></div>
</div>

<div id="noteBox" class="d-hide">
Expand Down Expand Up @@ -102,7 +103,7 @@
{{end}}

{{define "bottom"}}
<script src="/js/entry.js?v=XYXY183gH"></script>
<script src="/js/entry.js?v=jBRE183gH"></script>
</body>
</html>
{{end}}
2 changes: 1 addition & 1 deletion client/webserver/site/src/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export default class Application {
})
// The main element is the interchangeable part of the page that doesn't
// include the header. Main should define a data-handler attribute
// associated with one of the available constructors.
// associated with one of the available constructors.
this.main = idel(document, 'main')
const handler = this.main.dataset.handler
// Don't fetch the user until we know what page we're on.
Expand Down
13 changes: 12 additions & 1 deletion client/webserver/site/src/js/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
WalletStateNote,
WalletInfo,
Token,
WalletCreationNote
WalletCreationNote,
CoreNote
} from './registry'
import { XYRangeHandler } from './opts'

Expand Down Expand Up @@ -1573,6 +1574,16 @@ export class LoginForm {
this.headerTxt = page.header.textContent || ''

bind(form, page.submit, () => { this.submit() })

app().registerNoteFeeder({
login: (note: CoreNote) => { this.handleLoginNote(note) }
})
}

handleLoginNote (n: CoreNote) {
if (n.details === '') return
const loginMsg = Doc.idel(this.form, 'loaderMsg')
if (loginMsg) loginMsg.textContent = n.details
}

focus () {
Expand Down

0 comments on commit 265ec3b

Please sign in to comment.