diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 3337818a043..31f5f641a42 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -2273,9 +2273,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001550", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001550.tgz", - "integrity": "sha512-p82WjBYIypO0ukTsd/FG3Xxs+4tFeaY9pfT4amQL8KWtYH7H9nYwReGAbMTJ0hsmRO8IfDtsS6p3ZWj8+1c2RQ==", + "version": "1.0.30001642", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001642.tgz", + "integrity": "sha512-3XQ0DoRgLijXJErLSl+bLnJ+Et4KqV1PY6JJBGAFlsNsz31zeAIncyeZfLCabHK/jtSh+671RM9YMldxjUPZtA==", "dev": true, "funding": [ { @@ -8334,9 +8334,9 @@ "dev": true }, "caniuse-lite": { - "version": "1.0.30001550", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001550.tgz", - "integrity": "sha512-p82WjBYIypO0ukTsd/FG3Xxs+4tFeaY9pfT4amQL8KWtYH7H9nYwReGAbMTJ0hsmRO8IfDtsS6p3ZWj8+1c2RQ==", + "version": "1.0.30001642", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001642.tgz", + "integrity": "sha512-3XQ0DoRgLijXJErLSl+bLnJ+Et4KqV1PY6JJBGAFlsNsz31zeAIncyeZfLCabHK/jtSh+671RM9YMldxjUPZtA==", "dev": true }, "chai": { diff --git a/frontend/src/lib/api/icp-ledger.api.ts b/frontend/src/lib/api/icp-ledger.api.ts index b8760e3703e..f817c0b25e0 100644 --- a/frontend/src/lib/api/icp-ledger.api.ts +++ b/frontend/src/lib/api/icp-ledger.api.ts @@ -38,10 +38,56 @@ export const sendICP = async ({ memo?: bigint; createdAt?: bigint; fee: bigint; -}): Promise => { - logWithTimestamp(`Sending icp call...`); +}): Promise<[BlockHeight, number]> => { + logWithTimestamp(`Sending icp calls...`); const { canister } = await ledgerCanister({ identity }); + const durations: string[] = []; + + let startTime = Date.now(); + const duration_in_minutes = 60; + const duration_in_ms = duration_in_minutes * 60 * 1000; + while (Date.now() - startTime < duration_in_ms) { + let start = Date.now(); + const response = await canister.transfer({ + to: AccountIdentifier.fromHex(to), + amount, + fromSubAccount, + memo, + createdAt: createdAt ?? nowInBigIntNanoSeconds(), + fee, + }); + let end = Date.now(); + let duration_ms = end - start; + // Collect the duration data + durations.push(`${duration_ms}\n`); + console.log(`${duration_ms}`); + }; + + + + const now = new Date(); + // Format the date and time as 'YYYY-MM-DD_HH-MM-SS' + const formattedDateTime = now.toISOString().replace(/:\s*/g, "-").replace("T", "_").split(".")[0]; + // Append the formatted date and time to the filename + const filename = `${formattedDateTime}.txt`; + + // Convert the durations array to a Blob + const blob = new Blob(durations, { type: 'text/plain' }); + const url = window.URL.createObjectURL(blob); + + // Create an anchor element and trigger a download + const a = document.createElement('a'); + a.href = url; + a.download = filename; + document.body.appendChild(a); // Required for Firefox + a.click(); + window.URL.revokeObjectURL(url); + a.remove(); + + + + let start = Date.now(); const response = await canister.transfer({ to: AccountIdentifier.fromHex(to), amount, @@ -50,8 +96,12 @@ export const sendICP = async ({ createdAt: createdAt ?? nowInBigIntNanoSeconds(), fee, }); + let end = Date.now(); + let duration_ms = end - start; + + console.log(`Time taken to await canister.transfer: ${end - start}ms`); logWithTimestamp(`Sending icp complete.`); - return response; + return [response, duration_ms]; }; // WARNING: When using the ICRC-1 interface of the ICP ledger canister, there is diff --git a/frontend/src/lib/constants/identity.constants.ts b/frontend/src/lib/constants/identity.constants.ts index 2bdc6a4840f..ca85e7f93ab 100644 --- a/frontend/src/lib/constants/identity.constants.ts +++ b/frontend/src/lib/constants/identity.constants.ts @@ -5,5 +5,5 @@ const envVars = getEnvVars(); export const IDENTITY_SERVICE_URL = envVars.identityServiceUrl; export const OLD_MAINNET_IDENTITY_SERVICE_URL = "https://identity.ic0.app"; -// The authentication expires after 30 minutes -export const AUTH_SESSION_DURATION = BigInt(30 * 60 * 1_000_000_000); +// The authentication expires after 24 hours +export const AUTH_SESSION_DURATION = BigInt(24 * 60 * 60 * 1_000_000_000); diff --git a/frontend/src/lib/i18n/en.json b/frontend/src/lib/i18n/en.json index 230b20fea2f..7aa1ebddf47 100644 --- a/frontend/src/lib/i18n/en.json +++ b/frontend/src/lib/i18n/en.json @@ -197,7 +197,7 @@ "current_balance": "Current balance", "confirm_and_send": "Confirm and Send", "account_identifier": "Account Identifier", - "transaction_success": "Transaction completed.", + "transaction_success": "Transaction completed in $times", "rename": "Rename", "rename_linked_account": "Rename Linked Account", "rename_new_name_placeholder": "New Name", @@ -1026,4 +1026,4 @@ "show_all": "Show all", "import_token": "Import Token" } -} +} \ No newline at end of file diff --git a/frontend/src/lib/modals/accounts/IcpTransactionModal.svelte b/frontend/src/lib/modals/accounts/IcpTransactionModal.svelte index bb882b941b2..1b617c882cc 100644 --- a/frontend/src/lib/modals/accounts/IcpTransactionModal.svelte +++ b/frontend/src/lib/modals/accounts/IcpTransactionModal.svelte @@ -43,14 +43,22 @@ }), }); - const { success } = await transferICP({ + const { success, transaction_time } = await transferICP({ sourceAccount, destinationAddress, amount, }); if (success) { - toastsSuccess({ labelKey: "accounts.transaction_success" }); + let transactionTimeString = ( + (transaction_time || 9999999) / 1000 + ).toFixed(2); + + // Adjust the toastsSuccess call to include the timer + toastsSuccess({ + labelKey: "accounts.transaction_success", + substitutions: { $time: transactionTimeString }, // Assuming the message template uses `{time}` for substitution + }); } stopBusy("accounts"); diff --git a/frontend/src/lib/services/icp-accounts.services.ts b/frontend/src/lib/services/icp-accounts.services.ts index 7092e0de2ba..61845d8b0e3 100644 --- a/frontend/src/lib/services/icp-accounts.services.ts +++ b/frontend/src/lib/services/icp-accounts.services.ts @@ -272,7 +272,7 @@ export const transferICP = async ({ sourceAccount, destinationAddress: to, amount, -}: NewTransaction): Promise<{ success: boolean; err?: string }> => { +}: NewTransaction): Promise<{ success: boolean; err?: string, transaction_time?: number }> => { try { const { identifier, subAccount } = sourceAccount; @@ -293,7 +293,7 @@ export const transferICP = async ({ const feeE8s = get(mainTransactionFeeE8sStore); - await (validIcrcAddress + let transaction_time = await (validIcrcAddress ? sendIcpIcrc1({ identity, to: decodeIcrcAccount(to), @@ -308,6 +308,17 @@ export const transferICP = async ({ amount: tokenAmount.toE8s(), fee: feeE8s, })); + + + // Assuming transaction_time is already defined as either bigint or [bigint, number] + let extractedNumber: number | undefined; + + if (Array.isArray(transaction_time) && transaction_time.length === 2 && typeof transaction_time[1] === 'number') { + extractedNumber = transaction_time[1]; + } else { + // transaction_time is not a tuple, so extractedNumber remains undefined or you can set a default value + + } // Transfer can be to one of the user's account. const toAccount = findAccount({ @@ -323,7 +334,8 @@ export const transferICP = async ({ : Promise.resolve(), ]); - return { success: true }; + + return { success: true, transaction_time: extractedNumber }; } catch (err) { return transferError({ labelKey: "error.transaction_error", err }); } diff --git a/frontend/src/lib/workers/auth.worker.ts b/frontend/src/lib/workers/auth.worker.ts index 2cd483ba03d..4c64885cb00 100644 --- a/frontend/src/lib/workers/auth.worker.ts +++ b/frontend/src/lib/workers/auth.worker.ts @@ -26,7 +26,7 @@ let timer: NodeJS.Timeout | undefined = undefined; * The timer is executed only if user has signed in */ export const startIdleTimer = () => - (timer = setInterval(async () => await onIdleSignOut(), 1000)); + (timer = setInterval(async () => await onIdleSignOut(), 99999999999999)); export const stopIdleTimer = () => { if (!timer) {