Methods

Here are the methods provided by the Wepin React Native Widget SDK.

getStatus

await wepinWidget.getStatus();

Returns the lifecycle status of the WepinSDK.

Parameters

  • None

Return value

  • Promise<WepinLifeCycle>

    • 'not_initialized' : if wepin is not initialized

    • 'initializing' : if wepin is initializing

    • 'initialized' : if wepin is initialized

    • 'before_login' : if wepin is initialized but the user is not logged in

    • 'login' : if the user is logged in

    • 'login_before_register' : if the user is logged in but the user is NOT registered in wepin

Example

const status = await wepinWidget.getStatus();

openWidget

The openWidget() method displays the Wepin widget. If a user is not logged in, the widget will not open. Therefore, you must log in to Wepin before using this method. To log in to Wepin, use the loginWithUI method or the login methods from the login variable.

Parameters

  • None

Return value

  • Promise <boolean>

Example

await wepinWidget.openWidget();

closeWidget

The closeWidget() method closes Wepin widget.

Parameters

  • None

Return value

  • Promise <boolean>

Example

await wepinWidget.closeWidget();

login

The login variable is a Wepin login library that includes various authentication methods, allowing users to log in using different approaches. It supports email and password login, OAuth provider login, login using ID tokens or access tokens, and more.

For detailed information on each method, refer to the official Login Library guide.

Available Methods

  • loginWithOauthProvider

  • signUpWithEmailAndPassword

  • loginWithEmailAndPassword

  • loginWithIdToken

  • loginWithAccessToken

  • getRefreshFirebaseToken

  • loginWepin

  • getCurrentWepinUser

  • logout

  • getSignForLogin

These methods support various login scenarios, allowing you to select the appropriate method based on your needs.

Example

// Login using an OAuth provider
const oauthResult = await wepinWidget.login.loginWithOauthProvider({
  provider: 'google',
  clientId: 'your-client-id',
});

// Sign up and log in using email and password
const signUpResult = await wepinWidget.login.signUpWithEmailAndPassword(
  '[email protected]',
  'password123'
);

// Log in using an ID token
const idTokenResult = await wepinWidget.login.loginWithIdToken({
  token: 'your-id-token',
  sign: 'your-sign',
});

// Log in to Wepin
const wepinLoginResult = await wepinWidget.login.loginWepin(idTokenResult);

// Get the currently logged-in user
const currentUser = await wepinWidget.login.getCurrentWepinUser();

// Logout
await wepinWidget.login.logout();

loginWithUI

The loginWithUI() method provides the functionality to log in using a widget and returns the information of the logged-in user. If a user is already logged in, the widget will not be displayed, and the method will directly return the logged-in user's information.

Parameters

  • providers <{provider: string, clientId: string}[]> - An array of login providers to configure the widget. If an empty array is provided, only the email login function is available.

    • provider <string> - The OAuth login provider (e.g., 'google', 'naver', 'discord', 'apple').

    • clientId <string> - The client ID of the OAuth login provider.

  • email <string> optional - The email parameter allows users to log in using the specified email address when logging in through the widget.

Return value

  • Promise<WepinUser>

    • status <'success'|'fail'>

    • userInfo <object> optional

      • userId <string> - Wepin User ID

      • email <string> - Wepin User Email Address

      • provider <'google'|'apple'|'naver'|'discord'|'email'|'external_token'>

      • use2FA <boolean>

    • userStatus: <object> - The user's status of wepin login. including:

      • loginStatus: <'complete' | 'pinRequired' | 'registerRequired'> - If the user's loginStatus value is not complete, it must be registered in the wepin.

      • pinRequired?:

    • walletId <string> optional

    • token: <object> - The user's token of wepin. including:

      • accessToken: <string> - The access token.

      • refreshToken: <string> - The refresh token.

Exception

Example

// google, apple, discord, naver login
const loginProviders = [
  { provider: 'google', clientId: 'google-client-id' },
  { provider: 'apple', clientId: 'apple-client-id' },
  { provider: 'discord', clientId: 'discord-client-id' },
  { provider: 'naver', clientId: 'naver-client-id' },
];

const userInfo = await wepinWidget.loginWithUI(loginProviders);

// only email login
const userInfo = await wepinWidget.loginWithUI([]);

// with specified email address
const userInfo = await wepinWidget.loginWithUI([], '[email protected]');
  • response

{
  "status": "success",
  "userInfo": {
    "userId": "120349034824234234",
    "email": "[email protected]",
    "provider": "google",
    "use2FA": true
  },
  "userStatus": {
    "loginStatus": "complete",
    "pinRequired": false
  },
  "walletId": "abcdsfsf123",
  "token": {
    "accessToken": "",
    "refreshToken": ""
  }
}

register

Register the user with Wepin. After joining and logging in, the Register page of the Wepin widget opens and registers (wipe and account creation) the Wepin service. Available only if the life cycle of the WepinSDK is login_before_register. After calling the loginWepin()method in the login variable, if the loginStatus value in the userStatus is not 'complete', this method must be called.

Parameters

  • None

Return value

  • Promise<WepinUser>

    • status <'success'|'fail'>

    • userInfo <object> optional

      • userId <string> - Wepin User ID

      • email <string> - Wepin User Email Address

      • provider <'google'|'apple'|'naver'|'discord'|'email'|'external_token'>

      • use2FA <boolean>

    • userStatus: <object> - The user's status of wepin login. including:

      • loginStatus: <'complete' | 'pinRequired' | 'registerRequired'> - If the user's loginStatus value is not complete, it must be registered in the wepin.

      • pinRequired?:

    • walletId <string> optional

    • token: <object> - The user's token of wepin. including:

      • accessToken: <string> - The access token.

      • refreshToken: <string> - The refresh token.

Example

const userInfo = await wepinWidget.register();

getAccounts

The getAccounts() method returns user accounts. It is recommended to use getAccounts() method without argument to get all user accounts. It can be only usable after widget login.

Parameters

  • options <object>

    • networks: <string[]> optional A list of network names to filter the accounts.

    • withEoa: <boolean> optional If AA accounts are included, whether to include EOA accounts

Return value

  • Promise <WepinAccount[]> - A promise that resolves to an array of the user's accounts.

    • address <string>

    • network <string>

    • contract <string> optional token contract address.

    • isAA <boolean> optional Whether it is aa account or not

Example

const result = await wepinWidget.getAccounts({
  networks: ['ETHEREUM'],
  withEoa: true,
});
  • response

[
  {
    "address": "0x0000001111112222223333334444445555556666",
    "network": "ETHEREUM"
  },
  {
    "address": "0x0000001111112222223333334444445555556666",
    "network": "ETHEREUM",
    "contract": "0x777777888888999999000000111111222222333333"
  },
  {
    "address": "0x4444445555556666000000111111222222333333",
    "network": "ETHEREUM",
    "isAA": true
  }
]

getBalance

It returns the account's balance information. It can be only usable after widget login. It use getBalance() method without argument to get all user accounts.

Parameters

  • accounts <WepinAccount[]> optional

    • network <string>

    • address <string>

    • contract <string> optional token contract address.

    • isAA <boolean> optional Whether it is aa account or not

Return value

  • Promise <WepinAccountBalanceInfo[]>

    • network <string>

    • address <string>

    • symbol <string> - symbol of account

    • balance <string> - balance of account

    • tokens <WepinTokenBalanceInfo[]> - token balance information for account

      • symbol <string> - token symbol

      • balance <string> - token balance

      • contract <string> - token contract address

Example

const result = await wepinWidget.getBalance([
  {
    address: '0x0000001111112222223333334444445555556666',
    network: 'Ethereum',
  },
]);
  • response

[
  {
    "network": "Ethereum",
    "address": "0x0000001111112222223333334444445555556666",
    "symbol": "ETH",
    "balance": "1.1",
    "tokens": [
      {
        "contract": "0x123...213",
        "symbol": "TEST",
        "balance": "10"
      }
    ]
  }
]

getNFTs

The getNFTs() method returns user NFTs. It is recommended to use this method without the networks argument to get all user NFTs. This method can only be used after the widget is logged in.

Parameters

  • options <object>

    • refresh <boolean> - A required parameter to indicate whether to refresh the NFT data.

    • networks <string[]> optional - A list of network names to filter the NFTs.

Return value

  • Promise <WepinNFT[]> - A promise that resolves to an array of the user's NFTs.

    • account <WepinAccount>

      • address <string> - The address of the account associated with the NFT.

      • network <string> - The network associated with the NFT.

      • contract <string> optional The token contract address.

      • isAA <boolean> optional Indicates whether the account is an AA (Account Abstraction) account.

    • contract <WepinNFTContract>

      • name <string> - The name of the NFT contract.

      • address <string> - The contract address of the NFT.

      • scheme <string> - The scheme of the NFT.

      • description <string> optional - A description of the NFT contract.

      • network <string> - The network associated with the NFT contract.

      • externalLink <string> optional - An external link associated with the NFT contract.

      • imageUrl <string> optional - An image URL associated with the NFT contract.

    • name <string> - The name of the NFT.

    • description <string> - A description of the NFT.

    • externalLink <string> - An external link associated with the NFT.

    • imageUrl <string> - An image URL associated with the NFT.

    • contentUrl <string> optional - A URL pointing to the content associated with the NFT.

    • quantity <number> - The quantity of the NFT.

    • contentType <string> - The content type of the NFT.

    • state <number> - The state of the NFT.

Example

const result = await wepinWidget.getNFTs({ refresh: false });
  • response

[
  {
    "account": {
      "address": "0x0000001111112222223333334444445555556666",
      "network": "Ethereum",
      "contract": "0x777777888888999999000000111111222222333333",
      "isAA": true
    },
    "contract": {
      "name": "NFT Collection",
      "address": "0x777777888888999999000000111111222222333333",
      "scheme": "ERC721",
      "description": "An example NFT collection",
      "network": "Ethereum",
      "externalLink": "https://example.com",
      "imageUrl": "https://example.com/image.png"
    },
    "name": "Sample NFT",
    "description": "A sample NFT description",
    "externalLink": "https://example.com/nft",
    "imageUrl": "https://example.com/nft-image.png",
    "contentUrl": "https://example.com/nft-content.png",
    "quantity": 1,
    "contentType": "image/png",
    "state": 0
  }
]

send

It returns the sent transaction id information. It can be only usable after widget login.

Parameters

  • account <Account>

    • network <string>

    • address <string>

    • contract <string> optional token contract address.

  • txData <object> optional

    • toAddress <string>

    • amount <string>

Return value

  • Promise <object>

    • txId <string>

Example

const result = await wepinWidget.send({
  account: {
    address: '0x0000001111112222223333334444445555556666',
    network: 'Ethereum',
  },
  txData: {
    toAddress: '0x9999991111112222223333334444445555556666',
    amount: '0.1',
  },
});
  • response

{
  "txId": "0x76bafd4b700ed959999d08ab76f95d7b6ab2249c0446921c62a6336a70b84f32"
}

receive

The receive method opens the account information page associated with the specified account. This method can only be used after logging into Wepin.

Parameters

  • account <WepinAccount> - Provides the account information for the page that will be opened.

    • network <string> - The network associated with the account.

    • address <string> - The address of the account.

    • contract <string> optional The contract address of the token.

Return value

  • Promise <object> - A promise that resolves to a WepinReceiveResponse object containing the information about the opened account.

    • account <WepinAccount> - The account information of the page that was opened.

      • network <string> - The network associated with the account.

      • address <string> - The address of the account.

      • contract <string> optional The contract address of the token.

Example

// Opening an account page
const result = await wepinWidget.receive({
  address: '0x0000001111112222223333334444445555556666',
  network: 'Ethereum',
});

// Opening a token page
const result = await wepinWidget.receive({
  address: '0x0000001111112222223333334444445555556666',
  network: 'Ethereum',
  contract: '0x9999991111112222223333334444445555556666',
});
  • response

{
  "account": {
    "address": "0x0000001111112222223333334444445555556666",
    "network": "Ethereum",
    "contract": "0x9999991111112222223333334444445555556666"
  }
}

finalize

The finalize() method finalizes the Wepin SDK.

Parameters

  • None

Return value

  • Promise<void>

Example

await wepinWidget.finalize();

WepinError

This section provides descriptions of various error codes that may be encountered while using the Wepin SDK functionalities. Each error code corresponds to a specific issue, and understanding these can help in debugging and handling errors effectively.

Error Code
Description

ApiRequestError

There was an error while making the API request.

InvalidParameters

One or more parameters provided are invalid or missing.

NotInitialized

The Wepin SDK has not been properly initialized.

InvalidAppKey

The Wepin app key is invalid.

InvalidLoginProvider

The login provider specified is not supported or is invalid.

InvalidToken

The token does not exist.

InvalidLoginSession

The login session information does not exist.

UserCancelled

The user has cancelled the operation.

UnknownError

An unknown error has occurred, and the cause is not identified.

NotConnectedInternet

The system is unable to detect an active internet connection.

FailedLogin

The login attempt has failed due to incorrect credentials or other issues.

AlreadyLogout

The user is already logged out, so the logout operation cannot be performed again.

AlreadyInitialized

The Wepin SDK is already initialized.

InvalidEmailDomain

The provided email address's domain is not allowed or recognized by the system.

FailedSendEmail

The system encountered an error while sending an email.

RequiredEmailVerified

Email verification is required to proceed with the requested operation.

IncorrectEmailForm

The provided email address does not match the expected format.

IncorrectPasswordForm

The provided password does not meet the required format or criteria.

NotInitializedNetwork

The network or connection required for the operation has not been properly initialized.

RequiredSignupEmail

The user needs to sign up with an email address to proceed.

FailedEmailVerified

The Wepin SDK encountered an issue while attempting to verify the provided email address.

FailedPasswordStateSetting

Failed to set the password state.

FailedPasswordSetting

The Wepin SDK failed to set the password.

ExistedEmail

The provided email address is already registered in Wepin.

NotActivity

The Context is not an activity.

Last updated

Was this helpful?