@stellar-expert/ui-framework 1.9.2 → 1.9.3
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/contract/sc-val.js +37 -20
- package/contract/sc-val.scss +3 -0
- package/index.js +1 -0
- package/package.json +1 -1
package/contract/sc-val.js
CHANGED
|
@@ -3,30 +3,37 @@ import {xdr, scValToBigInt} from '@stellar/stellar-base'
|
|
|
3
3
|
import {xdrParserUtils} from '@stellar-expert/tx-meta-effects-parser'
|
|
4
4
|
import {shortenString} from '@stellar-expert/formatter'
|
|
5
5
|
import {AccountAddress} from '../account/account-address'
|
|
6
|
+
import './sc-val.scss'
|
|
6
7
|
|
|
7
|
-
export function ScVal({value, nested = false}) {
|
|
8
|
+
export const ScVal = React.memo(function ScVal({value, nested = false, indent = false}) {
|
|
8
9
|
if (!nested)
|
|
9
|
-
return <code className="sc-val"><ScVal value={value} nested/></code>
|
|
10
|
+
return <code className="sc-val"><ScVal value={value} indent={indent} nested/></code>
|
|
10
11
|
if (!value)
|
|
11
12
|
return 'void'
|
|
12
13
|
if (typeof value === 'string') {
|
|
13
14
|
value = xdr.ScVal.fromXDR(value, 'base64')
|
|
14
15
|
}
|
|
15
16
|
if (value instanceof Array)
|
|
16
|
-
return <>[{value.map((v, i) => <
|
|
17
|
+
return <>[{value.map((v, i) => <ScValStruct key={i} indent={indent} separate={value.length - i}>
|
|
18
|
+
<ScVal value={v} indent={indent} nested/>
|
|
19
|
+
</ScValStruct>)}]</>
|
|
20
|
+
const val = value._value
|
|
17
21
|
switch (value._arm) {
|
|
18
22
|
case 'vec':
|
|
19
|
-
return <>[{
|
|
23
|
+
return <>[{val.map((v, i) => <ScValStruct key={i} indent={indent} separate={val.length - i}>
|
|
24
|
+
<ScVal value={v} indent={indent} nested/>
|
|
25
|
+
</ScValStruct>)}]</>
|
|
20
26
|
case 'map':
|
|
21
|
-
return <>{
|
|
22
|
-
{
|
|
23
|
-
<
|
|
27
|
+
return <>{{val.map((kv, i) =>
|
|
28
|
+
<ScValStruct key={i} indent={indent} separate={val.length - i}>
|
|
29
|
+
<ScVal value={kv.key()} indent={indent} nested/>: <ScVal value={kv.val()} indent={indent} nested/>
|
|
30
|
+
</ScValStruct>)}
|
|
24
31
|
}</>
|
|
25
32
|
case 'b':
|
|
26
|
-
return <>{
|
|
33
|
+
return <>{val.toString()}<ScValType type="bool"/></>
|
|
27
34
|
case 'i32':
|
|
28
35
|
case 'u32':
|
|
29
|
-
return <>{
|
|
36
|
+
return <>{val}<ScValType type={value._arm}/></>
|
|
30
37
|
case 'i256':
|
|
31
38
|
case 'u256':
|
|
32
39
|
case 'i128':
|
|
@@ -37,34 +44,44 @@ export function ScVal({value, nested = false}) {
|
|
|
37
44
|
case 'duration':
|
|
38
45
|
return <>{scValToBigInt(value).toString()}<ScValType type={value._arm}/></>
|
|
39
46
|
case 'address':
|
|
40
|
-
switch (
|
|
47
|
+
switch (val._arm) {
|
|
41
48
|
case 'accountId':
|
|
42
|
-
return <AccountAddress account={xdrParserUtils.xdrParseAccountAddress(
|
|
49
|
+
return <AccountAddress account={xdrParserUtils.xdrParseAccountAddress(val.value())}/>
|
|
43
50
|
case 'contractId':
|
|
44
|
-
return <AccountAddress account={xdrParserUtils.xdrParseContractAddress(
|
|
51
|
+
return <AccountAddress account={xdrParserUtils.xdrParseContractAddress(val.value())}/>
|
|
45
52
|
}
|
|
46
53
|
return <span className="dimmed">(unsupported address)</span>
|
|
47
54
|
case 'bytes':
|
|
48
|
-
const asBytes =
|
|
55
|
+
const asBytes = val.toString('base64')
|
|
49
56
|
return <><span className="condensed">{shortenString(asBytes, 86)}</span><ScValType type="bytes"/></>
|
|
50
57
|
case 'str':
|
|
51
58
|
case 'sym':
|
|
52
|
-
return <>"{
|
|
59
|
+
return <>"{val.toString()}"<ScValType type={value._arm}/></>
|
|
53
60
|
case 'nonceKey':
|
|
54
|
-
return <>{
|
|
61
|
+
return <>{val.nonce()._value.toString()}<ScValType type="nonce"/></>
|
|
55
62
|
case 'instance':
|
|
56
|
-
return <>{
|
|
63
|
+
return <>{val.executable.wasmHash().toString('hex')}<ScValType type="wasm"/></>
|
|
57
64
|
case 'error':
|
|
58
|
-
|
|
65
|
+
const errMessage = value.toXDR('base64')
|
|
66
|
+
return <><span className="condensed" title={errMessage}>{shortenString(errMessage, 50)}</span><ScValType type="error"/></>
|
|
59
67
|
case 'contractId':
|
|
60
68
|
return <AccountAddress account={xdrParserUtils.xdrParseContractAddress(value._value)}/>
|
|
61
69
|
default:
|
|
62
70
|
if (value.switch().name === 'scvVoid')
|
|
63
|
-
return '
|
|
71
|
+
return '()'
|
|
64
72
|
return <span className="dimmed">(unknown)</span>
|
|
65
73
|
}
|
|
66
|
-
}
|
|
74
|
+
})
|
|
67
75
|
|
|
68
|
-
const ScValType = React.memo(function ({type}) {
|
|
76
|
+
const ScValType = React.memo(function ScValType({type}) {
|
|
69
77
|
return <sub className="dimmed text-tiny" style={{padding: '0 0.2em'}}>{type}</sub>
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
const ScValStruct = React.memo(function ScValStruct({indent, children, separate}) {
|
|
81
|
+
const separator = separate > 1 ? <>, </> : null
|
|
82
|
+
if (!indent)
|
|
83
|
+
return <>{children}{separator}</>
|
|
84
|
+
return <div className="block-indent">
|
|
85
|
+
{children}{separator}
|
|
86
|
+
</div>
|
|
70
87
|
})
|
package/index.js
CHANGED