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); } 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, 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] );