diff --git a/.changeset/shy-tips-grin.md b/.changeset/shy-tips-grin.md new file mode 100644 index 00000000..d4b15a21 --- /dev/null +++ b/.changeset/shy-tips-grin.md @@ -0,0 +1,5 @@ +--- +'@bnb-chain/greenfield-js-sdk': patch +--- + +feat: Remove warning in browser. diff --git a/packages/js-sdk/src/clients/spclient/spClient.ts b/packages/js-sdk/src/clients/spclient/spClient.ts index df47ae58..d64d5b5d 100644 --- a/packages/js-sdk/src/clients/spclient/spClient.ts +++ b/packages/js-sdk/src/clients/spclient/spClient.ts @@ -169,7 +169,6 @@ export class SpClient implements ISpClient { }, ) { const R = superagent.put(url); - R.buffer(true); R.timeout(timeout); R.ok((res) => res.status < 500); @@ -179,25 +178,23 @@ export class SpClient implements ISpClient { }); } - try { - if (options.headers) { - (options.headers as Headers).forEach((v: string, k: string) => { - R.set(k, v); - }); - } + if (callback && callback.onProgress) { + R.on('progress', (e) => { + callback.onProgress?.(e); + }); + } - if (callback && callback.onProgress) { - R.on('progress', (e) => { - callback.onProgress?.(e); - }); - } + const file = assertFileType(uploadFile) ? uploadFile.content : uploadFile; - const file = assertFileType(uploadFile) ? uploadFile.content : uploadFile; + // https://ladjs.github.io/superagent/docs/index.html#serializing-request-body + const sendFile = + isNode && R.get('Content-Type') === 'application/json' ? file.toString() : file; + if (isNode) { + R.buffer(true); + } - // https://ladjs.github.io/superagent/docs/index.html#serializing-request-body - const serializeFile = - isNode && R.get('Content-Type') === 'application/json' ? file.toString() : file; - const response = await R.send(serializeFile); + try { + const response = await R.send(sendFile); const { status } = response; if (status === SP_NOT_AVAILABLE_ERROR_CODE) {