Skip to content

Commit

Permalink
fix: Make sure the app can start without config
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinTrinque committed Mar 25, 2023
1 parent fa6d8e0 commit a5579bb
Show file tree
Hide file tree
Showing 46 changed files with 2,117 additions and 2,372 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/build-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ jobs:
- arm64
steps:
- name: Set up Node 16
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 16
id: npm

- name: Set up Go ^1.17
uses: actions/setup-go@v2
- name: Set up Go ^1.19
uses: actions/setup-go@v4
with:
go-version: ^1.17
go-version: ^1.19
id: go

- name: Get Wails
run: go install github.com/wailsapp/wails/v2/cmd/wails@latest
run: go install github.com/wailsapp/wails/v2/cmd/wails@v2.4.1

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Build binary for Windows
if: ${{ runner.os == 'Windows' }}
Expand All @@ -63,15 +63,15 @@ jobs:
- amd64
steps:
- name: Set up Node 16
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 16
id: npm

- name: Set up Go ^1.17
uses: actions/setup-go@v2
- name: Set up Go ^1.19
uses: actions/setup-go@v4
with:
go-version: ^1.17
go-version: ^1.19
id: go

- name: Install Wails dependencies
Expand All @@ -80,10 +80,10 @@ jobs:
sudo apt-get install build-essential libgtk-3-dev libwebkit2gtk-4.0-dev
- name: Get Wails
run: go install github.com/wailsapp/wails/v2/cmd/wails@latest
run: go install github.com/wailsapp/wails/v2/cmd/wails@v2.4.1

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Build binary
run: wails build -f -platform=linux/${{ matrix.arch }}
Expand Down
30 changes: 15 additions & 15 deletions .github/workflows/release-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ jobs:
- arm64
steps:
- name: Set up Node 16
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 16
id: npm

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: 1.17
go-version: ^1.19
id: go

- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Get Wails
run: go install github.com/wailsapp/wails/v2/cmd/wails@latest
run: go install github.com/wailsapp/wails/v2/cmd/wails@v2.4.1

- name: Build binary
run: |
Expand Down Expand Up @@ -120,22 +120,22 @@ jobs:
- arm64
steps:
- name: Set up Node 16
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 16
id: npm

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: 1.17
go-version: ^1.19
id: go

- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Get Wails
run: go install github.com/wailsapp/wails/v2/cmd/wails@latest
run: go install github.com/wailsapp/wails/v2/cmd/wails@v2.4.1

- name: Build binary
run: |
Expand Down Expand Up @@ -184,27 +184,27 @@ jobs:
- amd64
steps:
- name: Set up Node 16
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 16
id: npm

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: 1.17
go-version: ^1.19
id: go

- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Install Wails dependencies
run: |
sudo apt-get update
sudo apt-get install build-essential libgtk-3-dev libwebkit2gtk-4.0-dev
- name: Get Wails
run: go install github.com/wailsapp/wails/v2/cmd/wails@latest
run: go install github.com/wailsapp/wails/v2/cmd/wails@v2.4.1

- name: Build binary
run: |
Expand Down
22 changes: 11 additions & 11 deletions .github/workflows/test-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ jobs:
CGO_ENABLED: 1 # Needed by Wails
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Use Node.js 16
id: Node
uses: actions/setup-node@v2-beta
uses: actions/setup-node@v3
with:
node-version: 16

- name: Set up Go ^1.17
uses: actions/setup-go@v2
- name: Set up Go ^1.19
uses: actions/setup-go@v4
with:
go-version: ^1.17
go-version: ^1.19
id: go

- name: Get Wails
run: go install github.com/wailsapp/wails/v2/cmd/wails@v2.0.0-beta.32
run: go install github.com/wailsapp/wails/v2/cmd/wails@v2.4.1

- name: Get dependencies
run: go get -v -t -d ./...
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
# pass the project ID from the secrets through environment variable
CYPRESS_PROJECT_ID: ${{ secrets.PROJECT_ID }}

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: coverage
Expand All @@ -84,11 +84,11 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Use Node.js 16
id: Node
uses: actions/setup-node@v2-beta
uses: actions/setup-node@v3
with:
node-version: 16

Expand All @@ -105,10 +105,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up Node 16
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 16
id: npm
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/verify-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
name: Verify CHANGELOG update
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3

- name: Check changelog
uses: Zomzog/[email protected]
Expand Down
12 changes: 3 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
# Created when applications are built
build/bin

# Created when frontend is built
frontend/build
frontend/dist

# Cypress
frontend/automation/.nyc_output/
frontend/automation/test-wallets/
frontend/automation/network-config/
# Auto-generated files during application build
build/windows/installer
build/windows/icon.ico

# Misc
.DS_Store
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Changelog

## ## 0.2.1
## 0.2.2

Compatible with 0.53.2

### 🛠 Improvements
- Bring the app to front when transaction needs to be reviewed.

### 🐛 Fixes
- Do not crash when starting for the first time, ever.


## 0.2.1

### 🐛 Fixes
- [252](https://github.com/vegaprotocol/vegawallet-desktop/issues/252) - Do not crash on Windows when creating log files
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Be sure to have the following environment variables set:
- `GO111MODULE=on`

```sh
go install github.com/wailsapp/wails/v2/cmd/wails@v2.0.0-beta.32
go install github.com/wailsapp/wails/v2/cmd/wails@v2.4.1
```

To check if you have the correct dependencies installed, use the following command:
Expand Down
20 changes: 19 additions & 1 deletion backend/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,25 @@ func (l *Loader) IsConfigInitialised() (bool, error) {
}

func (l *Loader) GetConfig() (Config, error) {
config := Config{}
exists, err := vgfs.FileExists(l.configFilePath)
if err != nil {
return Config{}, fmt.Errorf("could not verify the application configuration exists: %w", err)
}

config := Config{
LogLevel: zap.InfoLevel.String(),
VegaHome: "",
DefaultNetwork: "",
Telemetry: &TelemetryConfig{
ConsentAsked: false,
Enabled: true,
},
}

if !exists {
return config, nil
}

if err := paths.ReadStructuredFile(l.configFilePath, &config); err != nil {
return Config{}, fmt.Errorf("couldn't read configuration file: %w", err)
}
Expand Down
10 changes: 8 additions & 2 deletions backend/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,15 @@ func (h *Handler) StartService(req *StartServiceRequest) (bool, error) {
case <-ctx.Done():
h.log.Info("Stop listening to channels")
return
case consentRequest := <-h.service.ConsentRequestsChan:
case consentRequest, ok := <-h.service.ConsentRequestsChan:
if !ok {
return
}
h.emitNewConsentRequestEvent(consentRequest)
case sentTransaction := <-h.service.SentTransactionsChan:
case sentTransaction, ok := <-h.service.SentTransactionsChan:
if !ok {
return
}
h.emitTransactionSentEvent(sentTransaction)
}
}
Expand Down
24 changes: 13 additions & 11 deletions backend/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func (h *Handler) ConsentToTransaction(req *ConsentToTransactionRequest) error {
return ErrConsentRequestNotFound
}
if req.Decision {
h.log.Info("user approved transaction", zap.Any("transaction", consentRequest))
h.log.Info("user approved transaction", zap.Any("transaction", consentRequest.TxID))
consentRequest.Confirmation <- service.ConsentConfirmation{Decision: true}
} else {
h.log.Info("user declined transaction", zap.Any("transaction", consentRequest))
h.log.Info("user declined transaction", zap.Any("transaction", consentRequest.TxID))
consentRequest.Confirmation <- service.ConsentConfirmation{Decision: false}
}

Expand All @@ -82,7 +82,7 @@ func (h *Handler) GetConsentRequest(req *GetConsentRequestRequest) (*ConsentRequ
m := jsonpb.Marshaler{}
marshaledTransaction, err := m.MarshalToString(consentRequest.Tx)
if err != nil {
panic("couldn't marshal transaction")
h.log.Error("couldn't marshal transaction", zap.Error(err))
}

return &ConsentRequest{
Expand All @@ -98,7 +98,7 @@ func (h *Handler) ListConsentRequests() (*ListConsentRequestsResponse, error) {

consentRequests := []*ConsentRequest{}
h.service.ConsentRequests.Range(func(consentRequest service.ConsentRequest) bool {
consentRequests = append(consentRequests, toSerializableConsentRequest(consentRequest))
consentRequests = append(consentRequests, h.toSerializableConsentRequest(consentRequest))
return true
})

Expand All @@ -113,7 +113,7 @@ func (h *Handler) ListSentTransactions() (*ListSentTransactionsResponse, error)

sentTransactions := []*SentTransaction{}
h.service.SentTransactions.Range(func(sentTransaction service.SentTransaction) bool {
sentTransactions = append(sentTransactions, toSerializableSentTransaction(sentTransaction))
sentTransactions = append(sentTransactions, h.toSerializableSentTransaction(sentTransaction))
return true
})

Expand All @@ -134,23 +134,25 @@ func (h *Handler) emitTransactionSentEvent(sentTransaction service.SentTransacti
h.log.Info(fmt.Sprintf("Received a \"transaction_sent\" event with ID: %s", sentTransaction.TxID))
h.service.SentTransactions.Store(sentTransaction)
go func() {
runtime.EventsEmit(h.ctx, TransactionSentEvent, toSerializableSentTransaction(sentTransaction))
runtime.WindowShow(h.ctx)
runtime.EventsEmit(h.ctx, TransactionSentEvent, h.toSerializableSentTransaction(sentTransaction))
}()
}

func (h *Handler) emitNewConsentRequestEvent(consentRequest service.ConsentRequest) {
h.log.Info(fmt.Sprintf("Received a \"new_consent_request\" event with ID: %s", consentRequest.TxID))
h.service.ConsentRequests.Store(consentRequest)
go func() {
runtime.EventsEmit(h.ctx, NewConsentRequestEvent, toSerializableConsentRequest(consentRequest))
runtime.WindowShow(h.ctx)
runtime.EventsEmit(h.ctx, NewConsentRequestEvent, h.toSerializableConsentRequest(consentRequest))
}()
}

func toSerializableConsentRequest(consentRequest service.ConsentRequest) *ConsentRequest {
func (h *Handler) toSerializableConsentRequest(consentRequest service.ConsentRequest) *ConsentRequest {
m := jsonpb.Marshaler{}
marshaledTransaction, err := m.MarshalToString(consentRequest.Tx)
if err != nil {
panic("couldn't marshal transaction")
h.log.Error("couldn't marshal transaction", zap.Error(err))
}

return &ConsentRequest{
Expand All @@ -160,11 +162,11 @@ func toSerializableConsentRequest(consentRequest service.ConsentRequest) *Consen
}
}

func toSerializableSentTransaction(sentTransaction service.SentTransaction) *SentTransaction {
func (h *Handler) toSerializableSentTransaction(sentTransaction service.SentTransaction) *SentTransaction {
m := jsonpb.Marshaler{}
marshaledTransaction, err := m.MarshalToString(sentTransaction.Tx)
if err != nil {
panic("couldn't marshal transaction")
h.log.Error("couldn't marshal transaction", zap.Error(err))
}

serializableSentTransaction := &SentTransaction{
Expand Down
Loading

0 comments on commit a5579bb

Please sign in to comment.