transformItemsToSdkReceivers.ts
1 import type { Items, Weights } from '$lib/components/list-editor/types'; 2 import type { SdkSplitsReceiver } from '@drips-network/sdk'; 3 import assert from '$lib/utils/assert'; 4 5 export async function transformItemsToSdkReceivers( 6 weights: Weights, 7 items: Items, 8 ): Promise<SdkSplitsReceiver[]> { 9 const receivers: SdkSplitsReceiver[] = []; 10 11 for (const [accountId, weight] of Object.entries(weights)) { 12 assert(weight > 0n, 'Cannot transform item to SDK receiver: weight must be greater than 0'); 13 14 const item = items[accountId]; 15 16 switch (item.type) { 17 case 'address': 18 receivers.push({ 19 type: 'address', 20 address: item.address as `0x${string}`, 21 weight, 22 }); 23 break; 24 25 case 'project': 26 receivers.push({ 27 type: 'project', 28 url: item.project.source.url, 29 weight, 30 }); 31 break; 32 33 case 'drip-list': 34 receivers.push({ 35 type: 'drip-list', 36 accountId: BigInt(item.dripList.account.accountId), 37 weight, 38 }); 39 break; 40 41 case 'orcid': 42 receivers.push({ 43 type: 'orcid', 44 orcidId: item.orcid.orcid, 45 weight, 46 }); 47 break; 48 } 49 } 50 51 return receivers; 52 }