@stellar-expert/ui-framework 1.9.2 → 1.9.4

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