@b3dotfun/sdk 0.0.5-alpha.3 → 0.0.5-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ export declare const useB3EnsName: () => {
2
+ registerEns: (username: string, message: string, hash: string) => Promise<{
3
+ success: boolean;
4
+ error?: string;
5
+ }>;
6
+ getEns: (address: string) => Promise<{
7
+ name: string;
8
+ }>;
9
+ };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useB3EnsName = void 0;
7
+ const bsmnt_1 = __importDefault(require("../../../global-account/bsmnt"));
8
+ const constants_1 = require("../../../shared/constants");
9
+ const js_cookie_1 = __importDefault(require("js-cookie"));
10
+ const react_1 = require("react");
11
+ const useB3EnsName = () => {
12
+ const registerEns = (0, react_1.useCallback)(async (username, message, hash) => {
13
+ if (!bsmnt_1.default.authentication.authenticated) {
14
+ await bsmnt_1.default.authentication.authenticate({
15
+ strategy: "b3-jwt",
16
+ accessToken: js_cookie_1.default.get(constants_1.B3_AUTH_COOKIE_NAME) || ""
17
+ });
18
+ }
19
+ const response = await bsmnt_1.default.service("profiles").registerUsername({
20
+ username,
21
+ message,
22
+ hash
23
+ }, {});
24
+ return response;
25
+ }, [bsmnt_1.default.authentication.authenticated]);
26
+ const getEns = (0, react_1.useCallback)(async (address) => {
27
+ const response = await fetch(`https://ens-gateway.b3.fun/address/${address}`);
28
+ if (!response.ok) {
29
+ throw new Error(`Failed to fetch ENS name: ${response.statusText}`);
30
+ }
31
+ const data = await response.json();
32
+ return data;
33
+ }, []);
34
+ return {
35
+ registerEns,
36
+ getEns
37
+ };
38
+ };
39
+ exports.useB3EnsName = useB3EnsName;
@@ -0,0 +1,9 @@
1
+ export declare const useB3EnsName: () => {
2
+ registerEns: (username: string, message: string, hash: string) => Promise<{
3
+ success: boolean;
4
+ error?: string;
5
+ }>;
6
+ getEns: (address: string) => Promise<{
7
+ name: string;
8
+ }>;
9
+ };
@@ -0,0 +1,32 @@
1
+ import bsmntApp from "../../../global-account/bsmnt.js";
2
+ import { B3_AUTH_COOKIE_NAME } from "../../../shared/constants/index.js";
3
+ import Cookies from "js-cookie";
4
+ import { useCallback } from "react";
5
+ export const useB3EnsName = () => {
6
+ const registerEns = useCallback(async (username, message, hash) => {
7
+ if (!bsmntApp.authentication.authenticated) {
8
+ await bsmntApp.authentication.authenticate({
9
+ strategy: "b3-jwt",
10
+ accessToken: Cookies.get(B3_AUTH_COOKIE_NAME) || ""
11
+ });
12
+ }
13
+ const response = await bsmntApp.service("profiles").registerUsername({
14
+ username,
15
+ message,
16
+ hash
17
+ }, {});
18
+ return response;
19
+ }, [bsmntApp.authentication.authenticated]);
20
+ const getEns = useCallback(async (address) => {
21
+ const response = await fetch(`https://ens-gateway.b3.fun/address/${address}`);
22
+ if (!response.ok) {
23
+ throw new Error(`Failed to fetch ENS name: ${response.statusText}`);
24
+ }
25
+ const data = await response.json();
26
+ return data;
27
+ }, []);
28
+ return {
29
+ registerEns,
30
+ getEns
31
+ };
32
+ };
@@ -0,0 +1,9 @@
1
+ export declare const useB3EnsName: () => {
2
+ registerEns: (username: string, message: string, hash: string) => Promise<{
3
+ success: boolean;
4
+ error?: string;
5
+ }>;
6
+ getEns: (address: string) => Promise<{
7
+ name: string;
8
+ }>;
9
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b3dotfun/sdk",
3
- "version": "0.0.5-alpha.3",
3
+ "version": "0.0.5-alpha.4",
4
4
  "source": "src/index.ts",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "react-native": "./dist/cjs/index.native.js",
@@ -0,0 +1,45 @@
1
+ import bsmntApp from "@b3dotfun/sdk/global-account/bsmnt";
2
+ import { B3_AUTH_COOKIE_NAME } from "@b3dotfun/sdk/shared/constants";
3
+ import Cookies from "js-cookie";
4
+ import { useCallback } from "react";
5
+
6
+ export const useB3EnsName = () => {
7
+ const registerEns = useCallback(
8
+ async (username: string, message: string, hash: string) => {
9
+ if (!bsmntApp.authentication.authenticated) {
10
+ await bsmntApp.authentication.authenticate({
11
+ strategy: "b3-jwt",
12
+ accessToken: Cookies.get(B3_AUTH_COOKIE_NAME) || ""
13
+ });
14
+ }
15
+
16
+ const response = await bsmntApp.service("profiles").registerUsername(
17
+ {
18
+ username,
19
+ message,
20
+ hash
21
+ },
22
+ {}
23
+ );
24
+
25
+ return response;
26
+ },
27
+ [bsmntApp.authentication.authenticated]
28
+ );
29
+
30
+ const getEns = useCallback(async (address: string) => {
31
+ const response = await fetch(`https://ens-gateway.b3.fun/address/${address}`);
32
+
33
+ if (!response.ok) {
34
+ throw new Error(`Failed to fetch ENS name: ${response.statusText}`);
35
+ }
36
+
37
+ const data = await response.json();
38
+ return data as { name: string };
39
+ }, []);
40
+
41
+ return {
42
+ registerEns,
43
+ getEns
44
+ };
45
+ };