useIdentityKit
@nfid/identitykit
exports only one react hook, which is needed for getting the agent for the
currently connected user, its wallet address (as a valid ICRC1 Account), balance, disconnect
function and other:
Import
import { useIdentityKit } from "@nfid/identitykit/react"
Usage
const {
agent,
user,
icpBalance,
signer,
identity,
delegationType,
accounts,
connect,
disconnect,
fetchIcpBalance,
} = useIdentityKit()
Return values
agent
SignerAgent<Signer<Transport>> | null
@nfid/identitykit
agent which implements @dfinity/agent
Agent, it comes with predefined user and
should be used if canister call requires approve. Will be null until successfull connect.
user
{ principal: Principal, subaccount?: SubAccount} | undefined
Currently connected user principal and subaccount. Will be undefined until successfull connect.
icpBalance
number | undefined
Balance of connected user, will be undefined until successfull connect
signer
Signer<Transport> | undefined
Selected signer, undefined until selection
identity
Identity | PartialIdentity | undefined
If IdentityKitProvider.authType
is set to IdentityKitAuthType.DELEGATION
value will contain
@dfinity
identity after successfull connect, will be undefined if other authType is selected or
user not connected
delegationType
IdentityKitDelegationType.GLOBAL | IdentityKitDelegationType.ANONYMOUS
Will contain type of delegation depending whether IdentityKitProvider.targets
were provided or not
in case IdentityKitProvider.authType
is set to IdentityKitAuthType.DELEGATION
and user is
connected, otherwise will be undefined
accounts
{ principal: Principal, subaccount?: SubAccount}[] | undefined
Will contain connected accounts in case IdentityKitProvider.authType
is set to
IdentityKitAuthType.ACCOUNTS
and user is connected, otherwise will be undefined
connect
() => void
Function to trigger manual connect (opening of signers modal)
disconnect
() => Promise<void>
Function to trigger manual disconnect
fetchIcpBalance
() => Promise<void> | undefined
Function to manually fetch ICP balance of connected user, will be undefined if user is not
connected. Note function does not return balance, instead updates icpBalance
from
useIdentityKit()