Skip to content

Commit

Permalink
223 update wallet balance (#269)
Browse files Browse the repository at this point in the history
adds wallet balance display to front.
  • Loading branch information
thomas-senechal authored Nov 17, 2022
1 parent 3daa515 commit 1577c69
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 56 deletions.
3 changes: 3 additions & 0 deletions api/swagger/server/models/wallet.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 16 additions & 52 deletions api/swagger/server/restapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions api/swagger/server/restapi/resource/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,9 @@ definitions:
address:
description: wallet's address.
type: string
balance:
description: wallet's balance.
type: number
keyPairs:
description: wallet's key pairs.
type: array
Expand Down
5 changes: 5 additions & 0 deletions int/api/html/front/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const errorCodes = new Map([
"Wallet-4001",
"Error while connecting all your wallets. Reconnect all your wallets and try again",
],
[
"Wallet-4002",
"Error while fetching your balance. Reconnect all your wallets and try again",
],

["Wallet-5001", "Please select a wallet to be able to see your domains"],
["Wallet-5002", "Please select a wallet to be able to perform that action"],

Expand Down
2 changes: 1 addition & 1 deletion int/api/html/front/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function tableInsert(resp) {

cell0.innerHTML = addressInnerHTML(resp.address);
cell1.innerHTML = resp.nickname;
cell2.innerHTML = 0;
cell2.innerHTML = resp.balance ?? 0;
cell3.innerHTML =
'<svg class="quit-button" onclick="deleteRow(this)" xmlns="http://www.w3.org/2000/svg" width="24" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x"><line x1="18" y1="6" x2="6" y2="18"></line> <line x1="6" y1="6" x2="18" y2="18"></line></svg>';
}
Expand Down
1 change: 1 addition & 0 deletions int/api/wallet/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,6 @@ func (c *walletCreate) Handle(params operations.MgmtWalletCreateParams) middlewa
Salt: &salt,
Nonce: &nonce,
}},
Balance: 0,
})
}
1 change: 1 addition & 0 deletions int/api/wallet/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ const (
errorCodeWalletDeleteFile = "Wallet-2002"
errorCodeWalletImportNew = "Wallet-3001"
errorCodeWalletGetWallets = "Wallet-4001"
errorCodeWalletGetBalance = "Wallet-4002"
)
26 changes: 25 additions & 1 deletion int/api/wallet/get.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package wallet

import (
"strconv"
"sync"

"github.com/go-openapi/runtime/middleware"
"github.com/massalabs/thyra/api/swagger/server/models"
"github.com/massalabs/thyra/api/swagger/server/restapi/operations"
"github.com/massalabs/thyra/pkg/node"
"github.com/massalabs/thyra/pkg/node/ledger"
"github.com/massalabs/thyra/pkg/wallet"
)

Expand All @@ -20,6 +23,8 @@ type walletGet struct {

//nolint:nolintlint,ireturn
func (c *walletGet) Handle(params operations.MgmtWalletGetParams) middleware.Responder {
client := node.NewDefaultClient()

wallets, err := wallet.LoadAll()
if err != nil {
return operations.NewMgmtWalletGetInternalServerError().WithPayload(
Expand All @@ -31,11 +36,30 @@ func (c *walletGet) Handle(params operations.MgmtWalletGetParams) middleware.Res

var wal []*models.Wallet

for i := 0; i < len(wallets); i++ {
for i := 0; i < len(wallets); i++ { //nolint:varnamelen
address, err := ledger.Addresses(client, []string{wallets[i].Address})
if err != nil {
return operations.NewMgmtWalletGetInternalServerError().WithPayload(
&models.Error{
Code: errorCodeWalletGetBalance,
Message: err.Error(),
})
}

balance, err := strconv.ParseFloat(address[0].CandidateBalance, 64)
if err != nil {
return operations.NewMgmtWalletGetInternalServerError().WithPayload(
&models.Error{
Code: errorCodeWalletGetBalance,
Message: err.Error(),
})
}

walletss := &models.Wallet{
Nickname: &wallets[i].Nickname,
Address: &wallets[i].Address,
KeyPairs: []*models.WalletKeyPairsItems0{},
Balance: balance,
}

wal = append(wal, walletss)
Expand Down
4 changes: 2 additions & 2 deletions pkg/node/ledger/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ type Address struct {
Address string `json:"address"`
BlockDraws []string `json:"block_draws"`
BlocksCreated []string `json:"blocks_created"`
CandidateBalanceInfo string `json:"candidate_balance_info"`
CandidateBalance string `json:"candidate_balance"`
CandidateDatastoreKeys [][]byte `json:"candidate_datastore_keys"`
FinalBalanceInfo string `json:"final_balance_info"`
FinalBalance string `json:"final_balance"`
FinalDatastoreKeys [][]byte `json:"final_datastore_keys"`
}

Expand Down

0 comments on commit 1577c69

Please sign in to comment.