This commit is contained in:
AzizbekFayziyev 2025-03-16 16:59:17 +05:00
parent ccabe30546
commit 0f4384ca0e
2 changed files with 25 additions and 13 deletions

View file

@ -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 : []
);
},
{

View file

@ -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,