forked from olegdeezus/ChronoMint-RN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshim.ios.js
137 lines (118 loc) · 4.27 KB
/
shim.ios.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/**
* Copyright 2017–2018, LaborX PTY
* Licensed under the AGPL Version 3 license.
*/
// [AO] These imports breaking Android. See https://github.com/facebook/react-native/issues/15902#issuecomment-375352955
// import 'core-js/es6/symbol'
// import 'core-js/fn/symbol/iterator'
// For the package bitcore-mnemonic-react-native
// See https://github.com/WoeOm/bitcore-mnemonic-react-native#readme
import { asyncRandomBytes } from 'react-native-secure-randombytes'
window.randomBytes = asyncRandomBytes
// Needed so that 'stream-http' chooses the right default protocol.
global.location = {
protocol: 'file:',
}
/* eslint-disable no-underscore-dangle */
if (typeof __dirname === 'undefined') global.__dirname = '/'
if (typeof __filename === 'undefined') global.__filename = ''
/* eslint-enable no-underscore-dangle */
/* eslint-disable global-require */
if (typeof process === 'undefined') {
global.process = require('process')
} else {
const bProcess = require('process')
for (const p in bProcess) {
if (!(p in process)) {
process[p] = bProcess[p]
}
}
}
/* eslint-enable global-require */
process.browser = false
// eslint-disable-next-line global-require
if (typeof Buffer === 'undefined') global.Buffer = require('buffer').Buffer
// Web3 installation with CRNA: see https://gist.github.com/dougbacelar/29e60920d8fa1982535247563eb63766
if (typeof btoa === 'undefined') {
global.btoa = function (str) {
return new Buffer(str, 'binary').toString('base64')
}
}
if (typeof atob === 'undefined') {
global.atob = function (b64Encoded) {
return new Buffer(b64Encoded, 'base64').toString('binary')
}
}
// Polyfill for the Error.captureStackTrace (this is NodeJS core's method)
if (typeof Error.captureStackTrace === 'undefined') {
// eslint-disable-next-line global-require
global.Error.captureStackTrace = require('capture-stack-trace')
}
// eslint-disable-next-line no-undef
const isDev = typeof __DEV__ === 'boolean' && __DEV__
const strIsDev = isDev ? 'development' : 'production'
Object.assign(process.env, { NODE_ENV: strIsDev })
if (typeof localStorage !== 'undefined') {
localStorage.debug = isDev ? '*' : ''
}
// If using the crypto shim, uncomment the following line to ensure
// crypto is loaded first, so it can populate global.crypto
require('crypto')
/* eslint-disable no-underscore-dangle, no-inner-declarations, no-param-reassign */
if (
typeof Object.setPrototypeOf === 'undefined' &&
typeof Object.getOwnPropertyNames === 'function'
) {
var _exclude = ['length', 'name', 'arguments', 'caller', 'prototype']
function bindFunction (ctx, fn) {
return function () {
return fn.apply(this, arguments)
}
}
function bindProperty (ctx, prop, parentDescriptor) {
if (!parentDescriptor) {
var defaultValue = ctx.__proto__[prop]
parentDescriptor = {
get: function () {
return ctx['__' + prop] || defaultValue
},
set: function (val) {
ctx['__' + prop] = val
},
}
}
Object.defineProperty(ctx, prop, {
get: parentDescriptor.get ? parentDescriptor.get.bind(ctx) : undefined,
set: parentDescriptor.set ? parentDescriptor.set.bind(ctx) : undefined,
configurable: true,
})
}
function iterateProps (subClass, superClass) {
var props = Object.getOwnPropertyNames(superClass),
proto
subClass.__proto__ = superClass
for (var i = 0, len = props.length; i < len; i++) {
var prop = props[i]
if (prop === '__proto__') {
proto = superClass[prop]
} else if (_exclude.indexOf(i) === -1) {
var descriptor = Object.getOwnPropertyDescriptor(subClass, prop)
if (!descriptor) {
var superDescriptor = Object.getOwnPropertyDescriptor(superClass, prop)
if (typeof superDescriptor.get !== 'function' && typeof superClass[prop] === 'function') {
subClass[prop] = bindFunction(subClass, superClass[prop])
} else if (typeof superDescriptor.get == 'function') {
bindProperty(subClass, prop, superDescriptor)
} else {
bindProperty(subClass, prop)
}
}
}
}
if (proto) {
iterateProps(subClass, proto)
}
}
Object.setPrototypeOf = iterateProps
}
/* eslint-enable no-underscore-dangle, no-inner-declarations, no-param-reassign */