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
9306b500
Commit
9306b500
authored
Dec 25, 2023
by
isstuev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add native var
parent
11678896
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
6 deletions
+13
-6
TxInterpretation.tsx
ui/tx/interpretation/TxInterpretation.tsx
+8
-3
utils.test.ts
ui/tx/interpretation/utils.test.ts
+2
-2
utils.ts
ui/tx/interpretation/utils.ts
+3
-1
No files found.
ui/tx/interpretation/TxInterpretation.tsx
View file @
9306b500
...
@@ -5,13 +5,14 @@ import React from 'react';
...
@@ -5,13 +5,14 @@ import React from 'react';
import
type
{
TxInterpretationResponse
,
TxInterpretationVariable
}
from
'
types/api/txInterpretation
'
;
import
type
{
TxInterpretationResponse
,
TxInterpretationVariable
}
from
'
types/api/txInterpretation
'
;
import
config
from
'
configs/app
'
;
import
actionIcon
from
'
icons/action.svg
'
;
import
actionIcon
from
'
icons/action.svg
'
;
import
type
{
ResourceError
}
from
'
lib/api/resources
'
;
import
type
{
ResourceError
}
from
'
lib/api/resources
'
;
import
dayjs
from
'
lib/date/dayjs
'
;
import
dayjs
from
'
lib/date/dayjs
'
;
import
AddressEntity
from
'
ui/shared/entities/address/AddressEntity
'
;
import
AddressEntity
from
'
ui/shared/entities/address/AddressEntity
'
;
import
TokenEntity
from
'
ui/shared/entities/token/TokenEntity
'
;
import
TokenEntity
from
'
ui/shared/entities/token/TokenEntity
'
;
import
{
extractVariables
,
getStringChunks
}
from
'
./utils
'
;
import
{
extractVariables
,
getStringChunks
,
NATIVE_COIN_SYMBOL_VAR_NAME
}
from
'
./utils
'
;
type
Props
=
{
type
Props
=
{
query
:
UseQueryResult
<
TxInterpretationResponse
,
ResourceError
>
;
query
:
UseQueryResult
<
TxInterpretationResponse
,
ResourceError
>
;
...
@@ -54,8 +55,12 @@ const TxInterpretation = ({ query, className }: Props) => {
...
@@ -54,8 +55,12 @@ const TxInterpretation = ({ query, className }: Props) => {
{
chunks
.
map
((
chunk
,
index
)
=>
{
{
chunks
.
map
((
chunk
,
index
)
=>
{
return
(
return
(
<>
<>
<
Text
whiteSpace=
"pre"
>
{
chunk
}
</
Text
>
<
Text
whiteSpace=
"pre"
>
{
chunk
.
trim
()
+
'
'
}
</
Text
>
{
index
<
chunks
.
length
-
1
&&
<
TxInterpretationElementByType
{
...
variables
[
variablesNames
[
index
]]
}
/>
}
{
index
<
chunks
.
length
-
1
&&
(
variablesNames
[
index
]
===
NATIVE_COIN_SYMBOL_VAR_NAME
?
<
Text
>
{
config
.
chain
.
currency
.
symbol
}
</
Text
>
:
<
TxInterpretationElementByType
{
...
variables
[
variablesNames
[
index
]]
}
/>
)
}
</>
</>
);
);
})
}
})
}
...
...
ui/tx/interpretation/utils.test.ts
View file @
9306b500
import
{
extractVariables
,
checkTemplate
}
from
'
./utils
'
;
import
{
extractVariables
,
checkTemplate
}
from
'
./utils
'
;
const
template
=
'
{action_type} {source_amount}
Ether
into {destination_amount} {destination_token}
'
;
const
template
=
'
{action_type} {source_amount}
{native}
into {destination_amount} {destination_token}
'
;
it
(
'
extracts variables names
'
,
()
=>
{
it
(
'
extracts variables names
'
,
()
=>
{
const
result
=
extractVariables
(
template
);
const
result
=
extractVariables
(
template
);
expect
(
result
).
toEqual
([
'
action_type
'
,
'
source_amount
'
,
'
destination_amount
'
,
'
destination_token
'
]);
expect
(
result
).
toEqual
([
'
action_type
'
,
'
source_amount
'
,
'
native
'
,
'
destination_amount
'
,
'
destination_token
'
]);
});
});
it
(
'
check template true
'
,
()
=>
{
it
(
'
check template true
'
,
()
=>
{
...
...
ui/tx/interpretation/utils.ts
View file @
9306b500
...
@@ -4,6 +4,8 @@ import type { TxInterpretationSummary } from 'types/api/txInterpretation';
...
@@ -4,6 +4,8 @@ import type { TxInterpretationSummary } from 'types/api/txInterpretation';
// eslint-disable-next-line regexp/no-useless-non-capturing-group
// eslint-disable-next-line regexp/no-useless-non-capturing-group
export
const
VAR_REGEXP
=
/
\{(?:[^
}
]
+
)\}
/g
;
export
const
VAR_REGEXP
=
/
\{(?:[^
}
]
+
)\}
/g
;
export
const
NATIVE_COIN_SYMBOL_VAR_NAME
=
'
native
'
;
export
function
extractVariables
(
templateString
:
string
)
{
export
function
extractVariables
(
templateString
:
string
)
{
const
matches
=
templateString
.
match
(
VAR_REGEXP
);
const
matches
=
templateString
.
match
(
VAR_REGEXP
);
...
@@ -22,7 +24,7 @@ export function checkTemplate(summary: TxInterpretationSummary) {
...
@@ -22,7 +24,7 @@ export function checkTemplate(summary: TxInterpretationSummary) {
const
variablesNames
=
extractVariables
(
summary
.
summary_template
);
const
variablesNames
=
extractVariables
(
summary
.
summary_template
);
for
(
const
name
of
variablesNames
)
{
for
(
const
name
of
variablesNames
)
{
if
(
!
summary
.
summary_template_variables
[
name
])
{
if
(
name
!==
NATIVE_COIN_SYMBOL_VAR_NAME
&&
!
summary
.
summary_template_variables
[
name
])
{
return
false
;
return
false
;
}
}
}
}
...
...
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