Skip to content

Commit

Permalink
feat: 🎸 add safe api
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Dec 15, 2023
1 parent ddb3cf6 commit de00862
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions packages/utils/src/mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,58 @@ export function isDarkTheme() {
return window.matchMedia?.("(prefers-color-scheme: dark)").matches ?? false;
}

type Asset = {
symbol: string;
name: string;
icon_url: string;
chain_id: string;
balance: string;
asset_id: string;
};

export async function getAssets(ids: string[]): Promise<Asset[]> {
const win: any = window;

return new Promise((resolve, reject) => {
(window as any).MixinBridgeAssetsCallbackFunction = function (resp) {
resolve(resp);
};

if (
win.webkit &&
win.webkit.messageHandlers &&
win.webkit.messageHandlers.MixinContext &&
win.webkit.messageHandlers.getAssets
) {
win.webkit.messageHandlers.getAssets.postMessage([
ids,
"MixinBridgeAssetsCallbackFunction"
]);
} else if (
win.MixinContext &&
typeof win.MixinContext.getAssets === "function"
) {
win.MixinContext.getAssets(ids, "MixinBridgeAssetsCallbackFunction");
} else {
reject(new Error("no support getAssets"));
}
});
}

export function genSafePaymentUrl(params: {
recipient: string;
assetId: string;
amount: string;
traceId: string;
memo: string;
}) {
return `https://mixin.one/pay/${params.recipient}?asset=${
params.assetId
}&amount=${params.amount}&memo=${encodeURIComponent(params.memo)}&trace=${
params.traceId
}`;
}

export function genPaymentUrl(data: {
recipient: string;
assetId: string;
Expand Down

0 comments on commit de00862

Please sign in to comment.