mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-17 12:14:21 +01:00
pkg/client-sdk: expose IsLocked (#247)
* expose IsLocked * add test for IsLocked
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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())
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user