From 1eba390ad3931734d650ae07f39e66fcfe046621 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Tue, 15 Oct 2024 16:03:13 -0400 Subject: [PATCH 1/3] feat: update account.ts --- packages/core/src/account.ts | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/core/src/account.ts b/packages/core/src/account.ts index 50b46f126d..0d498cc9d0 100644 --- a/packages/core/src/account.ts +++ b/packages/core/src/account.ts @@ -404,7 +404,11 @@ export class Account { ); } - async createOrderlyKey(expiration?: number): Promise { + async createOrderlyKey( + expiration?: number, + scope: string = "trading,read", + shouldMutateAppState: boolean = true + ): Promise { if (this.stateValue.accountId === undefined) { throw new Error("account id is undefined"); } @@ -426,6 +430,7 @@ export class Account { expiration, brokerId: this.configStore.get("brokerId"), timestamp, + scope, }); const address = this.stateValue.address; @@ -455,17 +460,18 @@ export class Account { // if (res.success) { - this.keyStore.setKey(address, keyPair); - const nextState = { - ...this.stateValue, - status: AccountStatusEnum.EnableTrading, - // accountId: res.data.account_id, - // userId: res.data.user_id, - }; - - this._ee.emit("change:status", nextState); + if (shouldMutateAppState) { + this.keyStore.setKey(address, keyPair); + const nextState = { + ...this.stateValue, + status: AccountStatusEnum.EnableTrading, + // accountId: res.data.account_id, + // userId: res.data.user_id, + }; - return res; + this._ee.emit("change:status", nextState); + } + return { publicKey, secretKey: keyPair.secretKey, expiration, scope }; } else { throw new Error(res.message); } From 67096ca9f13d077e0b7e8a2bff55fecfd15c14d3 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Tue, 15 Oct 2024 16:04:49 -0400 Subject: [PATCH 2/3] feat: update helper.ts to add scope --- packages/core/src/helper.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/core/src/helper.ts b/packages/core/src/helper.ts index 6d9c267492..d4dc7ff07d 100644 --- a/packages/core/src/helper.ts +++ b/packages/core/src/helper.ts @@ -86,6 +86,7 @@ export function generateAddOrderlyKeyMessage(inputs: { primaryType: keyof typeof definedTypes; expiration?: number; timestamp?: number; + scope?: string; }) { const { publicKey, @@ -94,13 +95,14 @@ export function generateAddOrderlyKeyMessage(inputs: { brokerId, expiration = 365, timestamp = Date.now(), + scope = "read,trading", } = inputs; // const now = Date.now(); // message; const message = { brokerId, orderlyKey: publicKey, - scope: "read,trading", + scope, chainId, timestamp, expiration: timestamp + 1000 * 60 * 60 * 24 * expiration, From 2ddce079b0978bff14bd77e013d178a9fcfa650f Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Tue, 15 Oct 2024 16:06:39 -0400 Subject: [PATCH 3/3] feat: useAccount.ts --- packages/hooks/src/useAccount.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/hooks/src/useAccount.ts b/packages/hooks/src/useAccount.ts index 14a2aa9a78..956ddd98b2 100644 --- a/packages/hooks/src/useAccount.ts +++ b/packages/hooks/src/useAccount.ts @@ -56,8 +56,16 @@ export const useAccount = () => { // ); const createOrderlyKey = useCallback( - async (remember: boolean) => { - return account.createOrderlyKey(remember ? 365 : 30); + async ( + remember: boolean, + scope?: string, + shouldMutateAppState: boolean = true + ) => { + return account.createOrderlyKey( + remember ? 365 : 30, + scope, + shouldMutateAppState + ); }, [account] );