# 메서드

## getStatus

```javascript
await wepinWidget.getStatus();
```

`WepinWidgetSDK`의 Lifecycle 상태 값을 반환합니다.

#### **Parameters**

* None

#### **Return value**

* **Promise\<WepinLifeCycle>**
  * **'not\_initialized'**: `WepinSDK`이 초기화되지 않음
  * **'initializing'** : `WepinSDK`초기화 진행 중
  * **'initialized'**: `WepinSDK`초기화 완료
  * **'before\_login'**: `WepinSDK`은 초기화되었으나 사용자는 로그인 되지 않음
  * **'login'**: 사용자가 로그인 되었고 위핀에도  가입되어있음
  * **'login\_before\_register'**: 사용자가 로그인하였으나 위핀에 가입되지 않음

#### **Example**

```javascript
const status = await wepinWidget.getStatus();
```

## login

`login` 변수는 다양한 인증 방법을 포함한 위핀 로그인 라이브러리로, 사용자가 여러 방식으로 로그인할 수 있도록 합니다. 이메일 및 비밀번호 로그인, OAuth 프로바이더 로그인, ID Token 또는 Access Token을 사용한 로그인 등을 지원합니다. 각 메서드에 대한 자세한 정보는 공식 라이브러리 문서  [Login Library 가이드](/widget-integration/react-native-sdk/login-library.md)에서 확인할 수 있습니다.

#### **Available Methods**

* `loginWithOauthProvider`
* `signUpWithEmailAndPassword`
* `loginWithEmailAndPassword`
* `loginWithIdToken`
* `loginWithAccessToken`
* `getRefreshFirebaseToken`
* `loginWepin`
* `getCurrentWepinUser`
* `logout`
* `getSignForLogin`

이 메서드들은 다양한 로그인 시나리오를 지원하며, 필요에 맞는 적절한 방법을 선택할 수 있습니다.

#### **Example**

```javascript
// 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(
  'example@example.com',
  '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&#x20;

`loginWithUI()` 메서드는 위젯을 사용하여 로그인하는 기능을 제공하며, 로그인된 사용자의 정보를 반환합니다. 사용자가 이미 로그인되어 있는 경우, 위젯을 표시하지 않고 로그인된 사용자의 정보를 바로 반환합니다. 위젯 없이 로그인을 수행하려면, `login` 변수의 `loginWepin()` 메서드를 대신 사용해야 합니다.

{% hint style="warning" %}
OAuth 로그인 기능(예: loginWithUI)을 사용하려면 OAuth 로그인 프로바이더를 설정해야 합니다. 이를 위해 먼저 [위핀 워크스페이스](https://workspace.wepin.io/login)에 OAuth 로그인 프로바이더 정보를 등록해야 합니다. OAuth 프로바이더 설정에 대한 자세한 내용은 [소셜 로그인 인증 프로바이더 문서](/login/social-login-auth-provider.md)를 참고하세요.
{% endhint %}

#### **Parameters**

* `providers` <{provider: string, clientId: string}\[]> - 위젯을 구성할 로그인 프로바이더들의 목록입니다. 빈 목록이 제공되면 이메일 로그인 기능만 사용할 수 있습니다.
  * `provider` \<string> -OAuth 로그인 프로바이더(예: 'google', 'naver', 'discord', 'apple')
  * `clientId` \<string> - OAuth 로그인 프로바이더의 클라이언트 ID입니다.
* `email` \<string> **optional** - 위젯에서 로그인할 때 지정된 이메일 주소로 로그인할 수 있도록 합니다.

#### **Return value**

* Promise\<WepinUser>
  * `status` <'success'|'fail'>
  * `userInfo` \<object> **optional**
    * `userId` \<string> - Wepin 사용자 ID
    * `email` \<string> - 위핀에 로그인된 사용자의 이메일 주소
    * `provider` - 로그인 프로바이더 <'google'|'apple'|'naver'|'discord'|'email'|'external\_token'>
    * `use2FA` \<boolean> - 사용자 지갑에 2FA가 활성화되어 있는지 여부
  * `userStatus`: \<object> - 사용자의 로그인 상태
    * `loginStatus`: <'complete' | 'pinRequired' | 'registerRequired'> - 사용자의 loginStatus 값이 'complete'가 아닌 경우, 위핀에 register 해야 합니다.
    * `pinRequired` **optional :** 사용자 PIN 번호 필요 여부&#x20;
  * `walletId` \<string> **optional :** 사용자의 지갑 ID
  * `token`: \<object> - 사용자의 Wepin  토큰 정보
    * `accessToken`: \<string> - Wepin Access token.
    * `refreshToken`: \<string> - Wepin Refresh token.

#### **Exception**

* [WepinError](#wepinerror)

**Example**

```javascript
// 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([], 'abc@abc.com');
```

* response

```javascript
{
  "status": "success",
  "userInfo": {
    "userId": "120349034824234234",
    "email": "abc@gmail.com",
    "provider": "google",
    "use2FA": true
  },
  "userStatus": {
    "loginStatus": "complete",
    "pinRequired": false
  },
  "walletId": "abcdsfsf123",
  "token": {
    "accessToken": "",
    "refreshToken": ""
  }
}
```

## openWidget

위젯 창을 열어줍니다. 사용자가 로그인되어 있지 않으면 위젯 창이 열리지 않으므로, `openWidget`을 호출하기 전에 반드시 사용자가 위핀에 로그인되어 있어야 합니다. 로그인하려면 `loginWithUI` 매서드 또는 `login` 변수의 `loginWepin` 메서드를 사용해야 합니다.

#### **Parameters**

* None

#### **Return value**

* Promise \<boolean>

#### **Example**

```javascript
await wepinWidget.openWidget();
```

## closeWidget

위젯 창을 닫습니다. 창을 닫아도 로그아웃되지 않습니다.

#### **Parameters**

* None

#### **Return value**

* Promise \<boolean>

#### **Example**

```javascript
await wepinWidget.closeWidget();
```

## register

```dart
await wepinSDK.register(BuildContext context)
```

사용자를 위에 등록합니다. 가입 및 로그인 후 위핀 위젯의 등록 페이지가 열리며, 위핀 서비스에 등록(지갑 생성 및 계정 생성)을 진행합니다. 이 기능은 `WepinSDK`의 `WepinLifeCycle`이 `loginBeforeRegister` 상태일 때만 사용할 수 있습니다. `loginWithUI` 매서드 또는 `login` 변수의 `loginWepin` 메서드를 호출한 후, `userStatus`의 `loginStatus` 값이 'complete'가 아니면 이 메서드를 호출해야 합니다.

#### **Parameters**

* None

#### **Return value**

* Promise\<WepinUser>
  * `status` <'success'|'fail'>
  * `userInfo` \<object> **optional**
    * `userId` \<string> - Wepin 사용자 ID
    * `email` \<string> - 위핀에 로그인된 사용자의 이메일 주소
    * `provider` - 로그인 프로바이더 <'google'|'apple'|'naver'|'discord'|'email'|'external\_token'>
    * `use2FA` \<boolean> - 사용자 지갑에 2FA가 활성화되어 있는지 여부
  * `userStatus`: \<object> - 사용자의 로그인 상태
    * `loginStatus`: <'complete' | 'pinRequired' | 'registerRequired'> - 사용자의 loginStatus 값이 'complete'가 아닌 경우, 위핀에 register 해야 합니다.
    * `pinRequired` **optional :** 사용자 PIN 번호 필요 여부&#x20;
  * `walletId` \<string> **optional :** 사용자의 지갑 ID
  * `token`: \<object> - 사용자의 Wepin  토큰 정보
    * `accessToken`: \<string> - Wepin Access token.
    * `refreshToken`: \<string> - Wepin Refresh token.

#### **Example**

```javascript
const userInfo = await wepinWidget.register();
```

## getAccounts

앱에서 사용 가능한 사용자의 계정 정보(네트워크와 주소)를 반환합니다. 이 기능은 위핀에 로그인한 후에만 사용할 수 있습니다. 파라미터가 없는 경우에는 사용자의 모든 계정 정보가 반환됩니다.

#### **Parameters**

* `options` \<object>
  * `networks`: \<string\[]> **optional** - 반환받고자 하는 계정의 네트워크입니다. 네트워크로 지원하는 블록체인 목록은 아래 지원 블록체인 페이지에서 확인 가능합니다.
  * `withEoa`: \<boolean> **optional** - AA 계정이 있는 경우, EOA 계정도 포함하여 반환할지 여부를 지정합니다.

#### **Return value**

* Promise \<WepinAccount\[]> - A promise that resolves to an array of the user's accounts.
  * `address` \<string> - 사용자 계정의 주소
  * `network` \<string> - 사용자 계정의 네트워크 종류
  * `contract` \<string> **optional** - 토큰 Contract 주소
  * `isAA` \<boolean> **optional** - AA 계정인지 여부

#### **Example**

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

* response

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

## getBalance

정의 잔액(수량) 정보를 반환합니다. 이 기능은 위핀에 로그인한 후에만 사용할 수 있습니다.\
`accounts` 파라미터가 없는 경우에는 사용자의 모든 계정의 잔액이 반환됩니다.

#### **Parameters**

* `accounts` \<WepinAccount\[]> **optional**
  * `network` \<string> - 잔액을 조회할 사용자 계정의 네트워크 종류
  * `address` \<string> - 잔액을 조회할 사용자 계정의 주소
  * `contract` \<string> **optional** - 토큰 Contract 주소
  * `isAA` \<boolean> **optional** - AA 계정인지 여부

#### **Return value**

* Promise \<WepinAccountBalanceInfo\[]>
  * `network` \<string> - 사용자 계정의 네트워크 종류
  * `address` \<string> - 사용자 계정의 주소
  * `symbol` \<string> - 네트워크 심볼
  * `balance` \<string> -보유하고 있는 네트워크 코인의 수량
  * `tokens` \<WepinTokenBalanceInfo\[]> - 계정의 토큰 잔액 정보
    * `symbol` \<string> - 토큰 심볼
    * `balance` \<string> - 보유하고 있는 토큰의 수량
    * `contract` \<string> - 토큰 Contract 주소

#### **Example**

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

* response

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

## getNFTs

사용자의 NFT를 반환합니다. 이 기능은 위핀에 로그인한 후에만 사용할 수 있습니다. \
`networks`파라미터가 없는 경우에는 사용자의 모든 NFT 정보가 반환됩니다.

#### **Parameters**

* `options` \<object>
  * `refresh` \<boolean> - NFT 데이터를 새로 조회할지 여부
  * `networks` \<string\[]> **optional** - NFT를 필터링할 네트워크 이름 목록

#### **Return value**

* Promise \<WepinNFT\[]> - A promise that resolves to an array of the user's NFTs.
  * `account` \<WepinAccount>
    * `address` \<string> - 사용자 계정의 주소
    * `network` \<string> - 사용자 계정의 네트워크 종류
    * `contract` \<string> **optional** - 토큰의 Contract 주소
    * `isAA` \<boolean> **optional** - AA 계정인지 여부
  * `contract` \<WepinNFTContract>
    * `name` \<string> - NFT Contract 이름
    * `address` \<string> - NFT Contract 주소
    * `scheme` \<string> - NFT의 스킴
    * `description` \<string> **optional** - NFT Contract의 설명
    * `network` \<string> - NFT Contract과 연결된 네트워크
    * `externalLink` \<string> **optional** - NFT Contract와 관련된 외부 링크
    * `imageUrl` \<string> **optional** - NFT Contract와 관련된 이미지 URL
  * `name` \<string> - NFT의 이름
  * `description` \<string> - NFT의 설명
  * `externalLink` \<string> - NFT와 관련된 외부 링크
  * `imageUrl` \<string> - NFT와 관련된 이미지 URL
  * `contentUrl` \<string> **optional** - NFT와 연결된 콘텐츠의 URL
  * `quantity` \<number> - NFT의 수량
  * `contentType` \<string> - NFT의 콘텐츠 유형<'image' | 'video'>
  * `state` \<number> - NFT의 상태

#### **Example**

```javascript
const result = await wepinWidget.getNFTs({ refresh: false });
```

* response

```javascript
[
  {
    "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

위젯을 이용하여 send기능을 수행하고 send 트랜젝션의 ID정보를 반환합니다. 이 기능은 위핀에 로그인한 후에만 사용할 수 있습니다.

#### **Parameters**

* `account` \<Account> - 전송할 사용자의 계정 정보
  * `network` \<string> - 전송할 네트워크 종류
  * `address` \<string> - 전송할 계정의 주소
  * `contract` \<string> **optional** - 토큰의 Contract 주소
* `txData` \<object> **optional**
  * `toAddress` \<string> - 전송 받을 주소
  * `amount` \<string> - 전송할 수량

#### **Return value**

* Promise \<object>
  * `txId` \<string> - send 트랜잭션의 txID

#### **Example**

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

* response

```javascript
{
  "txId": "0x76bafd4b700ed959999d08ab76f95d7b6ab2249c0446921c62a6336a70b84f32"
}
```

## receive

`receive` 메서드는 지정된 계정과 연관된 계정 정보 페이지를 엽니다. 이 메서드는 위핀에 로그인한 후에만 사용할 수 있습니다.

#### **Parameters**

* `account` \<WepinAccount> - 오픈할 페이지에 대한 계정을 제공합니다.
  * `network` \<string> - 계정과 연관된 네트워크
  * `address` \<string> - 계정의 주소
  * `contract` \<string> **optional** - 토큰의 Contract 주소

#### **Return value**

* Promise \<object> - A promise that resolves to a `WepinReceiveResponse` object containing the information about the opened account.
  * `account` \<WepinAccount> - 오픈된 페이지의 계정 정보
    * `network` \<string> - 계정과 연관된 네트워크
    * `address` \<string> - 계정의 주소
    * `contract` \<string> **optional** - 토큰의 Contract 주소

#### **Example**

```javascript
// 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

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

## finalize

WepinSDK 사용을 종료합니다. `WepinLifeCycle`이 `notInitialized` 로 변경됩니다.&#x20;

#### **Parameters**

* None

#### **Return value**

* Promise\<void>

#### **Example**

```javascript
await wepinWidget.finalize();
```

## WepinError

이 섹션에서는 Wepin SDK 기능을 사용하는 동안 발생할 수 있는 다양한 오류 코드에 대한 설명을 제공합니다.\
각 오류 코드는 특정 문제에 대응하며, 이를 이해하면 디버깅 및 오류 처리를 보다 효과적으로 수행할 수 있습니다.

| 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.                                                           |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wepin.io/widget-integration/react-native-sdk/widget/methods.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
