Skip to content

Commit

Permalink
Mint sets directly form mass mint interface
Browse files Browse the repository at this point in the history
  • Loading branch information
wraitii committed Dec 4, 2023
1 parent 817e329 commit d940056
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 9 deletions.
65 changes: 64 additions & 1 deletion src/components/collections/MassMint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { pushModal } from '../Modals.vue';
import TextModal from '../generic/TextModal.vue';
import RecipientMappingModal from './RecipientMappingModal.vue';
import { getCalls } from './migrate';
import { getBookletAddress } from '@/chain/Collections';
import { hexUuid } from '@/Uuid';
class SetToMint {
filename: string;
Expand Down Expand Up @@ -46,6 +48,12 @@ const assemblyGroupId = computed(() => (collectionData[collection.value] ?? null
const existingItems = ref({});
const loadedItems = (collection: string) => {
const all = Object.keys(existingItems.value[collection] || {});
return all.filter(x => x in bookletDataStore[getCurrentNetwork()]);
}
// Load existing items based on current collection
watchEffect(async () => {
if (collection.value === '')
return;
Expand All @@ -55,6 +63,7 @@ watchEffect(async () => {
}
});
const importFiles = async () => {
let files = [] as File[];
let fileHandles = await showOpenFilePickerPolyfill({ multiple: true });
Expand Down Expand Up @@ -190,6 +199,60 @@ const mintBoxes = async () => {
);
}
const getOfficialSetPreview = async (booklet: string) => {
const bookletImage = fetch(genesisStore.coverItemRoute(booklet) + '?no-cache-please');
const imageBlob = (await (await bookletImage).blob());
const image_base64 = await new Promise(yes => {
const reader = new FileReader() ;
reader.onload = _ => reader.result && yes(reader.result);
reader.readAsDataURL(imageBlob);
});
return image_base64 as string;
}
const mintSets = async () => {
const mapping = await pushModal(RecipientMappingModal, {
initialMapping: loadedItems(collection.value).reduce((acc, val) => {
acc[val] = walletStore.userWalletAddress!;
return acc;
}, {} as Record<string, string>),
}) as Record<string, string>;
const calls = [] as Call[];
for (const booklet in mapping) {
const recipient = mapping[booklet];
const bookletData = bookletDataStore[getCurrentNetwork()][booklet]._data!;
if (!bookletData)
throw new Error(`Booklet ${booklet} not loaded`);
// Mint the booklet
const contract = getBookletAddress(ADDRESSES[getCurrentNetwork()], booklet.split('/')[0]);
calls.push({
contractAddress: contract,
entrypoint: 'mint',
calldata: [
recipient,
bookletData.token_id,
1,
],
});
// Then mint the set
const tokenHint = hexUuid();
const futureTokenId = contractStore.set!.precomputeTokenId(recipient, tokenHint, bookletData.briqs.length, booklet, bookletData);
calls.push(contractStore.set!.prepareAssemble(recipient, tokenHint, bookletData, bookletData.token_id));
// Immediately hint to the backend
await backendManager.storeSet({
chain_id: getCurrentNetwork(),
owner: walletStore.userWalletAddress!,
token_id: futureTokenId,
data: bookletData,
image_base64: await getOfficialSetPreview(booklet),
});
}
console.log('totoro', calls);
await walletStore.sendTransaction(calls);
}
const migrationData = reactive(new Fetchable<{ set_migrations: { old_token_id: string, new_token_id: string }[], calls: Call[] }>());
watchEffect(() => {
Expand Down Expand Up @@ -312,7 +375,7 @@ const mintStuff = async () => {
<Btn @click="loadAll">Load all</Btn>
<Btn @click="deployShapeContracts">Deploy missing shape contract(s)</Btn>
<Btn :disabled="true" @click="mintBoxes">Mint Boxes</Btn>
<Btn :disabled="true" @click="pushModal(RecipientMappingModal)">Mint Booklets</Btn>
<Btn @click="mintSets">Mint Sets</Btn>
<table>
<tr>
<th>Object ID</th>
Expand Down
21 changes: 14 additions & 7 deletions src/components/collections/RecipientMappingModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,36 @@ import Window from '../generic/Window.vue';
defineEmits(['close']);
const recipientMapping = ref({
[walletStore.userWalletAddress || '0x0']: '0x1',
} as Record<string, string>);
// Initial text as props
const props = withDefaults(defineProps<{
initialMapping: Record<string, string>;
}>(), {
initialMapping: () => ({
[walletStore.userWalletAddress || '0x0']: '0x1',
}),
});
const recipientMapping = ref(props.initialMapping);
const recipientMappingText = computed({
get: () => JSON.stringify(recipientMapping.value),
get: () => JSON.stringify(recipientMapping.value, undefined, 4),
set: (v) => recipientMapping.value = JSON.parse(v),
});
const step = ref('JSON' as 'JSON' | 'CONFIRM');
</script>

<template>
<Window>
<Window size="w-full max-w-[80rem]">
<template #title>Recipient mapping</template>
<template v-if="step == 'JSON'">
<textarea v-model="recipientMappingText" class="w-full h-32"/>
<textarea v-model="recipientMappingText" class="w-full min-h-[20rem]"/>
<div class="flex gap-4 justify-end items-center">
<Btn @click="step = 'CONFIRM'">Confirm</Btn>
</div>
</template>
<template v-else>
<p class="w-full h-32 text-xs">{{ JSON.stringify(recipientMapping, null, 4) }}</p>
<p class="w-full h-32 text-xs whitespace-pre">{{ JSON.stringify(recipientMapping, null, 4) }}</p>
<div class="flex gap-4 justify-end items-center">
<Btn secondary @click="step = 'JSON'">Back</Btn>
<Btn @click="$emit('close', recipientMapping)">Confirm</Btn>
Expand Down
1 change: 0 additions & 1 deletion src/components/collections/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export const getCalls = async (mapping: Record<string, unknown>) => {
for (const set of (mapping.sets as { owner: string, old_token_id: string, new_booklet_id: string, new_booklet_name: string }[])) {
await bookletDataStore[getCurrentNetwork()][set.new_booklet_name]._fetch;
const bookletData = bookletDataStore[getCurrentNetwork()][set.new_booklet_name]._data!;
console.log(bookletData);
calls.push({
contractAddress: ADDRESSES[getCurrentNetwork()].migrate_assets,
entrypoint: 'admin_migrate_legacy_set_briqs',
Expand Down

0 comments on commit d940056

Please sign in to comment.