diff --git a/.changeset/witty-bikes-flash.md b/.changeset/witty-bikes-flash.md new file mode 100644 index 00000000..28f59dac --- /dev/null +++ b/.changeset/witty-bikes-flash.md @@ -0,0 +1,5 @@ +--- +"@bnb-chain/greenfield-js-sdk": patch +--- + +fix: Offchain auth ei.data undefined diff --git a/packages/js-sdk/src/offchainauth/utils.ts b/packages/js-sdk/src/offchainauth/utils.ts index 48d903d8..8869db08 100644 --- a/packages/js-sdk/src/offchainauth/utils.ts +++ b/packages/js-sdk/src/offchainauth/utils.ts @@ -8,7 +8,7 @@ import { import { getNonce } from '@/clients/spclient/spApis/getNonce'; import { updateUserAccountKey } from '@/clients/spclient/spApis/updateUserAccountKey'; -const delay = (ms: number, value: { code: number; nonce?: null | number; message?: any }) => +const delay = (ms: number, value: T) => new Promise((resolve) => setTimeout(() => resolve(value), ms)); export const promiseRaceAll = async ( @@ -58,19 +58,19 @@ export const updateSpsPubKey = async ({ expireDate, authorization, }: IUpdateSpsPubKeyParams) => { - const promises = sps.map((sp: ISp) => - updateUserAccountKey({ - address, - domain, - sp, - pubKey, - expireDate, - authorization, - }), + return sps.map((sp: ISp) => + Promise.race([ + updateUserAccountKey({ + address, + domain, + sp, + pubKey, + expireDate, + authorization, + }), + delay(3000, { code: -1, data: { address } }), + ]), ); - const res = await promiseRaceAll(promises, 3000); - - return res; }; export const getSpsEndpoint = (sps: ISp[]) => {