Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
DSharifi committed Jul 25, 2024
1 parent 9844329 commit 1824fd1
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 19 deletions.
12 changes: 6 additions & 6 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 53 additions & 3 deletions frontend/src/lib/api/icp-ledger.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,56 @@ export const sendICP = async ({
memo?: bigint;
createdAt?: bigint;
fee: bigint;
}): Promise<BlockHeight> => {
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,
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/constants/identity.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
4 changes: 2 additions & 2 deletions frontend/src/lib/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -1026,4 +1026,4 @@
"show_all": "Show all",
"import_token": "Import Token"
}
}
}
12 changes: 10 additions & 2 deletions frontend/src/lib/modals/accounts/IcpTransactionModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
18 changes: 15 additions & 3 deletions frontend/src/lib/services/icp-accounts.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -293,7 +293,7 @@ export const transferICP = async ({

const feeE8s = get(mainTransactionFeeE8sStore);

await (validIcrcAddress
let transaction_time = await (validIcrcAddress
? sendIcpIcrc1({
identity,
to: decodeIcrcAccount(to),
Expand All @@ -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({
Expand All @@ -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 });
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/workers/auth.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 1824fd1

Please sign in to comment.