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

feat: optimize kaspa transfer tips OK-34760 #6464

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions packages/core/src/chains/kaspa/sdkKaspa/constant.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export const DEFAULT_FEE = 1000;
export const CONFIRMATION_COUNT = 10;

export const MAX_UTXO_SIZE = 80;
ByteZhang1024 marked this conversation as resolved.
Show resolved Hide resolved

export const DUST_AMOUNT = 20_000_000;
export const MAX_BLOCK_SIZE = 1_000_000;
export const MAX_ORPHAN_TX_MASS = 100_000;
Expand Down
31 changes: 25 additions & 6 deletions packages/kit-bg/src/vaults/impls/kaspa/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
DUST_AMOUNT,
MAX_BLOCK_SIZE,
MAX_ORPHAN_TX_MASS,
MAX_UTXO_SIZE,
isValidAddress,
privateKeyFromWIF,
selectUTXOs,
Expand Down Expand Up @@ -135,13 +136,31 @@ export default class Vault extends VaultBase {
specifiedFeeRate,
});
txn = toTransaction(encodedTx);
if (encodedTx.inputs.length > MAX_UTXO_SIZE) {
const totalAmount = encodedTx.inputs
.sort((a, b) =>
new BigNumber(b.satoshis).minus(a.satoshis).toNumber(),
)
.slice(0, MAX_UTXO_SIZE)
.reduce((acc, input) => acc.plus(input.satoshis), new BigNumber(0));
const tokenInfo = transferInfo.tokenInfo ?? (await this.getNetwork());

ByteZhang1024 marked this conversation as resolved.
Show resolved Hide resolved
const totalAmountStr = totalAmount
.shiftedBy(-tokenInfo.decimals)
.toFixed(0);
throw new OneKeyInternalError(
appLocale.intl.formatMessage(
{
id: ETranslations.feedback_kaspa_utxo_limit_exceeded_text,
},
{
amount: totalAmountStr,
symbol: tokenInfo?.symbol ?? 'KAS',
},
),
);
ByteZhang1024 marked this conversation as resolved.
Show resolved Hide resolved
}
ByteZhang1024 marked this conversation as resolved.
Show resolved Hide resolved
const massAndSize = txn.getMassAndSize();
// if (
// massAndSize.mass > MAX_ORPHAN_TX_MASS ||
// massAndSize.txSize > MAX_BLOCK_SIZE
// ) {
// throw new OneKeyInternalError('Transaction size is too large');
// }
encodedTx.feeInfo.limit = massAndSize.mass.toString();
encodedTx.mass = massAndSize.mass;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/locale/json/bn.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"address_label.allowlist": "অনুমোদিত তালিকা",
"address_type": "ঠিকানার ধরণ",
"adress_book.add_address_add_to_allowlist": "অনুমোদিত তালিকায় যোগ করুন",
"allowlist.enabled_popover_content": "আপনি শুধুমাত্র ঠিকানা বইয়ের অনুমোদিত তালিকার ঠিকানায় তহবিল স্থানান্তর করতে পারেন। আপনি যদি ঝুঁকিগুলি বুঝতে পারেন, তবে আপনি এটি <url><underline>Settings >> Protection</underline></url> এ নিষ্ক্রিয় করতে পারেন।",
"allowlist.enabled_popover_content": "আপনি শুধুমাত্র ঠিকানা বইয়ের অনুমোদিত তালিকার ঠিকানায় তহবিল স্থানান্তর করতে পারেন। আপনি যদি ঝুঁকিগুলি বুঝতে পারেন, তবে আপনি এটি <url>https://1key.so/send/protection<underline>Settings >> Protection</underline></url> এ নিষ্ক্রিয় করতে পারেন।",
"allowlist.enabled_popover_title": "অ্যালোলিস্ট সক্রিয়",
"approve_edit.approve_amount": "পরিমাণ অনুমোদন করুন",
"approve_edit.less_than_swap": "ভাতা অদলবদলের পরিমাণের চেয়ে কম হতে পারে না",
Expand Down Expand Up @@ -1646,7 +1646,7 @@
"selected_network_only_supports_device": "নির্বাচিত নেটওয়ার্ক বর্তমানে কেবল {deviceType} সমর্থন করে",
"send.address_exists": "ঠিকানাটি ইতিমধ্যেই বিদ্যমান",
"send.address_invalid": "অবৈধ ঠিকানা। দয়া করে পরীক্ষা করুন এবং পুনরায় প্রবেশ করুন",
"send.address_not_allowlist_error": "ঠিকানা অনুমোদিত তালিকায় নেই। এটি যোগ করার চেষ্টা করুন।",
"send.address_not_allowlist_error": "ঠিকানা অনুমোদিত তালিকায় নেই। চেষ্টা করুন <url>https://1key.so/send/contacts/add?id={contactId}&address={contactAddress}<underline>এটি যোগ করুন।</underline></url>",
"send.amount": "পরিমাণ",
"send.amount_invalid": "অপর্যাপ্ত ব্যালেন্স। দয়া করে একটি ছোট পরিমাণ চেষ্টা করুন",
"send.amount_too_small": "ট্রান্সফার পরিমাণ খুব ছোট।",
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/locale/json/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"address_label.allowlist": "Erlaubnisliste",
"address_type": "Adresstyp",
"adress_book.add_address_add_to_allowlist": "Zur Positivliste hinzufügen",
"allowlist.enabled_popover_content": "Sie können nur Gelder an eine Adresse in der Adressbuch-Zulassungsliste überweisen. Wenn Sie die Risiken verstehen, können Sie es in <url><underline>Einstellungen >> Schutz</underline></url> deaktivieren.",
"allowlist.enabled_popover_content": "Sie können nur Gelder an eine auf der Positivliste stehende Adresse im Adressbuch überweisen. Wenn Sie die Risiken verstehen, können Sie es unter <url>https://1key.so/send/protection<underline>Geräte >> Schutzverwaltung</underline></url> deaktivieren.",
"allowlist.enabled_popover_title": "Allowlist aktiviert",
"approve_edit.approve_amount": "Betrag genehmigen",
"approve_edit.less_than_swap": "Der Freibetrag darf nicht geringer sein als der Swap-Betrag",
Expand Down Expand Up @@ -1646,7 +1646,7 @@
"selected_network_only_supports_device": "Das ausgewählte Netzwerk unterstützt derzeit nur {deviceType}",
"send.address_exists": "Die Adresse existiert bereits",
"send.address_invalid": "Ungültige Adresse. Bitte überprüfen und erneut eingeben",
"send.address_not_allowlist_error": "Adresse ist nicht auf der Positivliste. Versuchen Sie, sie hinzuzufügen.",
"send.address_not_allowlist_error": "Die Adresse ist nicht in der Allowlist. Versuchen Sie, sie <url>https://1key.so/send/contacts/add?id={contactId}&address={contactAddress}<underline>hinzuzufügen.</underline></url>",
"send.amount": "Betrag",
"send.amount_invalid": "Unzureichendes Guthaben. Bitte versuchen Sie es mit einem kleineren Betrag",
"send.amount_too_small": "Überweisungsbetrag zu klein.",
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/locale/json/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"address_label.allowlist": "Allowlist",
"address_type": "Address type",
"adress_book.add_address_add_to_allowlist": "Add to allowlist",
"allowlist.enabled_popover_content": "You can only transfer funds to allowlist address in Address book. If you understand the risks, you can disable it in <url><underline>Settings >> Protection</underline></url>",
"allowlist.enabled_popover_content": "You can only transfer funds to allowlist address in Address book. If you understand the risks, you can disable it in <url>https://1key.so/send/protection<underline>Settings >> Protection</underline></url>",
"allowlist.enabled_popover_title": "Allowlist enabled",
"approve_edit.approve_amount": "Approve amount",
"approve_edit.less_than_swap": "Allowance can't be less than the swap amount",
Expand Down Expand Up @@ -1646,7 +1646,7 @@
"selected_network_only_supports_device": "The selected network currently only supports {deviceType}",
"send.address_exists": "The address already exists",
"send.address_invalid": "Invalid address. Please check and re-enter.",
"send.address_not_allowlist_error": "Address is not in allowlist. Try adding it.",
"send.address_not_allowlist_error": "Address is not in allowlist. Try <url>https://1key.so/send/contacts/add?id={contactId}&address={contactAddress}<underline>adding it.</underline></url>",
"send.amount": "Amount",
"send.amount_invalid": "Insufficient balance. Please try a smaller amount",
"send.amount_too_small": "Transfer amount too small.",
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/locale/json/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"address_label.allowlist": "Allowlist",
"address_type": "Address type",
"adress_book.add_address_add_to_allowlist": "Add to allowlist",
"allowlist.enabled_popover_content": "You can only transfer funds to allowlist address in Address book. If you understand the risks, you can disable it in <url>https://onekey.so/<underline>Settings >> Protection</underline></url>",
"allowlist.enabled_popover_content": "You can only transfer funds to allowlist address in Address book. If you understand the risks, you can disable it in <url>https://1key.so/send/protection<underline>Settings >> Protection</underline></url>",
"allowlist.enabled_popover_title": "Allowlist enabled",
"approve_edit.approve_amount": "Approve amount",
"approve_edit.less_than_swap": "Allowance can't be less than the swap amount",
Expand Down Expand Up @@ -1646,7 +1646,7 @@
"selected_network_only_supports_device": "The selected network currently only supports {deviceType}",
"send.address_exists": "The address already exists",
"send.address_invalid": "Invalid address. Please check and re-enter.",
"send.address_not_allowlist_error": "Address is not in allowlist. Try adding it.",
"send.address_not_allowlist_error": "Address is not in allowlist. Try <url>https://1key.so/send/contacts/add?id={contactId}&address={contactAddress}<underline>adding it.</underline></url>",
"send.amount": "Amount",
"send.amount_invalid": "Insufficient balance. Please try a smaller amount",
"send.amount_too_small": "Transfer amount too small.",
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/locale/json/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"address_label.allowlist": "Lista de permitidos",
"address_type": "Tipo de dirección",
"adress_book.add_address_add_to_allowlist": "Agregar a la lista de permitidos",
"allowlist.enabled_popover_content": "Solo puedes transferir fondos a direcciones de la lista blanca en la libreta de direcciones. Si entiendes los riesgos, puedes desactivarlo en <url><underline>Configuración >> Protección</underline></url>",
"allowlist.enabled_popover_content": "Solo puedes transferir fondos a direcciones de la lista permitida en la libreta de direcciones. Si entiendes los riesgos, puedes desactivarlo en <url>https://1key.so/send/protection<underline>Configuración >> Protección</underline></url>",
"allowlist.enabled_popover_title": "Lista de permitidos habilitada",
"approve_edit.approve_amount": "Aprobar monto",
"approve_edit.less_than_swap": "La asignación no puede ser menor que el monto del swap",
Expand Down Expand Up @@ -1646,7 +1646,7 @@
"selected_network_only_supports_device": "La red seleccionada actualmente solo admite {deviceType}",
"send.address_exists": "La dirección ya existe",
"send.address_invalid": "Dirección inválida. Por favor, verifica y vuelve a introducir",
"send.address_not_allowlist_error": "La dirección no está en la lista de permitidos. Intenta agregarla.",
"send.address_not_allowlist_error": "La dirección no está en la lista blanca. Intente <url>https://1key.so/send/contacts/add?id={contactId}&address={contactAddress}<underline>agregándola.</underline></url>",
"send.amount": "Cantidad",
"send.amount_invalid": "Saldo insuficiente. Por favor, intenta con una cantidad menor",
"send.amount_too_small": "La cantidad a transferir es demasiado pequeña.",
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/locale/json/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"address_label.allowlist": "Liste d'autorisation",
"address_type": "Type d'adresse",
"adress_book.add_address_add_to_allowlist": "Ajouter à la liste d'autorisation",
"allowlist.enabled_popover_content": "Vous ne pouvez transférer des fonds qu'à une adresse de la liste autorisée dans le carnet d'adresses. Si vous comprenez les risques, vous pouvez le désactiver dans <url><underline>Paramètres >> Protection</underline></url>",
"allowlist.enabled_popover_content": "Vous ne pouvez transférer des fonds qu'à une adresse de la liste autorisée dans le carnet d'adresses. Si vous comprenez les risques, vous pouvez le désactiver dans <url>https://1key.so/send/protection<underline>Paramètres >> Protection</underline></url>",
"allowlist.enabled_popover_title": "Liste d'autorisation activée",
"approve_edit.approve_amount": "Approuver le montant",
"approve_edit.less_than_swap": "L'allocation ne peut pas être inférieure au montant du swap",
Expand Down Expand Up @@ -1646,7 +1646,7 @@
"selected_network_only_supports_device": "Le réseau sélectionné ne prend actuellement en charge que {deviceType}",
"send.address_exists": "L'adresse existe déjà",
"send.address_invalid": "Adresse invalide. Veuillez vérifier et saisir à nouveau",
"send.address_not_allowlist_error": "L'adresse n'est pas dans la liste autorisée. Essayez de l'ajouter.",
"send.address_not_allowlist_error": "L'adresse n'est pas dans la liste blanche. Essayez <url>https://1key.so/send/contacts/add?id={contactId}&address={contactAddress}<underline>de l'ajouter.</underline></url>",
"send.amount": "Montant",
"send.amount_invalid": "Solde insuffisant. Veuillez essayer avec un montant plus petit",
"send.amount_too_small": "Montant du transfert trop petit.",
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/locale/json/hi_IN.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"address_label.allowlist": "अनुमतिसूची",
"address_type": "पता प्रकार",
"adress_book.add_address_add_to_allowlist": "अनुमति सूची में जोड़ें",
"allowlist.enabled_popover_content": "आप केवल एड्रेस बुक में अलाउलिस्ट पते पर फंड ट्रांसफर कर सकते हैं। यदि आप जोखिमों को समझते हैं, तो आप इसे <url><underline>सेटिंग्स >> प्रोटेक्शन</underline></url> में अक्षम कर सकते हैं।",
"allowlist.enabled_popover_content": "आप केवल एड्रेस बुक में अलाउलिस्ट पते पर फंड ट्रांसफर कर सकते हैं। यदि आप जोखिमों को समझते हैं, तो आप इसे <url>https://1key.so/send/protection<underline>设备 >> 防护管理</underline></url> में अक्षम कर सकते हैं।",
"allowlist.enabled_popover_title": "अनुमति सूची सक्षम की गई",
"approve_edit.approve_amount": "राशि स्वीकृत करें",
"approve_edit.less_than_swap": "भत्ता स्वैप राशि से कम नहीं हो सकता",
Expand Down Expand Up @@ -1646,7 +1646,7 @@
"selected_network_only_supports_device": "चयनित नेटवर्क वर्तमान में केवल {deviceType} का समर्थन करता है।",
"send.address_exists": "पता पहले से मौजूद है",
"send.address_invalid": "अमान्य पता। कृपया जांचें और पुनः दर्ज करें",
"send.address_not_allowlist_error": "पता अनुमति सूची में नहीं है। इसे जोड़ने का प्रयास करें।",
"send.address_not_allowlist_error": "पता अनुमति सूची में नहीं है। <url>https://1key.so/send/contacts/add?id={contactId}&address={contactAddress}<underline>इसे जोड़ने का प्रयास करें।</underline></url>",
"send.amount": "राशि",
"send.amount_invalid": "अपर्याप्त बैलेंस। कृपया एक छोटी राशि का प्रयास करें",
"send.amount_too_small": "स्थानांतरण राशि बहुत छोटी है।",
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/locale/json/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"address_label.allowlist": "Daftar Izin",
"address_type": "Jenis alamat",
"adress_book.add_address_add_to_allowlist": "Tambahkan ke daftar yang diizinkan",
"allowlist.enabled_popover_content": "Anda hanya dapat mentransfer dana ke alamat yang ada di daftar putih dalam Buku Alamat. Jika Anda memahami risikonya, Anda dapat menonaktifkannya di <url><underline>Pengaturan >> Perlindungan</underline></url>",
"allowlist.enabled_popover_content": "Anda hanya dapat mentransfer dana ke alamat yang ada di daftar putih dalam Buku Alamat. Jika Anda memahami risikonya, Anda dapat menonaktifkannya di <url>https://1key.so/send/protection<underline>Pengaturan >> Perlindungan</underline></url>",
"allowlist.enabled_popover_title": "Daftar diizinkan diaktifkan",
"approve_edit.approve_amount": "Menyetujui jumlah",
"approve_edit.less_than_swap": "Tunjangan tidak boleh kurang dari jumlah swap",
Expand Down Expand Up @@ -1646,7 +1646,7 @@
"selected_network_only_supports_device": "Jaringan yang dipilih saat ini hanya mendukung {deviceType}",
"send.address_exists": "Alamat sudah ada",
"send.address_invalid": "Alamat tidak valid. Silakan periksa dan masukkan kembali",
"send.address_not_allowlist_error": "Alamat tidak ada dalam daftar yang diizinkan. Coba tambahkan.",
"send.address_not_allowlist_error": "Alamat tidak ada dalam daftar yang diizinkan. Coba <url>https://1key.so/send/contacts/add?id={contactId}&address={contactAddress}<underline>menambahkannya.</underline></url>",
"send.amount": "Jumlah",
"send.amount_invalid": "Saldo tidak cukup. Silakan coba jumlah yang lebih kecil",
"send.amount_too_small": "Jumlah transfer terlalu kecil.",
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/locale/json/it_IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"address_label.allowlist": "Lista consentita",
"address_type": "Tipo di indirizzo",
"adress_book.add_address_add_to_allowlist": "Aggiungi alla lista consentita",
"allowlist.enabled_popover_content": "Puoi trasferire fondi solo agli indirizzi nella lista consentita nel Libro degli indirizzi. Se comprendi i rischi, puoi disabilitarlo in <url><underline>Impostazioni >> Protezione</underline></url>",
"allowlist.enabled_popover_content": "Puoi trasferire fondi solo agli indirizzi nella lista consentita nel Rubrica. Se comprendi i rischi, puoi disabilitarlo in <url>https://1key.so/send/protection<underline>Impostazioni >> Protezione</underline></url>",
"allowlist.enabled_popover_title": "Allowlist abilitata",
"approve_edit.approve_amount": "Approva importo",
"approve_edit.less_than_swap": "L'indennità non può essere inferiore all'importo dello swap",
Expand Down Expand Up @@ -1646,7 +1646,7 @@
"selected_network_only_supports_device": "La rete selezionata attualmente supporta solo {deviceType}",
"send.address_exists": "L'indirizzo esiste già",
"send.address_invalid": "Indirizzo non valido. Si prega di controllare e reinserire",
"send.address_not_allowlist_error": "L'indirizzo non è nella lista consentita. Prova ad aggiungerlo.",
"send.address_not_allowlist_error": "L'indirizzo non è nella lista consentita. Prova <url>https://1key.so/send/contacts/add?id={contactId}&address={contactAddress}<underline>ad aggiungerlo.</underline></url>",
"send.amount": "Importo",
"send.amount_invalid": "Saldo insufficiente. Si prega di provare con un importo minore",
"send.amount_too_small": "Importo del trasferimento troppo piccolo.",
Expand Down
Loading
Loading