Skip to content

Commit

Permalink
Simplifying interface (#63)
Browse files Browse the repository at this point in the history
* Renames variables

* Makes editionInfo.totalMinted a number instead of a function

* Update .changeset/dirty-owls-rescue.md

Co-authored-by: Pablo Sáez <pablosaez1995@gmail.com>

* Update .changeset/dirty-owls-rescue.md

Co-authored-by: Pablo Sáez <pablosaez1995@gmail.com>

Co-authored-by: Pablo Sáez <pablosaez1995@gmail.com>
  • Loading branch information
gigamesh and PabloSzx authored Sep 9, 2022
1 parent cc36fe6 commit 8f00721
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 41 deletions.
7 changes: 7 additions & 0 deletions .changeset/dirty-owls-rescue.md
Original file line number Diff line number Diff line change
@@ -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`
26 changes: 11 additions & 15 deletions packages/sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ export function SoundClient({
activeMintSchedules,
eligibleQuantity,
mint,
createEditionWithMintSchedules,
soundInfo,
createEdition,
editionInfo,
expectedEditionAddress,
soundNumSold,
}

// If the contract address is a SoundEdition contract
Expand Down Expand Up @@ -264,7 +263,7 @@ export function SoundClient({
}
}

async function createEditionWithMintSchedules({
async function createEdition({
editionConfig,
mintConfigs,
salt: customSalt,
Expand Down Expand Up @@ -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 })),
}
}
Expand Down
28 changes: 2 additions & 26 deletions packages/sdk/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
)
Expand All @@ -629,7 +605,7 @@ describe('mint', () => {
})
})

describe('createEditionWithMintSchedules', () => {
describe('createEdition', () => {
beforeEach(() => {
client = SoundClient({ signer: artistWallet, apiKey: '123', soundCreatorAddress: soundCreator.address })
})
Expand Down Expand Up @@ -702,7 +678,7 @@ describe('createEditionWithMintSchedules', () => {
/**
* Create sound edition and mint schedules.
*/
await client.createEditionWithMintSchedules({
await client.createEdition({
editionConfig,
mintConfigs,
salt: customSalt,
Expand Down

0 comments on commit 8f00721

Please sign in to comment.