@stellar-expert/ui-framework 1.9.0 → 1.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -82,4 +82,3 @@ export * from './effect/effect-description'
82
82
  //Stellar-specific utils
83
83
  export * from './stellar/key-type'
84
84
  export * from './stellar/signature-hint-utils'
85
- export * from './contract/wasm-section-parser'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stellar-expert/ui-framework",
3
- "version": "1.9.0",
3
+ "version": "1.9.2",
4
4
  "description": "StellarExpert shared UI components library",
5
5
  "main": "index.js",
6
6
  "module": "./index.js",
@@ -33,6 +33,11 @@ function ToastNotificationsBlock() {
33
33
 
34
34
  useEffect(() => {
35
35
  //declare globally available notify() function
36
+ /**
37
+ * Show toast notification popup
38
+ * @param {'info'|'success'|'warning'|'error'} type - Notification type
39
+ * @param {String} message - Message to show
40
+ */
36
41
  window.notify = function ({type, message}) {
37
42
  const newNotification = new ToastNotificationInstance({
38
43
  type,
@@ -65,6 +65,7 @@
65
65
  > div {
66
66
  color: var(--color-text);
67
67
  font-size: 0.9em;
68
+ overflow-wrap: anywhere;
68
69
  @media (max-width: $responsive-mobile-browser-width) {
69
70
  font-size: 0.85em;
70
71
  }
@@ -1,159 +0,0 @@
1
- import xdr from '@stellar/stellar-base'
2
- import {XdrReader} from './xdr-reader'
3
- import {WasmSectionReader} from './wasm-section-reader'
4
-
5
- /**
6
- * Parse contract metadata from WASM sections
7
- * @param {Buffer} rawWasm
8
- * @return {{}}
9
- */
10
- export function parseContractMetadata(rawWasm) {
11
- const wasmSectionReader = new WasmSectionReader(rawWasm)
12
- const sections = wasmSectionReader.readCustomSections()
13
- const res = {}
14
- for (const section of sections) {
15
- switch (section.name) {
16
- case 'contractenvmetav0':
17
- res.interfaceVersion = xdr.ScEnvMetaEntry.fromXDR(section.contents).value().toString()
18
- break
19
- case 'contractmetav0':
20
- Object.assign(res, parseContractMeta(parseEntries(section.contents, xdr.ScMetaEntry)))
21
- break
22
- case 'contractspecv0':
23
- Object.assign(res, parseSpec(parseEntries(section.contents, xdr.ScSpecEntry)))
24
- break
25
- }
26
- }
27
- return res
28
- }
29
-
30
- function parseEntries(buffer, xdrContract) {
31
- const reader = new XdrReader(buffer)
32
- const entries = []
33
- while (!reader.eof) {
34
- entries.push(xdrContract.read(reader))
35
- }
36
- return entries
37
- }
38
-
39
- function parseContractMeta(meta) {
40
- const res = {}
41
- for (const {_value} of meta) {
42
- const key = _value.key().toString()
43
- const val = _value.val().toString()
44
- switch (key) {
45
- case 'rsver':
46
- res.rustVersion = val
47
- break
48
- case 'rssdkver':
49
- res.sdkVersion = val
50
- break
51
- }
52
- }
53
- return res
54
- }
55
-
56
- function parseSpec(entries) {
57
- const res = {}
58
-
59
- function addSpec(key, descriptor) {
60
- let spec = res[key]
61
- if (spec === undefined) {
62
- spec = res[key] = []
63
- }
64
- spec.push(descriptor)
65
- }
66
-
67
- for (const spec of entries) {
68
- const value = spec.value()
69
- switch (spec._arm) {
70
- case 'functionV0':
71
- addSpec('functions', {
72
- name: value.name().toString(),
73
- inputs: value.inputs().map(parseParameter),
74
- outputs: value.outputs().map(parseParameterType)
75
- })
76
- break
77
- case 'udtStructV0':
78
- addSpec('structs', {
79
- name: parseStructName(value),
80
- fields: value.fields().map(parseParameter)
81
- })
82
- break
83
- case 'udtUnionV0':
84
- addSpec('unions', {
85
- name: parseStructName(value),
86
- cases: value.cases().reduce((agg, c) => {
87
- const value = c.value()
88
- const caseType = {
89
- name: value.name().toString()
90
- }
91
- if (value.type) {
92
- caseType.type = value.type().map(parseParameterType)
93
- }
94
- agg[c.switch().name.replace('scSpecUdtUnionCase', '')] = caseType
95
- return agg
96
- }, {})
97
- })
98
- break
99
- case 'udtEnumV0':
100
- addSpec('enums', {
101
- name: parseStructName(value),
102
- cases: value.cases().reduce((agg, c) => {
103
- const value = c.value()
104
- agg[value.name().toString()] = value.value() //TODO: check
105
- return agg
106
- }, {})
107
- })
108
- break
109
- case 'udtErrorEnumV0':
110
- addSpec('errors', {
111
- name: parseStructName(value),
112
- cases: value.cases().map(c => ({
113
- name: c.name().toString(),
114
- value: c.value()
115
- }))
116
- })
117
- break
118
- }
119
- }
120
- return res
121
- }
122
-
123
- function parseStructName(value) {
124
- let structName = value.name().toString()
125
- const lib = value.lib()
126
- if (lib.length) {
127
- structName += ':' + lib.toString()
128
- }
129
- return structName
130
- }
131
-
132
- function parseParameterType(type) {
133
- const typeName = type.switch().name
134
- switch (typeName) {
135
- case 'scSpecTypeOption':
136
- return `option<${parseParameterType(type.valueType())}>`
137
- case 'scSpecTypeBytesN':
138
- return `bytesn<${type.value().n()}>`
139
- case 'scSpecTypeVec':
140
- return `vec<${parseParameterType(type.value().elementType())}>`
141
- case 'scSpecTypeMap':
142
- return `map<${parseParameterType(type.value().keyType())},${parseParameter(type.value().valueType())}>`
143
- case 'scSpecTypeResult':
144
- return `result<${parseParameterType(type.value().okType())},${parseParameter(type.value().errorType())}>`
145
- case 'scSpecTypeTuple':
146
- return `tuple<${type.value().valueTypes().map(parseParameterType).join()}>`
147
- case 'scSpecTypeUdt':
148
- return `udt<${type.value().name()}>`
149
- default:
150
- return typeName.replace('scSpecType', '').toLowerCase()
151
- }
152
- }
153
-
154
- function parseParameter(param) {
155
- return {
156
- name: param.name().toString(),
157
- type: parseParameterType(param.type())
158
- }
159
- }
@@ -1,79 +0,0 @@
1
- /**
2
- * Minimalistic WASM metadata reader
3
- */
4
- export class WasmSectionReader {
5
- constructor(data) {
6
- this.data = data
7
- }
8
-
9
- /**
10
- * @type {Buffer}
11
- * @private
12
- */
13
- data
14
- /**
15
- * Current reader position
16
- * @type {number}
17
- * @private
18
- */
19
- pointer = 8
20
-
21
- /**
22
- * Read custom metadata sections from raw WASM
23
- * @return {{name: string, contents: Buffer}[]}
24
- */
25
- readCustomSections() {
26
- const sections = []
27
- while (this.pointer < this.data.length) {
28
- const sectionType = this.readUint8()
29
- let length = this.readVarUint32()
30
- if (sectionType === 0) { //accumulate only custom sections
31
- const sectionStart = this.pointer
32
- const name = this.readString()
33
- length -= this.pointer - sectionStart
34
- sections.push({
35
- name,
36
- contents: this.data.subarray(this.pointer, this.pointer + length)
37
- })
38
- }
39
- this.pointer += length
40
- }
41
- return sections
42
- }
43
-
44
- /**
45
- * @return {number}
46
- * @private
47
- */
48
- readUint8() {
49
- return this.data.readUint8(this.pointer++)
50
- }
51
-
52
- /**
53
- * @return {number}
54
- * @private
55
- */
56
- readVarUint32() {
57
- let result = 0
58
- let shift = 0
59
- while (true) {
60
- let byte = this.readUint8()
61
- result |= (byte & 0x7f) << shift
62
- shift += 7
63
- if ((byte & 0x80) === 0)
64
- break
65
- }
66
- return result >>> 0
67
- }
68
-
69
- /**
70
- * @return {string}
71
- * @private
72
- */
73
- readString() {
74
- const length = this.readVarUint32()
75
- const contents = this.data.subarray(this.pointer, this.pointer + length)
76
- this.pointer += length
77
- return contents.toString('utf-8')
78
- }
79
- }
@@ -1,148 +0,0 @@
1
- export class XdrReader {
2
- /**
3
- * @constructor
4
- * @param {Buffer} source - Buffer containing serialized data
5
- */
6
- constructor(source) {
7
- if (!Buffer.isBuffer(source)) {
8
- if (source instanceof Array) {
9
- source = Buffer.from(source)
10
- } else
11
- throw new Error('Source not specified')
12
- }
13
-
14
- this._buffer = source
15
- this._length = source.length
16
- this._index = 0
17
- }
18
-
19
- /**
20
- * @type {Buffer}
21
- * @private
22
- * @readonly
23
- */
24
- _buffer
25
- /**
26
- * @type {Number}
27
- * @private
28
- * @readonly
29
- */
30
- _length
31
- /**
32
- * @type {Number}
33
- * @private
34
- * @readonly
35
- */
36
- _index
37
-
38
- /**
39
- * Check if the reader reached the end of the input buffer
40
- * @return {Boolean}
41
- */
42
- get eof() {
43
- return this._index === this._length
44
- }
45
-
46
- /**
47
- * Advance reader position, check padding and overflow
48
- * @param {Number} size - Bytes to read
49
- * @return {Number} Position to read from
50
- * @private
51
- */
52
- advance(size) {
53
- const from = this._index
54
- // advance cursor position
55
- this._index += size
56
- // check buffer boundaries
57
- if (this._length < this._index)
58
- throw new Error(
59
- 'attempt to read outside the boundary of the buffer'
60
- )
61
- // check that padding is correct for Opaque and String
62
- const padding = 4 - (size % 4 || 4)
63
- if (padding > 0) {
64
- for (let i = 0; i < padding; i++)
65
- if (this._buffer[this._index + i] !== 0)
66
- // all bytes in the padding should be zeros
67
- throw new Error('Invalid padding')
68
- this._index += padding
69
- }
70
- return from
71
- }
72
-
73
- /**
74
- * Reset reader position
75
- * @return {void}
76
- */
77
- rewind() {
78
- this._index = 0
79
- }
80
-
81
- /**
82
- * Read byte array from the buffer
83
- * @param {Number} size - Bytes to read
84
- * @return {Buffer} - Sliced portion of the underlying buffer
85
- */
86
- read(size) {
87
- const from = this.advance(size)
88
- return this._buffer.subarray(from, from + size)
89
- }
90
-
91
- /**
92
- * Read i32 from buffer
93
- * @return {Number}
94
- */
95
- readInt32BE() {
96
- return this._buffer.readInt32BE(this.advance(4))
97
- }
98
-
99
- /**
100
- * Read u32 from buffer
101
- * @return {Number}
102
- */
103
- readUInt32BE() {
104
- return this._buffer.readUInt32BE(this.advance(4))
105
- }
106
-
107
- /**
108
- * Read i64 from buffer
109
- * @return {BigInt}
110
- */
111
- readBigInt64BE() {
112
- return this._buffer.readBigInt64BE(this.advance(8))
113
- }
114
-
115
- /**
116
- * Read u64 from buffer
117
- * @return {BigInt}
118
- */
119
- readBigUInt64BE() {
120
- return this._buffer.readBigUInt64BE(this.advance(8))
121
- }
122
-
123
- /**
124
- * Read float from buffer
125
- * @return {Number}
126
- */
127
- readFloatBE() {
128
- return this._buffer.readFloatBE(this.advance(4))
129
- }
130
-
131
- /**
132
- * Read double from buffer
133
- * @return {Number}
134
- */
135
- readDoubleBE() {
136
- return this._buffer.readDoubleBE(this.advance(8))
137
- }
138
-
139
- /**
140
- * Ensure that input buffer has been consumed in full, otherwise it's a type mismatch
141
- * @return {void}
142
- * @throws {Error}
143
- */
144
- ensureInputConsumed() {
145
- if (this._index !== this._length)
146
- throw new Error(`Invalid XDR contract typecast - source buffer not entirely consumed`)
147
- }
148
- }