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/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", diff --git a/packages/core-sdk/src/offers/mixin.ts b/packages/core-sdk/src/offers/mixin.ts index 6a55493d4..567a3a7ad 100644 --- a/packages/core-sdk/src/offers/mixin.ts +++ b/packages/core-sdk/src/offers/mixin.ts @@ -21,7 +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 { MetadataMixin } from "../metadata/mixin"; +import { AccountsMixin } from "../accounts/mixin"; export class OfferMixin extends BaseCoreSDK { /* -------------------------------------------------------------------------- */ @@ -361,7 +361,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 +419,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 +427,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,23 +463,28 @@ 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; }; 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: offer.condition.id + condition: offerConditionId } } }); - - const currentCommits = exchanges.length; - return currentCommits; + const [buyer] = buyers ?? []; + return buyer?.exchanges?.length ?? 0; }; const concurrencyLimit = 5; 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: "" }); }