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
34d8a577
Unverified
Commit
34d8a577
authored
Feb 12, 2024
by
Igor Stuev
Committed by
GitHub
Feb 12, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1585 from blockscout/check-summary
check template summary
parents
fec9e20d
8aca9e7e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
2 deletions
+31
-2
TxInterpretation.tsx
ui/tx/interpretation/TxInterpretation.tsx
+5
-1
utils.test.ts
ui/tx/interpretation/utils.test.ts
+13
-1
utils.ts
ui/tx/interpretation/utils.ts
+13
-0
No files found.
ui/tx/interpretation/TxInterpretation.tsx
View file @
34d8a577
...
...
@@ -17,7 +17,7 @@ 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
,
NATIVE_COIN_SYMBOL_VAR_NAME
}
from
'
./utils
'
;
import
{
extractVariables
,
getStringChunks
,
fillStringVariables
,
checkSummary
,
NATIVE_COIN_SYMBOL_VAR_NAME
}
from
'
./utils
'
;
type
Props
=
{
summary
?:
TxInterpretationSummary
;
...
...
@@ -116,6 +116,10 @@ const TxInterpretation = ({ summary, isLoading, className }: Props) => {
const
template
=
summary
.
summary_template
;
const
variables
=
summary
.
summary_template_variables
;
if
(
!
checkSummary
(
template
,
variables
))
{
return
null
;
}
const
intermediateResult
=
fillStringVariables
(
template
,
variables
);
const
variablesNames
=
extractVariables
(
intermediateResult
);
...
...
ui/tx/interpretation/utils.test.ts
View file @
34d8a577
import
{
extractVariables
,
getStringChunks
}
from
'
./utils
'
;
import
{
extractVariables
,
getStringChunks
,
checkSummary
}
from
'
./utils
'
;
const
template
=
'
{action_type} {source_amount} {native} into {destination_amount} {destination_token}
'
;
...
...
@@ -11,3 +11,15 @@ it('split string without capturing variables', () => {
const
result
=
getStringChunks
(
template
);
expect
(
result
).
toEqual
([
''
,
'
'
,
'
'
,
'
into
'
,
'
'
,
''
]);
});
it
(
'
checks that summary is valid
'
,
()
=>
{
const
result
=
checkSummary
(
'
{foo} {bar}
'
,
{
foo
:
{
type
:
'
string
'
,
value
:
'
foo
'
},
bar
:
{
type
:
'
string
'
,
value
:
'
bar
'
}
});
expect
(
result
).
toBe
(
true
);
});
it
(
'
checks that summary is invalid
'
,
()
=>
{
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore:
const
result
=
checkSummary
(
'
{foo} {bar}
'
,
{
foo
:
{
type
:
'
string
'
,
value
:
null
},
bar
:
{
type
:
'
string
'
,
value
:
'
bar
'
}
});
expect
(
result
).
toBe
(
false
);
});
ui/tx/interpretation/utils.ts
View file @
34d8a577
...
...
@@ -20,6 +20,19 @@ export function getStringChunks(template: string) {
return
template
.
split
(
VAR_REGEXP
);
}
export
function
checkSummary
(
template
:
string
,
variables
:
Record
<
string
,
TxInterpretationVariable
>
)
{
const
variablesNames
=
extractVariables
(
template
);
let
result
=
true
;
for
(
const
name
of
variablesNames
)
{
if
(
!
variables
[
name
]
||
variables
[
name
].
value
===
undefined
||
variables
[
name
].
value
===
null
)
{
result
=
false
;
break
;
}
}
return
result
;
}
export
function
fillStringVariables
(
template
:
string
,
variables
:
Record
<
string
,
TxInterpretationVariable
>
)
{
const
variablesNames
=
extractVariables
(
template
);
...
...
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