@campnetwork/origin 1.0.0-alpha.2 → 1.0.0-alpha.3
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/core.cjs +59 -31
- package/dist/core.d.ts +43 -6
- package/dist/core.esm.d.ts +43 -6
- package/dist/core.esm.js +102 -74
- package/dist/react/index.esm.d.ts +43 -6
- package/dist/react/index.esm.js +330 -92
- package/package.json +1 -1
|
@@ -12,6 +12,7 @@ interface Environment {
|
|
|
12
12
|
CHAIN: any;
|
|
13
13
|
IPNFT_ABI?: any;
|
|
14
14
|
MARKETPLACE_ABI?: any;
|
|
15
|
+
ROYALTY_VAULT_ABI?: any;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
/**
|
|
@@ -81,6 +82,13 @@ declare function updateTerms(this: Origin, tokenId: bigint, newTerms: LicenseTer
|
|
|
81
82
|
*/
|
|
82
83
|
declare function finalizeDelete(this: Origin, tokenId: bigint): Promise<any>;
|
|
83
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Calls the getOrCreateRoyaltyVault method on the IPNFT contract.
|
|
87
|
+
* @param tokenOwner The address of the token owner for whom to get or create the royalty vault.
|
|
88
|
+
* @returns The address of the royalty vault associated with the specified token owner.
|
|
89
|
+
*/
|
|
90
|
+
declare function getOrCreateRoyaltyVault(this: Origin, tokenOwner: Address): Promise<Address>;
|
|
91
|
+
|
|
84
92
|
/**
|
|
85
93
|
* Returns the license terms associated with a specific token ID.
|
|
86
94
|
* @param tokenId The token ID to query.
|
|
@@ -163,6 +171,11 @@ interface OriginUsageReturnType {
|
|
|
163
171
|
teams: Array<any>;
|
|
164
172
|
dataSources: Array<any>;
|
|
165
173
|
}
|
|
174
|
+
interface RoyaltyInfo {
|
|
175
|
+
royaltyVault: Address;
|
|
176
|
+
balance: bigint;
|
|
177
|
+
balanceFormatted: string;
|
|
178
|
+
}
|
|
166
179
|
type CallOptions = {
|
|
167
180
|
value?: bigint;
|
|
168
181
|
gas?: bigint;
|
|
@@ -178,6 +191,7 @@ declare class Origin {
|
|
|
178
191
|
registerIpNFT: typeof registerIpNFT;
|
|
179
192
|
updateTerms: typeof updateTerms;
|
|
180
193
|
finalizeDelete: typeof finalizeDelete;
|
|
194
|
+
getOrCreateRoyaltyVault: typeof getOrCreateRoyaltyVault;
|
|
181
195
|
getTerms: typeof getTerms;
|
|
182
196
|
ownerOf: typeof ownerOf;
|
|
183
197
|
balanceOf: typeof balanceOf;
|
|
@@ -197,14 +211,14 @@ declare class Origin {
|
|
|
197
211
|
constructor(jwt: string, environment: Environment, viemClient?: any);
|
|
198
212
|
getJwt(): string;
|
|
199
213
|
setViemClient(client: any): void;
|
|
200
|
-
uploadFile
|
|
214
|
+
uploadFile(file: File, options?: {
|
|
201
215
|
progressCallback?: (percent: number) => void;
|
|
202
|
-
})
|
|
203
|
-
mintFile
|
|
216
|
+
}): Promise<any>;
|
|
217
|
+
mintFile(file: File, metadata: Record<string, unknown>, license: LicenseTerms, parents?: bigint[], options?: {
|
|
204
218
|
progressCallback?: (percent: number) => void;
|
|
205
|
-
})
|
|
206
|
-
mintSocial
|
|
207
|
-
getOriginUploads
|
|
219
|
+
}): Promise<string | null>;
|
|
220
|
+
mintSocial(source: "spotify" | "twitter" | "tiktok", metadata: Record<string, unknown>, license: LicenseTerms): Promise<string | null>;
|
|
221
|
+
getOriginUploads(): Promise<any[] | null>;
|
|
208
222
|
/**
|
|
209
223
|
* Get the user's Origin stats (multiplier, consent, usage, etc.).
|
|
210
224
|
* @returns {Promise<OriginUsageReturnType>} A promise that resolves with the user's Origin stats.
|
|
@@ -235,6 +249,29 @@ declare class Origin {
|
|
|
235
249
|
*/
|
|
236
250
|
buyAccessSmart(tokenId: bigint): Promise<any>;
|
|
237
251
|
getData(tokenId: bigint): Promise<any>;
|
|
252
|
+
/**
|
|
253
|
+
* Get royalty information for a wallet address, including the royalty vault address and its balance.
|
|
254
|
+
* @param {Address} [owner] - Optional wallet address to check royalties for. If not provided, uses the connected wallet.
|
|
255
|
+
* @returns {Promise<RoyaltyInfo>} A promise that resolves with the royalty vault address and balance information.
|
|
256
|
+
* @throws {Error} Throws an error if no wallet is connected and no owner address is provided.
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* // Get royalties for connected wallet
|
|
260
|
+
* const royalties = await origin.getRoyalties();
|
|
261
|
+
*
|
|
262
|
+
* // Get royalties for specific address
|
|
263
|
+
* const royalties = await origin.getRoyalties("0x1234...");
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
getRoyalties(token?: Address, owner?: Address): Promise<RoyaltyInfo>;
|
|
267
|
+
/**
|
|
268
|
+
* Claim royalties from the royalty vault.
|
|
269
|
+
* @param {Address} [token] - Optional token address to claim royalties in. If not provided, claims in native token.
|
|
270
|
+
* @param {Address} [owner] - Optional wallet address to claim royalties for. If not provided, uses the connected wallet.
|
|
271
|
+
* @returns {Promise<any>} A promise that resolves when the claim transaction is confirmed.
|
|
272
|
+
* @throws {Error} Throws an error if no wallet is connected and no owner address is provided.
|
|
273
|
+
*/
|
|
274
|
+
claimRoyalties(token?: Address, owner?: Address): Promise<any>;
|
|
238
275
|
}
|
|
239
276
|
|
|
240
277
|
declare global {
|
package/dist/react/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import React, { createContext, useState, useContext, useEffect, useLayoutEffect, useRef, useSyncExternalStore } from 'react';
|
|
3
|
-
import { custom, createWalletClient, createPublicClient, http, erc20Abi, getAbiItem, encodeFunctionData, zeroAddress, checksumAddress } from 'viem';
|
|
3
|
+
import { custom, createWalletClient, createPublicClient, http, erc20Abi, getAbiItem, encodeFunctionData, zeroAddress, formatEther, formatUnits, checksumAddress } from 'viem';
|
|
4
4
|
import { toAccount } from 'viem/accounts';
|
|
5
5
|
import { createSiweMessage } from 'viem/siwe';
|
|
6
6
|
import axios from 'axios';
|
|
@@ -2394,6 +2394,116 @@ var marketplaceMainnetAbi = [
|
|
|
2394
2394
|
}
|
|
2395
2395
|
];
|
|
2396
2396
|
|
|
2397
|
+
var royaltyVaultAbi = [
|
|
2398
|
+
{
|
|
2399
|
+
type: "constructor",
|
|
2400
|
+
inputs: [
|
|
2401
|
+
{
|
|
2402
|
+
name: "_owner",
|
|
2403
|
+
type: "address",
|
|
2404
|
+
internalType: "address"
|
|
2405
|
+
}
|
|
2406
|
+
],
|
|
2407
|
+
stateMutability: "nonpayable"
|
|
2408
|
+
},
|
|
2409
|
+
{
|
|
2410
|
+
type: "receive",
|
|
2411
|
+
stateMutability: "payable"
|
|
2412
|
+
},
|
|
2413
|
+
{
|
|
2414
|
+
type: "function",
|
|
2415
|
+
name: "claimRoyalty",
|
|
2416
|
+
inputs: [
|
|
2417
|
+
{
|
|
2418
|
+
name: "token",
|
|
2419
|
+
type: "address",
|
|
2420
|
+
internalType: "address"
|
|
2421
|
+
}
|
|
2422
|
+
],
|
|
2423
|
+
outputs: [
|
|
2424
|
+
],
|
|
2425
|
+
stateMutability: "nonpayable"
|
|
2426
|
+
},
|
|
2427
|
+
{
|
|
2428
|
+
type: "function",
|
|
2429
|
+
name: "owner",
|
|
2430
|
+
inputs: [
|
|
2431
|
+
],
|
|
2432
|
+
outputs: [
|
|
2433
|
+
{
|
|
2434
|
+
name: "",
|
|
2435
|
+
type: "address",
|
|
2436
|
+
internalType: "address"
|
|
2437
|
+
}
|
|
2438
|
+
],
|
|
2439
|
+
stateMutability: "view"
|
|
2440
|
+
},
|
|
2441
|
+
{
|
|
2442
|
+
type: "function",
|
|
2443
|
+
name: "renounceOwnership",
|
|
2444
|
+
inputs: [
|
|
2445
|
+
],
|
|
2446
|
+
outputs: [
|
|
2447
|
+
],
|
|
2448
|
+
stateMutability: "nonpayable"
|
|
2449
|
+
},
|
|
2450
|
+
{
|
|
2451
|
+
type: "function",
|
|
2452
|
+
name: "transferOwnership",
|
|
2453
|
+
inputs: [
|
|
2454
|
+
{
|
|
2455
|
+
name: "newOwner",
|
|
2456
|
+
type: "address",
|
|
2457
|
+
internalType: "address"
|
|
2458
|
+
}
|
|
2459
|
+
],
|
|
2460
|
+
outputs: [
|
|
2461
|
+
],
|
|
2462
|
+
stateMutability: "nonpayable"
|
|
2463
|
+
},
|
|
2464
|
+
{
|
|
2465
|
+
type: "event",
|
|
2466
|
+
name: "OwnershipTransferred",
|
|
2467
|
+
inputs: [
|
|
2468
|
+
{
|
|
2469
|
+
name: "previousOwner",
|
|
2470
|
+
type: "address",
|
|
2471
|
+
indexed: true,
|
|
2472
|
+
internalType: "address"
|
|
2473
|
+
},
|
|
2474
|
+
{
|
|
2475
|
+
name: "newOwner",
|
|
2476
|
+
type: "address",
|
|
2477
|
+
indexed: true,
|
|
2478
|
+
internalType: "address"
|
|
2479
|
+
}
|
|
2480
|
+
],
|
|
2481
|
+
anonymous: false
|
|
2482
|
+
},
|
|
2483
|
+
{
|
|
2484
|
+
type: "error",
|
|
2485
|
+
name: "OwnableInvalidOwner",
|
|
2486
|
+
inputs: [
|
|
2487
|
+
{
|
|
2488
|
+
name: "owner",
|
|
2489
|
+
type: "address",
|
|
2490
|
+
internalType: "address"
|
|
2491
|
+
}
|
|
2492
|
+
]
|
|
2493
|
+
},
|
|
2494
|
+
{
|
|
2495
|
+
type: "error",
|
|
2496
|
+
name: "OwnableUnauthorizedAccount",
|
|
2497
|
+
inputs: [
|
|
2498
|
+
{
|
|
2499
|
+
name: "account",
|
|
2500
|
+
type: "address",
|
|
2501
|
+
internalType: "address"
|
|
2502
|
+
}
|
|
2503
|
+
]
|
|
2504
|
+
}
|
|
2505
|
+
];
|
|
2506
|
+
|
|
2397
2507
|
var constants = {
|
|
2398
2508
|
SIWE_MESSAGE_STATEMENT: "Connect with Camp Network",
|
|
2399
2509
|
AUTH_HUB_BASE_API: "https://wv2h4to5qa.execute-api.us-east-2.amazonaws.com/dev",
|
|
@@ -2435,6 +2545,7 @@ const ENVIRONMENTS = {
|
|
|
2435
2545
|
CHAIN: testnet,
|
|
2436
2546
|
IPNFT_ABI: ipnftMainnetAbi,
|
|
2437
2547
|
MARKETPLACE_ABI: marketplaceMainnetAbi,
|
|
2548
|
+
ROYALTY_VAULT_ABI: royaltyVaultAbi,
|
|
2438
2549
|
},
|
|
2439
2550
|
PRODUCTION: {
|
|
2440
2551
|
NAME: "PRODUCTION",
|
|
@@ -2446,6 +2557,7 @@ const ENVIRONMENTS = {
|
|
|
2446
2557
|
CHAIN: mainnet,
|
|
2447
2558
|
IPNFT_ABI: ipnftMainnetAbi,
|
|
2448
2559
|
MARKETPLACE_ABI: marketplaceMainnetAbi,
|
|
2560
|
+
ROYALTY_VAULT_ABI: royaltyVaultAbi,
|
|
2449
2561
|
},
|
|
2450
2562
|
};
|
|
2451
2563
|
|
|
@@ -2611,6 +2723,15 @@ function finalizeDelete(tokenId) {
|
|
|
2611
2723
|
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "finalizeDelete", [tokenId]);
|
|
2612
2724
|
}
|
|
2613
2725
|
|
|
2726
|
+
/**
|
|
2727
|
+
* Calls the getOrCreateRoyaltyVault method on the IPNFT contract.
|
|
2728
|
+
* @param tokenOwner The address of the token owner for whom to get or create the royalty vault.
|
|
2729
|
+
* @returns The address of the royalty vault associated with the specified token owner.
|
|
2730
|
+
*/
|
|
2731
|
+
function getOrCreateRoyaltyVault(tokenOwner) {
|
|
2732
|
+
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "getOrCreateRoyaltyVault", [tokenOwner]);
|
|
2733
|
+
}
|
|
2734
|
+
|
|
2614
2735
|
/**
|
|
2615
2736
|
* Returns the license terms associated with a specific token ID.
|
|
2616
2737
|
* @param tokenId The token ID to query.
|
|
@@ -2747,7 +2868,7 @@ function approveIfNeeded(_a) {
|
|
|
2747
2868
|
});
|
|
2748
2869
|
}
|
|
2749
2870
|
|
|
2750
|
-
var _Origin_instances, _Origin_generateURL, _Origin_setOriginStatus, _Origin_waitForTxReceipt, _Origin_ensureChainId;
|
|
2871
|
+
var _Origin_instances, _Origin_generateURL, _Origin_setOriginStatus, _Origin_waitForTxReceipt, _Origin_ensureChainId, _Origin_resolveWalletAddress;
|
|
2751
2872
|
/**
|
|
2752
2873
|
* The Origin class
|
|
2753
2874
|
* Handles the upload of files to Origin, as well as querying the user's stats
|
|
@@ -2755,61 +2876,41 @@ var _Origin_instances, _Origin_generateURL, _Origin_setOriginStatus, _Origin_wai
|
|
|
2755
2876
|
class Origin {
|
|
2756
2877
|
constructor(jwt, environment, viemClient) {
|
|
2757
2878
|
_Origin_instances.add(this);
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
status,
|
|
2791
|
-
fileKey: key,
|
|
2792
|
-
}),
|
|
2793
|
-
headers: {
|
|
2794
|
-
Authorization: `Bearer ${this.jwt}`,
|
|
2795
|
-
"Content-Type": "application/json",
|
|
2796
|
-
},
|
|
2797
|
-
});
|
|
2798
|
-
if (!res.ok) {
|
|
2799
|
-
const errorText = yield res.text().catch(() => "Unknown error");
|
|
2800
|
-
throw new Error(`HTTP ${res.status}: ${errorText}`);
|
|
2801
|
-
}
|
|
2802
|
-
return true;
|
|
2803
|
-
}
|
|
2804
|
-
catch (error) {
|
|
2805
|
-
console.error("Failed to update origin status:", error);
|
|
2806
|
-
throw error;
|
|
2807
|
-
}
|
|
2808
|
-
}));
|
|
2809
|
-
this.uploadFile = (file, options) => __awaiter(this, void 0, void 0, function* () {
|
|
2879
|
+
this.jwt = jwt;
|
|
2880
|
+
this.viemClient = viemClient;
|
|
2881
|
+
this.environment = environment;
|
|
2882
|
+
// DataNFT methods
|
|
2883
|
+
this.mintWithSignature = mintWithSignature.bind(this);
|
|
2884
|
+
this.registerIpNFT = registerIpNFT.bind(this);
|
|
2885
|
+
this.updateTerms = updateTerms.bind(this);
|
|
2886
|
+
this.finalizeDelete = finalizeDelete.bind(this);
|
|
2887
|
+
this.getOrCreateRoyaltyVault = getOrCreateRoyaltyVault.bind(this);
|
|
2888
|
+
this.getTerms = getTerms.bind(this);
|
|
2889
|
+
this.ownerOf = ownerOf.bind(this);
|
|
2890
|
+
this.balanceOf = balanceOf.bind(this);
|
|
2891
|
+
this.tokenURI = tokenURI.bind(this);
|
|
2892
|
+
this.dataStatus = dataStatus.bind(this);
|
|
2893
|
+
this.isApprovedForAll = isApprovedForAll.bind(this);
|
|
2894
|
+
this.transferFrom = transferFrom.bind(this);
|
|
2895
|
+
this.safeTransferFrom = safeTransferFrom.bind(this);
|
|
2896
|
+
this.approve = approve.bind(this);
|
|
2897
|
+
this.setApprovalForAll = setApprovalForAll.bind(this);
|
|
2898
|
+
// Marketplace methods
|
|
2899
|
+
this.buyAccess = buyAccess.bind(this);
|
|
2900
|
+
this.hasAccess = hasAccess.bind(this);
|
|
2901
|
+
this.subscriptionExpiry = subscriptionExpiry.bind(this);
|
|
2902
|
+
}
|
|
2903
|
+
getJwt() {
|
|
2904
|
+
return this.jwt;
|
|
2905
|
+
}
|
|
2906
|
+
setViemClient(client) {
|
|
2907
|
+
this.viemClient = client;
|
|
2908
|
+
}
|
|
2909
|
+
uploadFile(file, options) {
|
|
2910
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2810
2911
|
let uploadInfo;
|
|
2811
2912
|
try {
|
|
2812
|
-
uploadInfo = yield __classPrivateFieldGet(this,
|
|
2913
|
+
uploadInfo = yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_generateURL).call(this, file);
|
|
2813
2914
|
}
|
|
2814
2915
|
catch (error) {
|
|
2815
2916
|
console.error("Failed to generate upload URL:", error);
|
|
@@ -2823,7 +2924,7 @@ class Origin {
|
|
|
2823
2924
|
}
|
|
2824
2925
|
catch (error) {
|
|
2825
2926
|
try {
|
|
2826
|
-
yield __classPrivateFieldGet(this,
|
|
2927
|
+
yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_setOriginStatus).call(this, uploadInfo.key, "failed");
|
|
2827
2928
|
}
|
|
2828
2929
|
catch (statusError) {
|
|
2829
2930
|
console.error("Failed to update status to failed:", statusError);
|
|
@@ -2832,14 +2933,16 @@ class Origin {
|
|
|
2832
2933
|
throw new Error(`Failed to upload file: ${errorMessage}`);
|
|
2833
2934
|
}
|
|
2834
2935
|
try {
|
|
2835
|
-
yield __classPrivateFieldGet(this,
|
|
2936
|
+
yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_setOriginStatus).call(this, uploadInfo.key, "success");
|
|
2836
2937
|
}
|
|
2837
2938
|
catch (statusError) {
|
|
2838
2939
|
console.error("Failed to update status to success:", statusError);
|
|
2839
2940
|
}
|
|
2840
2941
|
return uploadInfo;
|
|
2841
2942
|
});
|
|
2842
|
-
|
|
2943
|
+
}
|
|
2944
|
+
mintFile(file, metadata, license, parents, options) {
|
|
2945
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2843
2946
|
if (!this.viemClient) {
|
|
2844
2947
|
throw new Error("WalletClient not connected.");
|
|
2845
2948
|
}
|
|
@@ -2868,7 +2971,9 @@ class Origin {
|
|
|
2868
2971
|
}
|
|
2869
2972
|
return tokenId.toString();
|
|
2870
2973
|
});
|
|
2871
|
-
|
|
2974
|
+
}
|
|
2975
|
+
mintSocial(source, metadata, license) {
|
|
2976
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2872
2977
|
if (!this.viemClient) {
|
|
2873
2978
|
throw new Error("WalletClient not connected.");
|
|
2874
2979
|
}
|
|
@@ -2892,7 +2997,9 @@ class Origin {
|
|
|
2892
2997
|
}
|
|
2893
2998
|
return tokenId.toString();
|
|
2894
2999
|
});
|
|
2895
|
-
|
|
3000
|
+
}
|
|
3001
|
+
getOriginUploads() {
|
|
3002
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2896
3003
|
const res = yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/files`, {
|
|
2897
3004
|
method: "GET",
|
|
2898
3005
|
headers: {
|
|
@@ -2906,34 +3013,6 @@ class Origin {
|
|
|
2906
3013
|
const data = yield res.json();
|
|
2907
3014
|
return data.data;
|
|
2908
3015
|
});
|
|
2909
|
-
this.jwt = jwt;
|
|
2910
|
-
this.viemClient = viemClient;
|
|
2911
|
-
this.environment = environment;
|
|
2912
|
-
// DataNFT methods
|
|
2913
|
-
this.mintWithSignature = mintWithSignature.bind(this);
|
|
2914
|
-
this.registerIpNFT = registerIpNFT.bind(this);
|
|
2915
|
-
this.updateTerms = updateTerms.bind(this);
|
|
2916
|
-
this.finalizeDelete = finalizeDelete.bind(this);
|
|
2917
|
-
this.getTerms = getTerms.bind(this);
|
|
2918
|
-
this.ownerOf = ownerOf.bind(this);
|
|
2919
|
-
this.balanceOf = balanceOf.bind(this);
|
|
2920
|
-
this.tokenURI = tokenURI.bind(this);
|
|
2921
|
-
this.dataStatus = dataStatus.bind(this);
|
|
2922
|
-
this.isApprovedForAll = isApprovedForAll.bind(this);
|
|
2923
|
-
this.transferFrom = transferFrom.bind(this);
|
|
2924
|
-
this.safeTransferFrom = safeTransferFrom.bind(this);
|
|
2925
|
-
this.approve = approve.bind(this);
|
|
2926
|
-
this.setApprovalForAll = setApprovalForAll.bind(this);
|
|
2927
|
-
// Marketplace methods
|
|
2928
|
-
this.buyAccess = buyAccess.bind(this);
|
|
2929
|
-
this.hasAccess = hasAccess.bind(this);
|
|
2930
|
-
this.subscriptionExpiry = subscriptionExpiry.bind(this);
|
|
2931
|
-
}
|
|
2932
|
-
getJwt() {
|
|
2933
|
-
return this.jwt;
|
|
2934
|
-
}
|
|
2935
|
-
setViemClient(client) {
|
|
2936
|
-
this.viemClient = client;
|
|
2937
3016
|
}
|
|
2938
3017
|
/**
|
|
2939
3018
|
* Get the user's Origin stats (multiplier, consent, usage, etc.).
|
|
@@ -3105,8 +3184,138 @@ class Origin {
|
|
|
3105
3184
|
return response.json();
|
|
3106
3185
|
});
|
|
3107
3186
|
}
|
|
3187
|
+
/**
|
|
3188
|
+
* Get royalty information for a wallet address, including the royalty vault address and its balance.
|
|
3189
|
+
* @param {Address} [owner] - Optional wallet address to check royalties for. If not provided, uses the connected wallet.
|
|
3190
|
+
* @returns {Promise<RoyaltyInfo>} A promise that resolves with the royalty vault address and balance information.
|
|
3191
|
+
* @throws {Error} Throws an error if no wallet is connected and no owner address is provided.
|
|
3192
|
+
* @example
|
|
3193
|
+
* ```typescript
|
|
3194
|
+
* // Get royalties for connected wallet
|
|
3195
|
+
* const royalties = await origin.getRoyalties();
|
|
3196
|
+
*
|
|
3197
|
+
* // Get royalties for specific address
|
|
3198
|
+
* const royalties = await origin.getRoyalties("0x1234...");
|
|
3199
|
+
* ```
|
|
3200
|
+
*/
|
|
3201
|
+
getRoyalties(token, owner) {
|
|
3202
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3203
|
+
const walletAddress = yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_resolveWalletAddress).call(this, owner);
|
|
3204
|
+
try {
|
|
3205
|
+
const royaltyVaultAddress = yield this.getOrCreateRoyaltyVault(walletAddress);
|
|
3206
|
+
const publicClient = getPublicClient();
|
|
3207
|
+
let balance;
|
|
3208
|
+
let balanceFormatted;
|
|
3209
|
+
if (!token || token === zeroAddress) {
|
|
3210
|
+
balance = yield publicClient.getBalance({
|
|
3211
|
+
address: royaltyVaultAddress,
|
|
3212
|
+
});
|
|
3213
|
+
balanceFormatted = formatEther(balance);
|
|
3214
|
+
}
|
|
3215
|
+
else {
|
|
3216
|
+
// erc20 (wrapped camp)
|
|
3217
|
+
const erc20Abi = [
|
|
3218
|
+
{
|
|
3219
|
+
inputs: [{ name: "owner", type: "address" }],
|
|
3220
|
+
name: "balanceOf",
|
|
3221
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
3222
|
+
stateMutability: "view",
|
|
3223
|
+
type: "function",
|
|
3224
|
+
},
|
|
3225
|
+
{
|
|
3226
|
+
inputs: [],
|
|
3227
|
+
name: "decimals",
|
|
3228
|
+
outputs: [{ name: "", type: "uint8" }],
|
|
3229
|
+
stateMutability: "view",
|
|
3230
|
+
type: "function",
|
|
3231
|
+
},
|
|
3232
|
+
];
|
|
3233
|
+
balance = yield this.callContractMethod(token, erc20Abi, "balanceOf", [
|
|
3234
|
+
royaltyVaultAddress,
|
|
3235
|
+
]);
|
|
3236
|
+
const decimals = yield this.callContractMethod(token, erc20Abi, "decimals", []);
|
|
3237
|
+
balanceFormatted = formatUnits(balance, decimals);
|
|
3238
|
+
}
|
|
3239
|
+
return {
|
|
3240
|
+
royaltyVault: royaltyVaultAddress,
|
|
3241
|
+
balance,
|
|
3242
|
+
balanceFormatted,
|
|
3243
|
+
};
|
|
3244
|
+
}
|
|
3245
|
+
catch (error) {
|
|
3246
|
+
throw new Error(`Failed to retrieve royalties for address ${walletAddress}: ${error instanceof Error ? error.message : String(error)}`);
|
|
3247
|
+
}
|
|
3248
|
+
});
|
|
3249
|
+
}
|
|
3250
|
+
/**
|
|
3251
|
+
* Claim royalties from the royalty vault.
|
|
3252
|
+
* @param {Address} [token] - Optional token address to claim royalties in. If not provided, claims in native token.
|
|
3253
|
+
* @param {Address} [owner] - Optional wallet address to claim royalties for. If not provided, uses the connected wallet.
|
|
3254
|
+
* @returns {Promise<any>} A promise that resolves when the claim transaction is confirmed.
|
|
3255
|
+
* @throws {Error} Throws an error if no wallet is connected and no owner address is provided.
|
|
3256
|
+
*/
|
|
3257
|
+
claimRoyalties(token, owner) {
|
|
3258
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3259
|
+
const walletAddress = yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_resolveWalletAddress).call(this, owner);
|
|
3260
|
+
const royaltyVaultAddress = yield this.getOrCreateRoyaltyVault(walletAddress);
|
|
3261
|
+
return this.callContractMethod(royaltyVaultAddress, this.environment.ROYALTY_VAULT_ABI, "claimRoyalties", [token !== null && token !== void 0 ? token : zeroAddress], { waitForReceipt: true });
|
|
3262
|
+
});
|
|
3263
|
+
}
|
|
3108
3264
|
}
|
|
3109
|
-
|
|
3265
|
+
_Origin_instances = new WeakSet(), _Origin_generateURL = function _Origin_generateURL(file) {
|
|
3266
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3267
|
+
try {
|
|
3268
|
+
const uploadRes = yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/upload-url`, {
|
|
3269
|
+
method: "POST",
|
|
3270
|
+
body: JSON.stringify({
|
|
3271
|
+
name: file.name,
|
|
3272
|
+
type: file.type,
|
|
3273
|
+
}),
|
|
3274
|
+
headers: {
|
|
3275
|
+
Authorization: `Bearer ${this.jwt}`,
|
|
3276
|
+
"Content-Type": "application/json",
|
|
3277
|
+
},
|
|
3278
|
+
});
|
|
3279
|
+
if (!uploadRes.ok) {
|
|
3280
|
+
throw new Error(`HTTP ${uploadRes.status}: ${uploadRes.statusText}`);
|
|
3281
|
+
}
|
|
3282
|
+
const data = yield uploadRes.json();
|
|
3283
|
+
if (data.isError) {
|
|
3284
|
+
throw new Error(data.message || "Failed to generate upload URL");
|
|
3285
|
+
}
|
|
3286
|
+
return data.data;
|
|
3287
|
+
}
|
|
3288
|
+
catch (error) {
|
|
3289
|
+
console.error("Failed to generate upload URL:", error);
|
|
3290
|
+
throw error;
|
|
3291
|
+
}
|
|
3292
|
+
});
|
|
3293
|
+
}, _Origin_setOriginStatus = function _Origin_setOriginStatus(key, status) {
|
|
3294
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3295
|
+
try {
|
|
3296
|
+
const res = yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/update-status`, {
|
|
3297
|
+
method: "PATCH",
|
|
3298
|
+
body: JSON.stringify({
|
|
3299
|
+
status,
|
|
3300
|
+
fileKey: key,
|
|
3301
|
+
}),
|
|
3302
|
+
headers: {
|
|
3303
|
+
Authorization: `Bearer ${this.jwt}`,
|
|
3304
|
+
"Content-Type": "application/json",
|
|
3305
|
+
},
|
|
3306
|
+
});
|
|
3307
|
+
if (!res.ok) {
|
|
3308
|
+
const errorText = yield res.text().catch(() => "Unknown error");
|
|
3309
|
+
throw new Error(`HTTP ${res.status}: ${errorText}`);
|
|
3310
|
+
}
|
|
3311
|
+
return true;
|
|
3312
|
+
}
|
|
3313
|
+
catch (error) {
|
|
3314
|
+
console.error("Failed to update origin status:", error);
|
|
3315
|
+
throw error;
|
|
3316
|
+
}
|
|
3317
|
+
});
|
|
3318
|
+
}, _Origin_waitForTxReceipt = function _Origin_waitForTxReceipt(txHash) {
|
|
3110
3319
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3111
3320
|
if (!this.viemClient)
|
|
3112
3321
|
throw new Error("WalletClient not connected.");
|
|
@@ -3165,6 +3374,28 @@ _Origin_generateURL = new WeakMap(), _Origin_setOriginStatus = new WeakMap(), _O
|
|
|
3165
3374
|
}
|
|
3166
3375
|
}
|
|
3167
3376
|
});
|
|
3377
|
+
}, _Origin_resolveWalletAddress = function _Origin_resolveWalletAddress(owner) {
|
|
3378
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3379
|
+
if (owner) {
|
|
3380
|
+
return owner;
|
|
3381
|
+
}
|
|
3382
|
+
if (!this.viemClient) {
|
|
3383
|
+
throw new Error("No wallet address provided and no wallet client connected. Please provide an owner address or connect a wallet.");
|
|
3384
|
+
}
|
|
3385
|
+
try {
|
|
3386
|
+
const accounts = yield this.viemClient.request({
|
|
3387
|
+
method: "eth_requestAccounts",
|
|
3388
|
+
params: [],
|
|
3389
|
+
});
|
|
3390
|
+
if (!accounts || accounts.length === 0) {
|
|
3391
|
+
throw new Error("No accounts found in connected wallet.");
|
|
3392
|
+
}
|
|
3393
|
+
return accounts[0];
|
|
3394
|
+
}
|
|
3395
|
+
catch (error) {
|
|
3396
|
+
throw new Error(`Failed to get wallet address: ${error instanceof Error ? error.message : String(error)}`);
|
|
3397
|
+
}
|
|
3398
|
+
});
|
|
3168
3399
|
};
|
|
3169
3400
|
|
|
3170
3401
|
var _Auth_instances, _Auth_triggers, _Auth_ackeeInstance, _Auth_trigger, _Auth_loadAuthStatusFromStorage, _Auth_requestAccount, _Auth_fetchNonce, _Auth_verifySignature, _Auth_createMessage, _Auth_sendAnalyticsEvent;
|
|
@@ -4856,6 +5087,7 @@ const AuthModal = ({ setIsVisible, wcProvider, loading, onlyWagmi, defaultProvid
|
|
|
4856
5087
|
wagmiConnectorClient = useConnectorClient();
|
|
4857
5088
|
wagmiAccount = useAccount();
|
|
4858
5089
|
}
|
|
5090
|
+
const { addToast: toast } = useToast();
|
|
4859
5091
|
if (!auth) {
|
|
4860
5092
|
throw new Error("Auth instance is not available. Make sure to wrap your component with CampProvider.");
|
|
4861
5093
|
}
|
|
@@ -4928,7 +5160,7 @@ const AuthModal = ({ setIsVisible, wcProvider, loading, onlyWagmi, defaultProvid
|
|
|
4928
5160
|
}
|
|
4929
5161
|
};
|
|
4930
5162
|
}, [wcProvider]);
|
|
4931
|
-
const handleConnect = (provider) => {
|
|
5163
|
+
const handleConnect = (provider) => __awaiter(void 0, void 0, void 0, function* () {
|
|
4932
5164
|
var _a, _b;
|
|
4933
5165
|
if (provider) {
|
|
4934
5166
|
let addr = null;
|
|
@@ -4946,8 +5178,14 @@ const AuthModal = ({ setIsVisible, wcProvider, loading, onlyWagmi, defaultProvid
|
|
|
4946
5178
|
((_b = provider === null || provider === void 0 ? void 0 : provider.provider) === null || _b === void 0 ? void 0 : _b.uid) === (customProvider === null || customProvider === void 0 ? void 0 : customProvider.uid)) {
|
|
4947
5179
|
auth.setWalletAddress(customAccount === null || customAccount === void 0 ? void 0 : customAccount.address);
|
|
4948
5180
|
}
|
|
4949
|
-
|
|
4950
|
-
|
|
5181
|
+
try {
|
|
5182
|
+
yield connect();
|
|
5183
|
+
}
|
|
5184
|
+
catch (error) {
|
|
5185
|
+
console.error("Error during connect:", error);
|
|
5186
|
+
toast("Error connecting wallet. Please try again.", "error", 5000);
|
|
5187
|
+
}
|
|
5188
|
+
});
|
|
4951
5189
|
return (React.createElement("div", { className: styles["outer-container"] },
|
|
4952
5190
|
React.createElement("div", { className: `${styles.container} ${styles["linking-container"]}` },
|
|
4953
5191
|
React.createElement(ArrowCorners, { padding: 8, color: "#AAA" }),
|