# gameos-wof-widget

> GameOS Wheel of Luck widget

Latest version **0.1.5** (published 2024-01-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install gameos-wof-widget
pnpm add gameos-wof-widget
yarn add gameos-wof-widget
bun add gameos-wof-widget
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2024-01-22 |
| First published | 2023-10-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 6 |
| Unpacked size | 8.7 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 288 |
| Maintainers | yuri_gameos |

## Links

- npm: https://www.npmjs.com/package/gameos-wof-widget
- Repository: https://github.com/ionic-team/stencil-component-starter
- Homepage: https://github.com/ionic-team/stencil-component-starter#readme
- Issues: https://github.com/ionic-team/stencil-component-starter/issues
- npm.io page: https://npm.io/package/gameos-wof-widget

## Dependencies (6)

- [axios](https://npm.io/package/axios.md) ^1.5.1
- [animejs](https://npm.io/package/animejs.md) ^3.2.1
- [typescript](https://npm.io/package/typescript.md) ^5.2.2
- [@stencil/core](https://npm.io/package/@stencil/core.md) 4.5.0
- [fontfaceobserver](https://npm.io/package/fontfaceobserver.md) ^2.3.0
- [rollup-plugin-dotenv](https://npm.io/package/rollup-plugin-dotenv.md) ^0.5.0

## Recent versions

- 0.1.5 (latest) — 2024-01-22
- 0.1.4 — 2024-01-09
- 0.1.3 — 2024-01-04
- 0.1.2 — 2023-12-28
- 0.1.1 — 2023-12-26
- 0.1.0 — 2023-12-15
- 0.0.99 — 2023-12-06
- 0.0.98 — 2023-12-06
- 0.0.97 — 2023-12-06
- 0.0.96 — 2023-12-04
- 0.0.95 — 2023-12-04
- 0.0.94 — 2023-12-01
- 0.0.93 — 2023-11-30
- 0.0.92 — 2023-11-23
- 0.0.91 — 2023-11-21
- … 10 more at https://npm.io/package/gameos-wof-widget/versions

## README

# GameOS Wheel of Fortune Widget

## Usage:

Install `gameos-wof-widget`

```js
npm install gameos-wof-widget
```

In your root file add import

```js
import { applyPolyfills, defineCustomElements } from 'gameos-wof-widget/loader';
```

In that file apply polyfills that you imported before

```js
applyPolyfills().then(() => {
  defineCustomElements(window);
});
```

Then you can use the gos-wheel-of-fortune tag where you need it.

### Attributes:

- `token: String`: Ready-to-use long-life token.

To get token and to be aware if current player have available WoF, you should make an API request GET `/wof/available/{player_id}/` and token in headers.

```js
headers: {
 "Authorization": "Bearer cCjIkGfFfPbbBkSI0agLIed0oeiikk"
}
```

**Response example:**

```js
[
  {
    name: 'Binding',
    token:
      'eyJhbGciOiJIUz351iIsInR5cCI6IkpXVCJ9.eyJ3b2Zfc2VjX2lkIjoiMjI3ZmJjMzQtZTkzNS00ODdjLTlhOTItNWRhYzYzYjZhZTE1IiwijxkydG5lcl9pZCI6IlNreVNvZnRUZWNoIiwiZXhwaXJhdGlvbl9kYXRlIjoiMjAyMy0xMS0wMyAxMTo0Mjo0Ny43ODA2MjkrMDA6MDAifQ.MqlpORCdBrJz4WnTtTLIHI2cbVKGKTXkfX_YMSJgZF8',
    type: 'Single',
  },
];
```

**Example of usage in React:**

1. Assume that you already have a button that will open the WoF widget and you should manage the state of WoF visibility. In React you can do it by using useState hook:

```js
const [isWidgetOpen, setIsWidgetOpen] = useState(false);
```

2. You need to create a function to handle on button click.

```js
const onWidgetButtonClick = () => {
  setIsWidgetOpen(true);
};
```

3. Add a check in your code to show or hide WoF dependence of isWidgetOpen state.

```js
{
  isWidgetOpen ? (
    <gos-wheel-of-fortune token="eyJhbGciOiJIUz351iIsInR5cCI6IkpXVCJ9.eyJ3b2Zfc2VjX2lkIjoiMjI3ZmJjMzQtZTkzNS00ODdjLTlhOTItNWRhYzYzYjZhZTE1IiwijxkydG5lcl9pZCI6IlNreVNvZnRUZWNoIiwiZXhwaXJhdGlvbl9kYXRlIjoiMjAyMy0xMS0wMyAxMTo0Mjo0Ny43ODA2MjkrMDA6MDAifQ.MqlpORCdBrJz4WnTtTLIHI2cbVKGKTXkfX_YMSJgZF8"></gos-wheel-of-fortune>
  ) : null;
}
```

4. When a player clicks on “Close” button you will receive the event “closeModal”. You can handle it in useEffect hook.

```js
useEffect(() => {
  document.body.addEventListener('closeModal', () => {
    setIsWidgetOpen(false);
  });
  return () => {
    document.body.removeEventListener('closeModal', () => {
      setIsWidgetOpen(false);
    });
  };
}, []);
```

After the player claims the reward in the WoF widget, you will receive **reward_id** and **player_id** in the API provided as part of the integration process.
In case of receiving error from the API call you will receive the event **closeModal**.

---
_Source: https://npm.io/package/gameos-wof-widget · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
