From a2590d461807e69dc550277395ee51bb84ddc439 Mon Sep 17 00:00:00 2001 From: Albert Folch Date: Tue, 21 Nov 2023 10:29:23 +0100 Subject: [PATCH 1/4] fix: typescript compilation warning --- packages/core-sdk/src/offers/mixin.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/core-sdk/src/offers/mixin.ts b/packages/core-sdk/src/offers/mixin.ts index 6a55493d4..49614cb97 100644 --- a/packages/core-sdk/src/offers/mixin.ts +++ b/packages/core-sdk/src/offers/mixin.ts @@ -21,7 +21,6 @@ import { ITokenInfo, TokenInfoManager } from "../utils/tokenInfoManager"; import { batchTasks } from "../utils/promises"; import { ExchangesMixin } from "../exchanges/mixin"; import { EventLogsMixin } from "../event-logs/mixin"; -import { MetadataMixin } from "../metadata/mixin"; export class OfferMixin extends BaseCoreSDK { /* -------------------------------------------------------------------------- */ @@ -361,7 +360,7 @@ export class OfferMixin extends BaseCoreSDK { */ public async getExchangeTokenInfo( exchangeToken: string - ): Promise { + ): Promise { if (this._tokenInfoManager === undefined) { this._tokenInfoManager = new TokenInfoManager( this._chainId, @@ -419,6 +418,7 @@ export class OfferMixin extends BaseCoreSDK { if (!offer?.condition) { return true; } + const offerConditionId = offer.condition.id; const getCanTokenIdBeUsedToCommit = async (): Promise< (tokenId: string) => boolean > => { @@ -426,7 +426,7 @@ export class OfferMixin extends BaseCoreSDK { this as unknown as EventLogsMixin ).getConditionalCommitAuthorizedEventLogs({ conditionalCommitAuthorizedLogsFilter: { - groupId: offer.condition.id, // all offers of the same product have the same condition.id + groupId: offerConditionId, // all offers of the same product have the same condition.id buyerAddress } }); @@ -462,6 +462,9 @@ export class OfferMixin extends BaseCoreSDK { return true; } const log = tokenIdToAvailableCommitsMap.get(tokenId); + if (!log) { + return true; + } return Number(log.maxCommits) - Number(log.commitCount) > 0; }; return canTokenIdBeUsedToCommit; @@ -472,7 +475,7 @@ export class OfferMixin extends BaseCoreSDK { exchangesFilter: { buyer: buyerAddress, offer_: { - condition: offer.condition.id + condition: offerConditionId } } }); From ea367d54b34c88c05af37cc3dee754eb1d442b21 Mon Sep 17 00:00:00 2001 From: Albert Folch Date: Tue, 21 Nov 2023 11:04:41 +0100 Subject: [PATCH 2/4] fix: build --- .../components/Redeem/ExchangeView/DetailView/TokenGated.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/react-kit/src/components/modal/components/Redeem/ExchangeView/DetailView/TokenGated.tsx b/packages/react-kit/src/components/modal/components/Redeem/ExchangeView/DetailView/TokenGated.tsx index 46d6bc0c5..57c849b61 100644 --- a/packages/react-kit/src/components/modal/components/Redeem/ExchangeView/DetailView/TokenGated.tsx +++ b/packages/react-kit/src/components/modal/components/Redeem/ExchangeView/DetailView/TokenGated.tsx @@ -157,10 +157,11 @@ const TokenGated = ({ (async () => { if (condition?.tokenAddress && condition?.tokenType === 0) { try { - const { name, decimals, symbol } = await coreSDK.getExchangeTokenInfo( + const result = await coreSDK.getExchangeTokenInfo( condition.tokenAddress ); - setTokenInfo({ name, decimals: decimals?.toString(), symbol }); + const { name = "", decimals, symbol = "" } = result ?? {}; + setTokenInfo({ name, decimals: decimals?.toString() ?? "", symbol }); } catch (error) { setTokenInfo({ name: "", decimals: "", symbol: "" }); } From dde5521aa20cede9d83ff3dbb897e90ae76340c8 Mon Sep 17 00:00:00 2001 From: Ludovic Levalleux Date: Tue, 21 Nov 2023 11:26:58 +0000 Subject: [PATCH 3/4] try remove packageManager from package.json --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index e65f5736b..d0531bb8e 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,6 @@ "url": "https://github.com/bosonprotocol/core-components/issues" }, "homepage": "https://github.com/bosonprotocol/core-components#readme", - "packageManager": "npm@8.11.0", "devDependencies": { "@graphql-codegen/cli": "^2.6.2", "@graphql-codegen/typescript": "^2.5.1", From b521c05ae50fbeb2d2f1579a0aa4bde910e1db13 Mon Sep 17 00:00:00 2001 From: Albert Folch Date: Tue, 21 Nov 2023 12:59:26 +0100 Subject: [PATCH 4/4] fix: token gate commit --- e2e/tests/core-sdk-funds.test.ts | 2 +- e2e/tests/core-sdk.test.ts | 27 +++++++++++++++++++++++---- packages/core-sdk/src/offers/mixin.ts | 13 ++++++++----- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/e2e/tests/core-sdk-funds.test.ts b/e2e/tests/core-sdk-funds.test.ts index ce281444e..36f0ccc88 100644 --- a/e2e/tests/core-sdk-funds.test.ts +++ b/e2e/tests/core-sdk-funds.test.ts @@ -152,7 +152,7 @@ describe("core-sdk-funds", () => { }); describe("locked funds", () => { - test("completed exchanges should be excluded when coputing the locked funds value", async () => { + test("completed exchanges should be excluded when computing the locked funds value", async () => { const { sellerCoreSDK, buyerCoreSDK, sellerWallet, buyerWallet } = await initSellerAndBuyerSDKs(seedWallet); const sellers = await ensureCreatedSeller(sellerWallet); diff --git a/e2e/tests/core-sdk.test.ts b/e2e/tests/core-sdk.test.ts index 919bad59d..8f1981e5f 100644 --- a/e2e/tests/core-sdk.test.ts +++ b/e2e/tests/core-sdk.test.ts @@ -784,11 +784,12 @@ describe("core-sdk", () => { "ERC721-pertokenid-tokenrange", "ERC1155-peraddress", "ERC1155-pertokenid", - "ERC20" + "ERC20-threshold", + "ERC20-commits" ])( `create an offer with condition on %p and buyer does NOT meet the condition of that token gated`, async (token) => { - const tokenId = Date.now(); + let tokenId = Date.now(); const { sellerCoreSDK, buyerCoreSDK, sellerWallet, buyerWallet } = await initSellerAndBuyerSDKs(seedWallet); @@ -869,7 +870,8 @@ describe("core-sdk", () => { threshold: "3", maxCommits: "1" }; - } else if (token === "ERC20") { + } else if (token === "ERC20-threshold") { + tokenId = 0; await ensureMintedAndAllowedTokens([buyerWallet], "5"); conditionToCreate = { method: EvaluationMethod.Threshold, @@ -881,6 +883,19 @@ describe("core-sdk", () => { threshold: "7000000000000000000", maxCommits: "1" }; + } else if (token === "ERC20-commits") { + tokenId = 0; + await ensureMintedAndAllowedTokens([buyerWallet], "5"); + conditionToCreate = { + method: EvaluationMethod.Threshold, + tokenType: TokenType.FungibleToken, + tokenAddress: MOCK_ERC20_ADDRESS, + gatingType: GatingType.PerAddress, + minTokenId: "0", + maxTokenId: "0", + threshold: "1", + maxCommits: "1" + }; } const createOfferCondTx = await sellerCoreSDK.createOfferWithCondition( @@ -899,7 +914,11 @@ describe("core-sdk", () => { throw new Error(`offerId is not defined ${offerId}`); } if ( - ["ERC721-pertokenid-tokenrange", "ERC1155-pertokenid"].includes(token) + [ + "ERC721-pertokenid-tokenrange", + "ERC1155-pertokenid", + "ERC20-commits" + ].includes(token) ) { // let's use the tokenId to make it fail await ( diff --git a/packages/core-sdk/src/offers/mixin.ts b/packages/core-sdk/src/offers/mixin.ts index 49614cb97..567a3a7ad 100644 --- a/packages/core-sdk/src/offers/mixin.ts +++ b/packages/core-sdk/src/offers/mixin.ts @@ -21,6 +21,7 @@ import { ITokenInfo, TokenInfoManager } from "../utils/tokenInfoManager"; import { batchTasks } from "../utils/promises"; import { ExchangesMixin } from "../exchanges/mixin"; import { EventLogsMixin } from "../event-logs/mixin"; +import { AccountsMixin } from "../accounts/mixin"; export class OfferMixin extends BaseCoreSDK { /* -------------------------------------------------------------------------- */ @@ -471,17 +472,19 @@ export class OfferMixin extends BaseCoreSDK { }; const getCurrentCommits = async (): Promise => { - const exchanges = await (this as unknown as ExchangesMixin).getExchanges({ + const buyers = await (this as unknown as AccountsMixin).getBuyers({ + buyersFilter: { + wallet: buyerAddress + }, + includeExchanges: true, exchangesFilter: { - buyer: buyerAddress, offer_: { condition: offerConditionId } } }); - - const currentCommits = exchanges.length; - return currentCommits; + const [buyer] = buyers ?? []; + return buyer?.exchanges?.length ?? 0; }; const concurrencyLimit = 5;