Don't pannic on walletDefAddr with no addrs

This commit is contained in:
Łukasz Magiera 2019-07-26 01:26:40 +02:00
parent ccfec98f96
commit 45ddd8e590
2 changed files with 8 additions and 1 deletions

View File

@ -80,7 +80,10 @@ class FullNode extends React.Component {
this.setState(() => ({tipset: tipset})) this.setState(() => ({tipset: tipset}))
const addrss = await this.state.client.call('Filecoin.WalletList', []) const addrss = await this.state.client.call('Filecoin.WalletList', [])
const defaultAddr = await this.state.client.call('Filecoin.WalletDefaultAddress', []) let defaultAddr = ""
if (addrss.length > 0) {
defaultAddr = await this.state.client.call('Filecoin.WalletDefaultAddress', [])
}
const balances = await addrss.map(async addr => { const balances = await addrss.map(async addr => {
let balance = 0 let balance = 0

View File

@ -2,6 +2,7 @@ package impl
import ( import (
"context" "context"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-lotus/api" "github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/chain" "github.com/filecoin-project/go-lotus/chain"
@ -132,6 +133,9 @@ func (a *FullNodeAPI) WalletDefaultAddress(ctx context.Context) (address.Address
if err != nil { if err != nil {
return address.Undef, err return address.Undef, err
} }
if len(addrs) == 0 {
return address.Undef, xerrors.New("no addresses in wallet")
}
// TODO: store a default address in the config or 'wallet' portion of the repo // TODO: store a default address in the config or 'wallet' portion of the repo
return addrs[0], nil return addrs[0], nil