Use x-gobal in node polyfills
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
|
||||
import nodeFetch from 'node-fetch';
|
||||
|
||||
export const fetch = typeof global.fetch === 'undefined'
|
||||
import { xglobal } from '@polkadot/x-global';
|
||||
|
||||
export const fetch = typeof xglobal.fetch === 'undefined'
|
||||
? nodeFetch as unknown as typeof global.fetch
|
||||
: global.fetch;
|
||||
: xglobal.fetch;
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
import { NativeModules } from 'react-native';
|
||||
|
||||
import { xglobal } from '@polkadot/x-global';
|
||||
|
||||
import { insecureRandomValues } from './fallback';
|
||||
|
||||
interface RNExt {
|
||||
@@ -29,9 +31,9 @@ function getRandomValuesGlobal <T extends Uint8Array> (arr: T): T {
|
||||
return crypto.getRandomValues(arr);
|
||||
}
|
||||
|
||||
export const getRandomValues = typeof global.crypto === 'object' && typeof global.crypto.getRandomValues === 'function'
|
||||
export const getRandomValues = typeof xglobal.crypto === 'object' && typeof xglobal.crypto.getRandomValues === 'function'
|
||||
? getRandomValuesGlobal
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-explicit-any
|
||||
: (typeof (global as any).nativeCallSyncHook === 'undefined' || !NativeModules.ExpoRandom)
|
||||
: (typeof (xglobal as any).nativeCallSyncHook === 'undefined' || !NativeModules.ExpoRandom)
|
||||
? insecureRandomValues
|
||||
: getRandomValuesNative;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
import util from 'util';
|
||||
|
||||
export const TextDecoder = typeof global.TextDecoder === 'undefined'
|
||||
? util.TextDecoder as unknown as typeof global.TextDecoder
|
||||
: global.TextDecoder;
|
||||
import { xglobal } from '@polkadot/x-global';
|
||||
|
||||
export const TextDecoder = typeof xglobal.TextDecoder === 'undefined'
|
||||
? util.TextDecoder as unknown as typeof xglobal.TextDecoder
|
||||
: xglobal.TextDecoder;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
import util from 'util';
|
||||
|
||||
import { xglobal } from '@polkadot/x-global';
|
||||
|
||||
class NodeFallback {
|
||||
#encoder: util.TextEncoder;
|
||||
|
||||
@@ -18,6 +20,6 @@ class NodeFallback {
|
||||
}
|
||||
}
|
||||
|
||||
export const TextEncoder = typeof global.TextEncoder === 'undefined'
|
||||
? NodeFallback as unknown as typeof global.TextEncoder
|
||||
: global.TextEncoder;
|
||||
export const TextEncoder = typeof xglobal.TextEncoder === 'undefined'
|
||||
? NodeFallback as unknown as typeof xglobal.TextEncoder
|
||||
: xglobal.TextEncoder;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
import ws from 'websocket';
|
||||
|
||||
export const WebSocket = typeof global.WebSocket === 'undefined'
|
||||
? ws.w3cwebsocket as unknown as typeof global.WebSocket
|
||||
: global.WebSocket;
|
||||
import { xglobal } from '@polkadot/x-global';
|
||||
|
||||
export const WebSocket = typeof xglobal.WebSocket === 'undefined'
|
||||
? ws.w3cwebsocket as unknown as typeof xglobal.WebSocket
|
||||
: xglobal.WebSocket;
|
||||
|
||||
Reference in New Issue
Block a user