Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
18d94efa
Commit
18d94efa
authored
Oct 31, 2024
by
isstuev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support wei variable in interpretation
parent
d5863de0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
13 deletions
+25
-13
TxInterpretation.tsx
ui/shared/tx/interpretation/TxInterpretation.tsx
+22
-11
utils.test.ts
ui/shared/tx/interpretation/utils.test.ts
+1
-1
utils.ts
ui/shared/tx/interpretation/utils.ts
+2
-1
No files found.
ui/shared/tx/interpretation/TxInterpretation.tsx
View file @
18d94efa
...
...
@@ -19,7 +19,14 @@ import EnsEntity from 'ui/shared/entities/ens/EnsEntity';
import
TokenEntity
from
'
ui/shared/entities/token/TokenEntity
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
import
{
extractVariables
,
getStringChunks
,
fillStringVariables
,
checkSummary
,
NATIVE_COIN_SYMBOL_VAR_NAME
}
from
'
./utils
'
;
import
{
extractVariables
,
getStringChunks
,
fillStringVariables
,
checkSummary
,
NATIVE_COIN_SYMBOL_VAR_NAME
,
WEI_VAR_NAME
,
}
from
'
./utils
'
;
type
Props
=
{
summary
?:
TxInterpretationSummary
;
...
...
@@ -152,19 +159,23 @@ const TxInterpretation = ({ summary, isLoading, addressDataMap, className }: Pro
<
IconSvg
name=
"lightning"
boxSize=
{
5
}
color=
"text_secondary"
mr=
{
1
}
verticalAlign=
"text-top"
/>
</
Tooltip
>
{
chunks
.
map
((
chunk
,
index
)
=>
{
return
(
<
chakra
.
span
key=
{
chunk
+
index
}
>
<
chakra
.
span
color=
"text_secondary"
>
{
chunk
.
trim
()
+
(
chunk
.
trim
()
&&
variablesNames
[
index
]
?
'
'
:
''
)
}
</
chakra
.
span
>
{
index
<
variablesNames
.
length
&&
(
variablesNames
[
index
]
===
NATIVE_COIN_SYMBOL_VAR_NAME
?
<
chakra
.
span
>
{
currencyUnits
.
ether
+
'
'
}
</
chakra
.
span
>
:
(
let
content
=
null
;
if
(
variablesNames
[
index
]
===
NATIVE_COIN_SYMBOL_VAR_NAME
)
{
content
=
<
chakra
.
span
>
{
currencyUnits
.
ether
+
'
'
}
</
chakra
.
span
>;
}
else
if
(
variablesNames
[
index
]
===
WEI_VAR_NAME
)
{
content
=
<
chakra
.
span
>
{
currencyUnits
.
wei
+
'
'
}
</
chakra
.
span
>;
}
else
{
content
=
(
<
TxInterpretationElementByType
variable=
{
variables
[
variablesNames
[
index
]]
as
NonStringTxInterpretationVariable
}
addressDataMap=
{
addressDataMap
}
/>
)
)
}
);
}
return
(
<
chakra
.
span
key=
{
chunk
+
index
}
>
<
chakra
.
span
color=
"text_secondary"
>
{
chunk
.
trim
()
+
(
chunk
.
trim
()
&&
variablesNames
[
index
]
?
'
'
:
''
)
}
</
chakra
.
span
>
{
index
<
variablesNames
.
length
&&
content
}
</
chakra
.
span
>
);
})
}
...
...
ui/shared/tx/interpretation/utils.test.ts
View file @
18d94efa
...
...
@@ -13,7 +13,7 @@ it('split string without capturing variables', () => {
});
it
(
'
checks that summary is valid
'
,
()
=>
{
const
result
=
checkSummary
(
'
{foo} {native} {bar}
'
,
{
foo
:
{
type
:
'
string
'
,
value
:
'
foo
'
},
bar
:
{
type
:
'
string
'
,
value
:
'
bar
'
}
});
const
result
=
checkSummary
(
'
{foo} {native} {bar}
{wei}
'
,
{
foo
:
{
type
:
'
string
'
,
value
:
'
foo
'
},
bar
:
{
type
:
'
string
'
,
value
:
'
bar
'
}
});
expect
(
result
).
toBe
(
true
);
});
...
...
ui/shared/tx/interpretation/utils.ts
View file @
18d94efa
...
...
@@ -6,6 +6,7 @@ import type { TxInterpretationVariable } from 'types/api/txInterpretation';
export
const
VAR_REGEXP
=
/
\{(?:[^
}
]
+
)\}
/g
;
export
const
NATIVE_COIN_SYMBOL_VAR_NAME
=
'
native
'
;
export
const
WEI_VAR_NAME
=
'
wei
'
;
export
function
extractVariables
(
templateString
:
string
)
{
...
...
@@ -24,7 +25,7 @@ export function checkSummary(template: string, variables: Record<string, TxInter
const
variablesNames
=
extractVariables
(
template
);
let
result
=
true
;
for
(
const
name
of
variablesNames
)
{
if
(
name
===
NATIVE_COIN_SYMBOL_VAR_NAME
)
{
if
(
name
===
NATIVE_COIN_SYMBOL_VAR_NAME
||
name
===
WEI_VAR_NAME
)
{
continue
;
}
if
(
!
variables
[
name
]
||
variables
[
name
].
value
===
undefined
||
variables
[
name
].
value
===
null
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment