diff --git a/src/background/background.ts b/src/background/background.ts index 077647e..b25b9bf 100644 --- a/src/background/background.ts +++ b/src/background/background.ts @@ -524,13 +524,15 @@ async function processRequest(request: RequestType, sender: Sender, sendResponse const transferData: any = req.transfer; const { assetId, destination, amount, asset, comment, destinations } = transferData; + const hasMultipleDestinations = Array.isArray(destinations) && destinations.length > 0; + return transfer( assetId, - destination, - amount, + hasMultipleDestinations ? undefined : destination, + hasMultipleDestinations ? undefined : amount, asset?.decimal_point ?? 12, comment ?? undefined, - destinations + hasMultipleDestinations ? destinations : [] ); }, { diff --git a/src/background/wallet.ts b/src/background/wallet.ts index 2b3c620..48e9625 100644 --- a/src/background/wallet.ts +++ b/src/background/wallet.ts @@ -316,19 +316,29 @@ export const createAlias = async ({ alias, address }: any) => { export const transfer = async ( assetId = ZANO_ASSET_ID, - destination: any, - amount: any, + destination: string, + amount: string, decimalPoint: any, comment?: string, - destinations = [], + destinations: { address: string; amount: number }[] = [], ) => { - const primaryDestination = { - address: destination, - amount: addZeros(amount, typeof decimalPoint === "number" ? decimalPoint : 12), - asset_id: assetId, - }; - - const allDestinations = destinations.length > 0 ? [primaryDestination, ...destinations] : [primaryDestination]; + const allDestinations = destinations.length > 0 + ? destinations.map(dest => ({ + address: dest.address, + amount: addZeros( + dest.amount, + typeof decimalPoint === "number" ? decimalPoint : 12 + ), + asset_id: assetId + })) + : [{ + address: destination, + amount: addZeros( + amount, + typeof decimalPoint === "number" ? decimalPoint : 12 + ), + asset_id: assetId + }]; const options: { destinations: typeof allDestinations; fee: number; mixin: number; comment?: string } = { destinations: allDestinations,