@b3dotfun/sdk 0.0.5-alpha.2 → 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.
- package/dist/cjs/global-account/react/hooks/useB3EnsName.d.ts +9 -0
- package/dist/cjs/global-account/react/hooks/useB3EnsName.js +39 -0
- package/dist/esm/global-account/react/hooks/useB3EnsName.d.ts +9 -0
- package/dist/esm/global-account/react/hooks/useB3EnsName.js +32 -0
- package/dist/types/global-account/react/hooks/useB3EnsName.d.ts +9 -0
- package/package.json +1 -1
- package/src/anyspend/README.md +12 -71
- package/src/global-account/react/hooks/useB3EnsName.ts +45 -0
|
@@ -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,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
|
+
};
|
package/package.json
CHANGED
package/src/anyspend/README.md
CHANGED
|
@@ -25,9 +25,8 @@ AnySpend handles the complexity of cross-chain operations, gas management, and p
|
|
|
25
25
|
|
|
26
26
|
### Prerequisites
|
|
27
27
|
|
|
28
|
-
- Node.js
|
|
28
|
+
- Node.js v20.15.0+
|
|
29
29
|
- React 18/19
|
|
30
|
-
- B3 Global Accounts integration (for authentication)
|
|
31
30
|
|
|
32
31
|
### Installation
|
|
33
32
|
|
|
@@ -40,16 +39,11 @@ pnpm add @b3dotfun/sdk
|
|
|
40
39
|
### Basic Setup
|
|
41
40
|
|
|
42
41
|
```tsx
|
|
43
|
-
import { B3Provider } from "@b3dotfun/sdk/global-account/react";
|
|
44
42
|
import { AnySpendProvider } from "@b3dotfun/sdk/anyspend/react";
|
|
45
43
|
import "@b3dotfun/sdk/index.css";
|
|
46
44
|
|
|
47
45
|
function App() {
|
|
48
|
-
return
|
|
49
|
-
<B3Provider environment="production" theme="light">
|
|
50
|
-
<AnySpendProvider>{/* Your app components */}</AnySpendProvider>
|
|
51
|
-
</B3Provider>
|
|
52
|
-
);
|
|
46
|
+
return <AnySpendProvider>{/* Your app components */}</AnySpendProvider>;
|
|
53
47
|
}
|
|
54
48
|
```
|
|
55
49
|
|
|
@@ -88,31 +82,6 @@ function NFTMinting() {
|
|
|
88
82
|
}
|
|
89
83
|
```
|
|
90
84
|
|
|
91
|
-
## 🔐 Authentication
|
|
92
|
-
|
|
93
|
-
AnySpend requires B3 Global Accounts for user authentication. Users must be signed in before they can create orders.
|
|
94
|
-
|
|
95
|
-
```tsx
|
|
96
|
-
import { SignInWithB3, useB3 } from "@b3dotfun/sdk/global-account/react";
|
|
97
|
-
|
|
98
|
-
function AuthenticatedAnySpend() {
|
|
99
|
-
const { account, isAuthenticated } = useB3();
|
|
100
|
-
|
|
101
|
-
if (!isAuthenticated) {
|
|
102
|
-
return (
|
|
103
|
-
<SignInWithB3
|
|
104
|
-
chain={{ id: 8333, name: "B3" /* ... */ }}
|
|
105
|
-
partnerId="your-partner-id"
|
|
106
|
-
sessionKeyAddress="0x..."
|
|
107
|
-
onLoginSuccess={account => console.log("Authenticated!", account)}
|
|
108
|
-
/>
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return <AnySpendNFTButton nftContract={nftContract} recipientAddress={account.address} />;
|
|
113
|
-
}
|
|
114
|
-
```
|
|
115
|
-
|
|
116
85
|
## 📚 API Reference
|
|
117
86
|
|
|
118
87
|
### Components
|
|
@@ -338,9 +307,6 @@ const order = await anyspendService.createOrder({
|
|
|
338
307
|
```bash
|
|
339
308
|
# Optional: Custom AnySpend API endpoints
|
|
340
309
|
NEXT_PUBLIC_ANYSPEND_BASE_URL=https://your-custom-anyspend-api.com
|
|
341
|
-
|
|
342
|
-
# Required for B3 Global Accounts
|
|
343
|
-
NEXT_PUBLIC_GLOBAL_ACCOUNTS_PARTNER_ID=your-partner-id
|
|
344
310
|
```
|
|
345
311
|
|
|
346
312
|
### Network Configuration
|
|
@@ -484,13 +450,12 @@ enum OrderStatus {
|
|
|
484
450
|
|
|
485
451
|
### Common Error Codes
|
|
486
452
|
|
|
487
|
-
| Error Code
|
|
488
|
-
|
|
|
489
|
-
| `SLIPPAGE`
|
|
490
|
-
| `INSUFFICIENT_BALANCE`
|
|
491
|
-
| `NETWORK_ERROR`
|
|
492
|
-
| `QUOTE_EXPIRED`
|
|
493
|
-
| `AUTHENTICATION_REQUIRED` | User not signed in | Prompt user to authenticate |
|
|
453
|
+
| Error Code | Description | Recovery Strategy |
|
|
454
|
+
| ---------------------- | --------------------------------- | ------------------------------------ |
|
|
455
|
+
| `SLIPPAGE` | Price movement exceeded tolerance | Retry with higher slippage tolerance |
|
|
456
|
+
| `INSUFFICIENT_BALANCE` | User doesn't have enough tokens | Request user to add funds |
|
|
457
|
+
| `NETWORK_ERROR` | RPC or network issues | Retry after a delay |
|
|
458
|
+
| `QUOTE_EXPIRED` | Price quote is no longer valid | Get a fresh quote |
|
|
494
459
|
|
|
495
460
|
### Error Handling Best Practices
|
|
496
461
|
|
|
@@ -607,18 +572,6 @@ Check that:
|
|
|
607
572
|
Orders will auto-refund after 30 minutes if no deposit is detected.
|
|
608
573
|
```
|
|
609
574
|
|
|
610
|
-
**Q: "Authentication required" error**
|
|
611
|
-
|
|
612
|
-
```
|
|
613
|
-
A: User needs to sign in with B3 Global Accounts first:
|
|
614
|
-
|
|
615
|
-
<SignInWithB3
|
|
616
|
-
chain={{ id: 8333, name: "B3" }}
|
|
617
|
-
partnerId="your-partner-id"
|
|
618
|
-
sessionKeyAddress="0x..."
|
|
619
|
-
/>
|
|
620
|
-
```
|
|
621
|
-
|
|
622
575
|
**Q: React Native build issues**
|
|
623
576
|
|
|
624
577
|
```
|
|
@@ -649,8 +602,8 @@ const quote = await anyspendService.getQuote(true, quoteRequest);
|
|
|
649
602
|
### Support Channels
|
|
650
603
|
|
|
651
604
|
- **Documentation**: [https://docs.b3.fun](https://docs.b3.fun)
|
|
652
|
-
- **GitHub Issues**: [https://github.com/b3-fun](https://github.com/b3-fun)
|
|
653
|
-
- **Discord**: [https://discord.gg/
|
|
605
|
+
- **GitHub Issues**: [https://github.com/b3-fun/b3/issues](https://github.com/b3-fun/b3/issues)
|
|
606
|
+
- **Discord**: [https://discord.gg/b3dotfun](https://discord.gg/b3dotfun)
|
|
654
607
|
|
|
655
608
|
## 🤝 Contributing
|
|
656
609
|
|
|
@@ -668,8 +621,8 @@ We welcome contributions! Here's how to get started:
|
|
|
668
621
|
|
|
669
622
|
```bash
|
|
670
623
|
# Clone the repo
|
|
671
|
-
git clone https://github.com/b3-fun/b3
|
|
672
|
-
cd b3
|
|
624
|
+
git clone https://github.com/b3-fun/b3.git
|
|
625
|
+
cd b3
|
|
673
626
|
|
|
674
627
|
# Install dependencies
|
|
675
628
|
pnpm install
|
|
@@ -679,16 +632,4 @@ pnpm dev
|
|
|
679
632
|
|
|
680
633
|
# Build the SDK
|
|
681
634
|
pnpm sdk:build
|
|
682
|
-
|
|
683
|
-
# Test in example apps
|
|
684
|
-
cd apps/login-minimal-example
|
|
685
|
-
pnpm dev
|
|
686
635
|
```
|
|
687
|
-
|
|
688
|
-
## 📄 License
|
|
689
|
-
|
|
690
|
-
This project is licensed under the MIT License. See the [LICENSE](../../../LICENSE) file for details.
|
|
691
|
-
|
|
692
|
-
---
|
|
693
|
-
|
|
694
|
-
**Ready to get started?** Check out our [Quick Start Guide](https://docs.b3.fun/anyspend/quickstart) or explore the [example applications](../../../apps/) in this repository.
|
|
@@ -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
|
+
};
|