pkg/client-sdk: expose IsLocked (#247)

* expose IsLocked

* add test for IsLocked
This commit is contained in:
Marco Argentieri
2024-08-14 14:07:15 +02:00
committed by GitHub
parent e79819cca8
commit 2e6fa7fe6d
5 changed files with 21 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ type ArkClient interface {
GetConfigData(ctx context.Context) (*store.StoreData, error) GetConfigData(ctx context.Context) (*store.StoreData, error)
Init(ctx context.Context, args InitArgs) error Init(ctx context.Context, args InitArgs) error
InitWithWallet(ctx context.Context, args InitWithWalletArgs) error InitWithWallet(ctx context.Context, args InitWithWalletArgs) error
IsLocked(ctx context.Context) bool
Unlock(ctx context.Context, password string) error Unlock(ctx context.Context, password string) error
Lock(ctx context.Context, password string) error Lock(ctx context.Context, password string) error
Balance(ctx context.Context, computeExpiryDetails bool) (*Balance, error) Balance(ctx context.Context, computeExpiryDetails bool) (*Balance, error)

View File

@@ -196,6 +196,10 @@ func (a *arkClient) Lock(ctx context.Context, pasword string) error {
return a.wallet.Lock(ctx, pasword) return a.wallet.Lock(ctx, pasword)
} }
func (a *arkClient) IsLocked(ctx context.Context) bool {
return a.wallet.IsLocked()
}
func (a *arkClient) Receive(ctx context.Context) (string, string, error) { func (a *arkClient) Receive(ctx context.Context) (string, string, error) {
offchainAddr, onchainAddr, err := a.wallet.NewAddress(ctx, false) offchainAddr, onchainAddr, err := a.wallet.NewAddress(ctx, false)
if err != nil { if err != nil {

View File

@@ -134,6 +134,15 @@ func TestWallet(t *testing.T) {
err = walletSvc.Lock(ctx, "") err = walletSvc.Lock(ctx, "")
require.NoError(t, err) require.NoError(t, err)
locked := walletSvc.IsLocked()
require.True(t, locked)
_, err = walletSvc.Unlock(ctx, password)
require.NoError(t, err)
locked = walletSvc.IsLocked()
require.False(t, locked)
}) })
} }
} }

View File

@@ -25,6 +25,7 @@ func init() {
js.Global().Set("init", InitWrapper()) js.Global().Set("init", InitWrapper())
js.Global().Set("unlock", UnlockWrapper()) js.Global().Set("unlock", UnlockWrapper())
js.Global().Set("lock", LockWrapper()) js.Global().Set("lock", LockWrapper())
js.Global().Set("locked", IsLockedWrapper())
js.Global().Set("balance", BalanceWrapper()) js.Global().Set("balance", BalanceWrapper())
js.Global().Set("onboard", OnboardWrapper()) js.Global().Set("onboard", OnboardWrapper())
js.Global().Set("receive", ReceiveWrapper()) js.Global().Set("receive", ReceiveWrapper())

View File

@@ -76,6 +76,12 @@ func InitWrapper() js.Func {
}) })
} }
func IsLockedWrapper() js.Func {
return js.FuncOf(func(this js.Value, p []js.Value) interface{} {
return js.ValueOf(arkSdkClient.IsLocked(context.Background()))
})
}
func UnlockWrapper() js.Func { func UnlockWrapper() js.Func {
return JSPromise(func(args []js.Value) (interface{}, error) { return JSPromise(func(args []js.Value) (interface{}, error) {
if len(args) != 1 { if len(args) != 1 {