From 8f007212ba66607fe0d7b01abff7755ff7a6a196 Mon Sep 17 00:00:00 2001 From: Matt Masurka Date: Fri, 9 Sep 2022 16:02:17 -0700 Subject: [PATCH] Simplifying interface (#63) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Renames variables * Makes editionInfo.totalMinted a number instead of a function * Update .changeset/dirty-owls-rescue.md Co-authored-by: Pablo Sáez * Update .changeset/dirty-owls-rescue.md Co-authored-by: Pablo Sáez Co-authored-by: Pablo Sáez --- .changeset/dirty-owls-rescue.md | 7 +++++++ packages/sdk/src/client.ts | 26 +++++++++++--------------- packages/sdk/test/client.test.ts | 28 ++-------------------------- 3 files changed, 20 insertions(+), 41 deletions(-) create mode 100644 .changeset/dirty-owls-rescue.md diff --git a/.changeset/dirty-owls-rescue.md b/.changeset/dirty-owls-rescue.md new file mode 100644 index 00000000..b627d63e --- /dev/null +++ b/.changeset/dirty-owls-rescue.md @@ -0,0 +1,7 @@ +--- +'@soundxyz/sdk': patch +--- + +- [BREAKING] Rename createEditionWithMintSchedules to createEdition +- [BREAKING] Rename soundInfo to editionInfo +- [BREAKING] Removes client `soundNumSold`, and renames `editionInfo.numSold` to `totalMinted` diff --git a/packages/sdk/src/client.ts b/packages/sdk/src/client.ts index 1baac961..cfa2be9b 100644 --- a/packages/sdk/src/client.ts +++ b/packages/sdk/src/client.ts @@ -57,10 +57,9 @@ export function SoundClient({ activeMintSchedules, eligibleQuantity, mint, - createEditionWithMintSchedules, - soundInfo, + createEdition, + editionInfo, expectedEditionAddress, - soundNumSold, } // If the contract address is a SoundEdition contract @@ -264,7 +263,7 @@ export function SoundClient({ } } - async function createEditionWithMintSchedules({ + async function createEdition({ editionConfig, mintConfigs, salt: customSalt, @@ -389,26 +388,23 @@ export function SoundClient({ ) } - async function soundNumSold({ contractAddress }: { contractAddress: string }) { - const soundCreatorContract = SoundEditionV1__factory.connect( - contractAddress, + async function editionInfo(soundParams: ReleaseInfoQueryVariables) { + const editionContract = SoundEditionV1__factory.connect( + soundParams.contractAddress, (await _requireSignerOrProvider()).signerOrProvider, ) - return (await soundCreatorContract.totalMinted()).toNumber() - } - - async function soundInfo(soundParams: ReleaseInfoQueryVariables) { - const { data, errors } = await client.soundApi.releaseInfo(soundParams) + const [{ data, errors }, totalMintedBigNum] = await Promise.all([ + client.soundApi.releaseInfo(soundParams), + editionContract.totalMinted(), + ]) const release = data?.release if (!release) throw new SoundNotFoundError({ ...soundParams, graphqlErrors: errors }) return { ...release, - numSold: function numSold() { - return soundNumSold({ contractAddress: soundParams.contractAddress }) - }, + totalMinted: totalMintedBigNum.toNumber(), trackAudio: LazyPromise(() => client.soundApi.audioFromTrack({ trackId: release.track.id })), } } diff --git a/packages/sdk/test/client.test.ts b/packages/sdk/test/client.test.ts index afb44794..b30e6a1e 100644 --- a/packages/sdk/test/client.test.ts +++ b/packages/sdk/test/client.test.ts @@ -492,12 +492,6 @@ describe('mint', () => { }) it(`Successfully mints via RangeEditionMinter`, async () => { - expect( - await client.soundNumSold({ - contractAddress: precomputedEditionAddress, - }), - ).to.equal(0) - const quantity = 2 const initialBalance = await SoundEditionV1__factory.connect( precomputedEditionAddress, @@ -510,12 +504,6 @@ describe('mint', () => { buyerWallet.address, ) expect(finalBalance.sub(initialBalance)).to.eq(quantity) - - expect( - await client.soundNumSold({ - contractAddress: precomputedEditionAddress, - }), - ).to.equal(quantity) }) it(`Should throw error if invalid quantity requested`, async () => { @@ -578,12 +566,6 @@ describe('mint', () => { }) it(`Successfully mints via MerkleDropMinter`, async () => { - expect( - await client.soundNumSold({ - contractAddress: precomputedEditionAddress, - }), - ).to.equal(0) - const quantity = 1 const initialBalance = await SoundEditionV1__factory.connect( precomputedEditionAddress, @@ -599,12 +581,6 @@ describe('mint', () => { quantity, }) - expect( - await client.soundNumSold({ - contractAddress: precomputedEditionAddress, - }), - ).to.equal(quantity) - const finalBalance = await SoundEditionV1__factory.connect(precomputedEditionAddress, ethers.provider).balanceOf( buyerWallet.address, ) @@ -629,7 +605,7 @@ describe('mint', () => { }) }) -describe('createEditionWithMintSchedules', () => { +describe('createEdition', () => { beforeEach(() => { client = SoundClient({ signer: artistWallet, apiKey: '123', soundCreatorAddress: soundCreator.address }) }) @@ -702,7 +678,7 @@ describe('createEditionWithMintSchedules', () => { /** * Create sound edition and mint schedules. */ - await client.createEditionWithMintSchedules({ + await client.createEdition({ editionConfig, mintConfigs, salt: customSalt,