export interface ActionLinkProps {
targetAppId: string; // app_6c5c5717c77abe83be8814c032c3a6f9 for Swap quick action
path: string; // '/' for Swap quick action
params: Record<string, string>;
}
const MAIN_ACTION_URL = "https://worldcoin.org/mini-app";
export function getActionLink({ targetAppId, path, params }: ActionLinkProps) {
let fullPath = path;
if (Object.keys(params).length > 0) {
const paramParts = Object.entries(params).map(([key, value]) => {
return `${key}=${value}`;
});
fullPath += `?${paramParts.join("&")}`;
}
const queryString = `${MAIN_ACTION_URL}?app_id=${targetAppId}&path=${encodeURIComponent(fullPath)}`;
return queryString;
}
// Example usage
const link = getActionLink({
targetAppId: "app_6c5c5717c77abe83be8814c032c3a6f9",
path: "/",
params: {
fromToken: "0x2cFc85d8E48F8EAB294be644d9E25C3030863003",
toToken: "0x4200000000000000000000000000000000000006",
amount: "1234500",
sourceAppId: "app_source1234567890abcdef",
sourceAppName: "My%20App",
},
});
console.log(link);