diff --git a/package.json b/package.json index f3a6ce3..784a99e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zootools", - "version": "0.1.13", + "version": "0.1.14", "description": "ZooTools Decentraland SDK Library", "main": "./dist/index.js", "scripts": { diff --git a/src/entities/Booth/RTBooth.ts b/src/entities/Booth/RTBooth.ts new file mode 100644 index 0000000..4497850 --- /dev/null +++ b/src/entities/Booth/RTBooth.ts @@ -0,0 +1,61 @@ +import { getCurrentRealm } from "@decentraland/EnvironmentAPI"; +import { getUserData } from "@decentraland/Identity"; +import { signedFetch } from "@decentraland/SignedFetch"; +import { AlertSystem } from "src/index"; +import { Booth, IBoothProps } from "./Booth"; + +export class RTBooth extends Entity { + booth: Booth; + constructor( + public props: Partial, + public rewardId: string, + public alertSystem: AlertSystem, + ) { + super() + this.addComponent(new Transform({})); + this.booth = new Booth({ + transformArgs: { position: new Vector3(8, 0, 8) }, + buttonText: `Get Attendance Token`, + onButtonClick: () => { + void executeTask(async () => { + try { + log("POAP", { rewardId }) + alertSystem.new("Attempting to claim POAP... Please wait...") + const userData = await getUserData(); + const realm = await getCurrentRealm(); + if (!userData?.hasConnectedWeb3) { + alertSystem.new(`Login with an Ethereum Wallet to claim this POAP`); + return; + } + const address = userData?.publicKey; + const displayName = userData?.displayName; + const callUrl = `https://api.reward.tools/v1/poap/claim`; + let response = await signedFetch(callUrl, { + headers: { "Content-Type": "application/json" }, + method: "POST", + body: JSON.stringify({ + address, + displayName, + rewardId, + realm, + timezone: new Date().toString(), + }), + }) + let json = JSON.parse(response.text ?? ""); + const { message } = json; + log(json) + alertSystem.new(message) + + } catch (err: any) { + alertSystem.new(err?.message ?? `An error has occcured`) + } + }) + }, + wrapTexturePath: `poap_assets/images/wrap1.png`, + dispenserModelPath: `poap_assets/models/POAP_dispenser.glb`, + buttonModelPath: `poap_assets/models/POAP_button.glb`, + ...props, + }) + this.booth.setParent(this); + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 9116271..91773dc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,6 +25,7 @@ export { Image } from './entities/Image' export { Model, IModelProps } from './entities/Model' export { ModelGroup, IModelGroupProps } from './entities/ModelGroup' export { POAPBooth, IPOAPBoothProps } from './entities/Booth/POAPBooth' +export { RTBooth } from './entities/Booth/RTBooth' export { Sound } from './entities/Sound' export { WearableBooth, IWearableBoothProps } from './entities/Booth/WearableBooth' export { ZooTools_Metronome } from './entities/Metronome/Metronome'