Skip to content

Commit

Permalink
Merge pull request #290 from storyprotocol/dev_v1.1
Browse files Browse the repository at this point in the history
Bump up react-sdk to 1.1.0-stable (#289)
  • Loading branch information
bonnie57 authored Oct 15, 2024
2 parents f52ae08 + 6fcfb9c commit f8d3752
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 15 deletions.
5 changes: 3 additions & 2 deletions packages/react-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@story-protocol/react-sdk",
"version": "0.0.2",
"version": "1.1.0-stable",
"description": "The Story Protocol React SDK",
"main": "dist/story-protocol-react-sdk.cjs.js",
"module": "dist/story-protocol-react-sdk.esm.js",
Expand All @@ -14,6 +14,7 @@
"scripts": {
"generate": "node ./generator/index.js",
"build": "pnpm run fix && preconstruct build",
"test:integration": "jest -i",
"fix": "pnpm run format:fix && pnpm run lint:fix",
"format": "prettier --check .",
"format:fix": "prettier --write .",
Expand Down Expand Up @@ -62,7 +63,7 @@
},
"license": "MIT",
"dependencies": {
"@story-protocol/core-sdk": "1.0.0-rc.22",
"@story-protocol/core-sdk": "1.1.0-stable",
"react": "^18.3.1",
"viem": "^2.8.12"
},
Expand Down
4 changes: 3 additions & 1 deletion packages/react-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type {
IPAccountExecuteWithSigRequest,
IPAccountExecuteWithSigResponse,
IpAccountStateResponse,
TokenResponse,
GenerateCreatorMetadataParam,
IpCreator,
GenerateIpMetadataParam,
Expand All @@ -41,8 +42,9 @@ export type {
RegisterIpAndMakeDerivativeRequest,
RegisterIpAndMakeDerivativeResponse,
MintAndRegisterIpAndMakeDerivativeRequest,
RegisterNonComSocialRemixingPILRequest,
RegisterPILTermsRequest,
RegisterPILResponse,
RegisterNonComSocialRemixingPILRequest,
RegisterCommercialUsePILRequest,
RegisterCommercialRemixPILRequest,
AttachLicenseTermsRequest,
Expand Down
20 changes: 18 additions & 2 deletions packages/react-sdk/src/resources/useIpAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
IPAccountExecuteWithSigRequest,
IPAccountExecuteWithSigResponse,
IpAccountStateResponse,
TokenResponse,
} from "@story-protocol/core-sdk";
import { Address } from "viem";
import { useState } from "react";

import { useStoryContext } from "../StoryProtocolContext";
Expand All @@ -16,11 +18,13 @@ const useIpAccount = () => {
execute: false,
executeWithSig: false,
getIpAccountNonce: false,
getToken: false,
});
const [errors, setErrors] = useState<Record<string, string | null>>({
execute: null,
executeWithSig: null,
getIpAccountNonce: null,
getToken: null,
});

/** Executes a transaction from the IP Account.
Expand Down Expand Up @@ -67,10 +71,10 @@ const useIpAccount = () => {

/** Returns the IPAccount&#39;s internal nonce for transaction ordering.
* @param ipId The IP ID
* @returns The nonce for transaction ordering.
* @returns A Promise that resolves to the IP Account&#39;s nonce.
*/
const getIpAccountNonce = withLoadingErrorHandling<
string,
Address,
IpAccountStateResponse
>(
"getIpAccountNonce",
Expand All @@ -79,12 +83,24 @@ const useIpAccount = () => {
setErrors
);

/**
* Returns the identifier of the non-fungible token which owns the account
* @returns A Promise that resolves to an object containing the chain ID, token contract address, and token ID.
*/
const getToken = withLoadingErrorHandling<Address, TokenResponse>(
"getToken",
client.ipAccount.getToken.bind(client.ipAccount),
setLoadings,
setErrors
);

return {
loadings,
errors,
execute,
executeWithSig,
getIpAccountNonce,
getToken,
};
};
export default useIpAccount;
44 changes: 41 additions & 3 deletions packages/react-sdk/src/resources/useLicense.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
RegisterNonComSocialRemixingPILRequest,
RegisterPILTermsRequest,
RegisterPILResponse,
RegisterNonComSocialRemixingPILRequest,
RegisterCommercialUsePILRequest,
RegisterCommercialRemixPILRequest,
AttachLicenseTermsRequest,
Expand All @@ -18,6 +19,7 @@ import { withLoadingErrorHandling } from "../withLoadingErrorHandling";
const useLicense = () => {
const client = useStoryContext();
const [loadings, setLoadings] = useState<Record<string, boolean>>({
registerPILTerms: false,
registerNonComSocialRemixingPIL: false,
registerCommercialUsePIL: false,
registerCommercialRemixPIL: false,
Expand All @@ -26,6 +28,7 @@ const useLicense = () => {
getLicenseTerms: false,
});
const [errors, setErrors] = useState<Record<string, string | null>>({
registerPILTerms: null,
registerNonComSocialRemixingPIL: null,
registerCommercialUsePIL: null,
registerCommercialRemixPIL: null,
Expand All @@ -34,6 +37,40 @@ const useLicense = () => {
getLicenseTerms: null,
});

/**
* Registers new license terms and return the ID of the newly registered license terms.
* @param request - The request object that contains all data needed to register a license term.
* @param request.transferable Indicates whether the license is transferable or not.
* @param request.royaltyPolicy The address of the royalty policy contract which required to StoryProtocol in advance.
* @param request.mintingFee The fee to be paid when minting a license.
* @param request.expiration The expiration period of the license.
* @param request.commercialUse Indicates whether the work can be used commercially or not.
* @param request.commercialAttribution Whether attribution is required when reproducing the work commercially or not.
* @param request.commercializerChecker Commercializers that are allowed to commercially exploit the work. If zero address, then no restrictions is enforced.
* @param request.commercializerCheckerData The data to be passed to the commercializer checker contract.
* @param request.commercialRevShare Percentage of revenue that must be shared with the licensor.
* @param request.commercialRevCeiling The maximum revenue that can be generated from the commercial use of the work.
* @param request.derivativesAllowed Indicates whether the licensee can create derivatives of his work or not.
* @param request.derivativesAttribution Indicates whether attribution is required for derivatives of the work or not.
* @param request.derivativesApproval Indicates whether the licensor must approve derivatives of the work before they can be linked to the licensor IP ID or not.
* @param request.derivativesReciprocal Indicates whether the licensee must license derivatives of the work under the same terms or not.
* @param request.derivativeRevCeiling The maximum revenue that can be generated from the derivative use of the work.
* @param request.currency The ERC20 token to be used to pay the minting fee. the token must be registered in story protocol.
* @param request.uri The URI of the license terms, which can be used to fetch the offchain license terms.
* @param request.txOptions - [Optional] transaction. This extends `WaitForTransactionReceiptParameters` from the Viem library, excluding the `hash` property.
* @returns A Promise that resolves to an object containing the optional transaction hash, optional transaction encodedTxData and optional license terms Id.
* @emits LicenseTermsRegistered (licenseTermsId, licenseTemplate, licenseTerms);
*/
const registerPILTerms = withLoadingErrorHandling<
RegisterPILTermsRequest,
RegisterPILResponse
>(
"registerPILTerms",
client.license.registerPILTerms.bind(client.license),
setLoadings,
setErrors
);

/**
* Convenient function to register a PIL non commercial social remix license to the registry
* @param request - [Optional] The request object that contains all data needed to register a PIL non commercial social remix license.
Expand All @@ -54,7 +91,7 @@ const useLicense = () => {
/**
* Convenient function to register a PIL commercial use license to the registry.
* @param request - The request object that contains all data needed to register a PIL commercial use license.
* @param request.mintingFee The fee to be paid when minting a license.
* @param request.defaultMintingFee The fee to be paid when minting a license.
* @param request.currency The ERC20 token to be used to pay the minting fee and the token must be registered in story protocol.
* @param request.txOptions - [Optional] transaction. This extends `WaitForTransactionReceiptParameters` from the Viem library, excluding the `hash` property.
* @returns A Promise that resolves to an object containing the optional transaction hash and optional license terms Id.
Expand All @@ -73,7 +110,7 @@ const useLicense = () => {
/**
* Convenient function to register a PIL commercial Remix license to the registry.
* @param request - The request object that contains all data needed to register license.
* @param request.mintingFee The fee to be paid when minting a license.
* @param request.defaultMintingFee The fee to be paid when minting a license.
* @param request.commercialRevShare Percentage of revenue that must be shared with the licensor.
* @param request.currency The ERC20 token to be used to pay the minting fee. the token must be registered in story protocol.
* @param request.txOptions - [Optional] transaction. This extends `WaitForTransactionReceiptParameters` from the Viem library, excluding the `hash` property.
Expand Down Expand Up @@ -159,6 +196,7 @@ const useLicense = () => {
return {
loadings,
errors,
registerPILTerms,
registerNonComSocialRemixingPIL,
registerCommercialUsePIL,
registerCommercialRemixPIL,
Expand Down
4 changes: 2 additions & 2 deletions packages/react-sdk/test/integration/useLicense.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("useLicense Functions", () => {
await act(async () => {
await expect(
licenseHook.registerCommercialUsePIL({
mintingFee: "1",
defaultMintingFee: "1",
currency: mockERC20Address,
txOptions: {
waitForTransaction: true,
Expand All @@ -52,7 +52,7 @@ describe("useLicense Functions", () => {
await act(async () => {
await expect(
licenseHook.registerCommercialRemixPIL({
mintingFee: "1",
defaultMintingFee: "1",
commercialRevShare: 100,
currency: mockERC20Address,
txOptions: {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-sdk/test/integration/useRoyalty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("useRoyalty Functions", () => {
return await act(async () => {
return (
await licenseHook.registerCommercialUsePIL({
mintingFee: "1",
defaultMintingFee: "1",
currency: mockERC20Address,
txOptions: {
waitForTransaction: true,
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f8d3752

Please sign in to comment.