Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: cleanup external broadcast #804

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/i18n/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ const dict = {
routing_fee_limit: "Routing fee limit",
broadcast_setting: "External Broadcast",
broadcast_setting_tooltip:
"Use third-party block explorers for broadcasting claim and refund transactions in addition to Boltz backend",
"Also use the block explorer to broadcast transactions",
},
de: {
language: "Deutsch",
Expand Down Expand Up @@ -495,9 +495,9 @@ const dict = {
no_wallet_connected: "Kein Wallet verbunden",
no_lockup_transaction: "Keine Lockup-Transaktion gefunden",
routing_fee_limit: "Routing Gebühr Limit",
broadcast_setting: "Externe Sendung",
broadcast_setting: "Externer Broadcast",
broadcast_setting_tooltip:
"Verwenden Sie Drittanbieter-Blockexplorer, um Anspruchs- und Rückerstattungstransaktionen zusätzlich zum Boltz-Backend zu senden",
"Verwende auch den Block Explorer, um Transaktionen zu senden",
},
es: {
language: "Español",
Expand Down Expand Up @@ -748,7 +748,7 @@ const dict = {
routing_fee_limit: "Límite de la tarifa de enrutamiento",
broadcast_setting: "Transmisión externa",
broadcast_setting_tooltip:
"Utilice exploradores de bloques de terceros para transmitir transacciones de reclamo y reembolso además del backend de Boltz",
"También use el explorador de bloques para transmitir transacciones",
},
zh: {
language: "中文",
Expand Down Expand Up @@ -971,8 +971,7 @@ const dict = {
no_lockup_transaction: "未找到锁仓交易",
routing_fee_limit: "最大路由费用",
broadcast_setting: "外部广播",
broadcast_setting_tooltip:
"除了Boltz后台外,还使用第三方区块浏览器广播认领和退款交易",
broadcast_setting_tooltip: "使用区块浏览器发送认领和退款交易",
},
ja: {
language: "日本語",
Expand Down Expand Up @@ -1220,9 +1219,9 @@ const dict = {
no_wallet_connected: "財布はつながっていない!",
no_lockup_transaction: "ロックアップトランザクションが見つかりません",
routing_fee_limit: "ルーティング料金の上限",
broadcast_setting: "外部ブロードキャスト",
broadcast_setting: "外部放送",
broadcast_setting_tooltip:
"Boltzバックエンドに加えて、サードパーティのブロックエクスプローラーを使用して請求および返金取引をブロードキャストします",
"ブロック・エクスプローラーを使ってトランザクションをブロードキャストする",
},
};

Expand Down
29 changes: 10 additions & 19 deletions src/utils/boltzClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,41 +355,32 @@ export const getContracts = () =>
export const broadcastTransaction = async (
asset: string,
txHex: string,
externalBroadcast: boolean,
externalBroadcast: boolean = false,
): Promise<{
id: string;
}> => {
const promises: Promise<{
id: string;
}>[] = [];

// broadcast to Boltz backend
promises.push(
}>[] = [
fetcher<{ id: string }>(`/v2/chain/${asset}/transaction`, {
hex: txHex,
}),
);
];

// broadcast to block explorer
if (externalBroadcast) {
promises.push(broadcastToExplorer(asset, txHex));
}

// Wait for all promises to settle
const results = await Promise.allSettled(promises);
let reason = "";

// Process the results
for (const result of results) {
if (result.status === "fulfilled") {
// Return the first successful transaction ID
return result.value;
}
reason = result.reason;
const successfulResult = results.find(
(result) => result.status === "fulfilled",
);
if (successfulResult) {
return (successfulResult as PromiseFulfilledResult<{ id: string }>)
.value;
}

// If no promises resolved successfully, return the last reason
throw reason;
throw (results[0] as PromiseRejectedResult).reason;
};

export const getLockupTransaction = async (
Expand Down
7 changes: 2 additions & 5 deletions src/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,11 @@ export const broadcastToExplorer = async (
txHex: string,
): Promise<{ id: string }> => {
const basePath = chooseUrl(config.assets[asset].blockExplorerUrl);

const opts: RequestInit = {
const response = await fetch(`${basePath}/api/tx`, {
method: "POST",
body: txHex,
};
});

const apiUrl = basePath + "/api/tx";
const response = await fetch(apiUrl, opts);
if (!response.ok) {
try {
const body = await response.json();
Expand Down
Loading