mirror of
https://github.com/hanzo-fi/stack.git
synced 2026-10-30 20:34:43 +00:00
76 lines
1.8 KiB
Go
76 lines
1.8 KiB
Go
package wallets
|
|
|
|
import (
|
|
"github.com/formancehq/fctl/cmd/wallets/internal"
|
|
"github.com/formancehq/fctl/cmd/wallets/internal/views"
|
|
fctl "github.com/formancehq/fctl/pkg"
|
|
"github.com/formancehq/formance-sdk-go/v2/pkg/models/operations"
|
|
"github.com/formancehq/formance-sdk-go/v2/pkg/models/shared"
|
|
"github.com/pkg/errors"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
type ShowStore struct {
|
|
Wallet shared.WalletWithBalances `json:"wallet"`
|
|
}
|
|
type ShowController struct {
|
|
store *ShowStore
|
|
}
|
|
|
|
var _ fctl.Controller[*ShowStore] = (*ShowController)(nil)
|
|
|
|
func NewDefaultShowStore() *ShowStore {
|
|
return &ShowStore{}
|
|
}
|
|
|
|
func NewShowController() *ShowController {
|
|
return &ShowController{
|
|
store: NewDefaultShowStore(),
|
|
}
|
|
}
|
|
|
|
func NewShowCommand() *cobra.Command {
|
|
c := NewShowController()
|
|
return fctl.NewCommand("show",
|
|
fctl.WithShortDescription("Show a wallets"),
|
|
fctl.WithAliases("sh"),
|
|
fctl.WithConfirmFlag(),
|
|
fctl.WithArgs(cobra.ExactArgs(0)),
|
|
internal.WithTargetingWalletByID(),
|
|
internal.WithTargetingWalletByName(),
|
|
fctl.WithController[*ShowStore](c),
|
|
)
|
|
}
|
|
|
|
func (c *ShowController) GetStore() *ShowStore {
|
|
return c.store
|
|
}
|
|
|
|
func (c *ShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) {
|
|
|
|
store := fctl.GetStackStore(cmd.Context())
|
|
|
|
walletID, err := internal.RetrieveWalletID(cmd, store.Client())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if walletID == "" {
|
|
return nil, errors.New("You need to specify wallet id using --id or --name flags")
|
|
}
|
|
|
|
response, err := store.Client().Wallets.V1.GetWallet(cmd.Context(), operations.GetWalletRequest{
|
|
ID: walletID,
|
|
})
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "getting wallet")
|
|
}
|
|
|
|
c.store.Wallet = response.GetWalletResponse.Data
|
|
|
|
return c, nil
|
|
}
|
|
|
|
func (c *ShowController) Render(cmd *cobra.Command, args []string) error {
|
|
return views.PrintWalletWithMetadata(cmd.OutOrStdout(), c.store.Wallet)
|
|
}
|