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
995e5630
Commit
995e5630
authored
Jul 23, 2024
by
Max Alekseenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move get gas button to a separate file and refactor
parent
589d58f5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
61 deletions
+73
-61
AddressBalance.tsx
ui/address/details/AddressBalance.tsx
+4
-61
GetGasButton.tsx
ui/address/details/GetGasButton.tsx
+69
-0
No files found.
ui/address/details/AddressBalance.tsx
View file @
995e5630
import
{
Image
}
from
'
@chakra-ui/react
'
;
import
{
useQueryClient
}
from
'
@tanstack/react-query
'
;
import
{
useQueryClient
}
from
'
@tanstack/react-query
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
type
{
SocketMessage
}
from
'
lib/socket/types
'
;
import
type
{
SocketMessage
}
from
'
lib/socket/types
'
;
import
type
{
Address
}
from
'
types/api/address
'
;
import
type
{
Address
}
from
'
types/api/address
'
;
import
{
route
}
from
'
nextjs-routes
'
;
import
config
from
'
configs/app
'
;
import
config
from
'
configs/app
'
;
import
{
getResourceKey
}
from
'
lib/api/useApiQuery
'
;
import
{
getResourceKey
}
from
'
lib/api/useApiQuery
'
;
import
getCurrencyValue
from
'
lib/getCurrencyValue
'
;
import
getCurrencyValue
from
'
lib/getCurrencyValue
'
;
import
*
as
mixpanel
from
'
lib/mixpanel/index
'
;
import
useSocketChannel
from
'
lib/socket/useSocketChannel
'
;
import
useSocketChannel
from
'
lib/socket/useSocketChannel
'
;
import
useSocketMessage
from
'
lib/socket/useSocketMessage
'
;
import
useSocketMessage
from
'
lib/socket/useSocketMessage
'
;
import
{
currencyUnits
}
from
'
lib/units
'
;
import
{
currencyUnits
}
from
'
lib/units
'
;
import
CurrencyValue
from
'
ui/shared/CurrencyValue
'
;
import
CurrencyValue
from
'
ui/shared/CurrencyValue
'
;
import
*
as
DetailsInfoItem
from
'
ui/shared/DetailsInfoItem
'
;
import
*
as
DetailsInfoItem
from
'
ui/shared/DetailsInfoItem
'
;
import
LinkExternal
from
'
ui/shared/links/LinkExternal
'
;
import
LinkInternal
from
'
ui/shared/links/LinkInternal
'
;
import
NativeTokenIcon
from
'
ui/shared/NativeTokenIcon
'
;
import
NativeTokenIcon
from
'
ui/shared/NativeTokenIcon
'
;
import
TextSeparator
from
'
ui/shared/TextSeparator
'
;
const
getGasFeature
=
config
.
features
.
getGasButton
;
import
GetGasButton
from
'
./GetGasButton
'
;
interface
Props
{
interface
Props
{
data
:
Pick
<
Address
,
'
block_number_balance_updated_at
'
|
'
coin_balance
'
|
'
hash
'
|
'
exchange_rate
'
|
'
is_contract
'
>
;
data
:
Pick
<
Address
,
'
block_number_balance_updated_at
'
|
'
coin_balance
'
|
'
hash
'
|
'
exchange_rate
'
|
'
is_contract
'
>
;
...
@@ -81,60 +74,8 @@ const AddressBalance = ({ data, isLoading }: Props) => {
...
@@ -81,60 +74,8 @@ const AddressBalance = ({ data, isLoading }: Props) => {
const
accuracyUsd
=
2
;
const
accuracyUsd
=
2
;
const
accuracy
=
8
;
const
accuracy
=
8
;
const
onGetGasClick
=
React
.
useCallback
(()
=>
{
mixpanel
.
logEvent
(
mixpanel
.
EventTypes
.
BUTTON_CLICK
,
{
Content
:
'
Get gas
'
,
Source
:
'
address
'
});
},
[]);
let
getGasButton
=
null
;
const
{
usd
:
usdResult
}
=
getCurrencyValue
({
value
,
accuracy
,
accuracyUsd
,
exchangeRate
,
decimals
});
const
{
usd
:
usdResult
}
=
getCurrencyValue
({
value
,
accuracy
,
accuracyUsd
,
exchangeRate
,
decimals
});
if
(
getGasFeature
.
isEnabled
&&
!
data
?.
is_contract
&&
Number
(
usdResult
)
<
getGasFeature
.
usdThreshold
)
{
const
buttonContent
=
(
<>
{
getGasFeature
.
logoUrl
&&
(
<
Image
src=
{
getGasFeature
.
logoUrl
}
alt=
{
getGasFeature
.
name
}
boxSize=
{
5
}
mr=
{
2
}
borderRadius=
"4px"
overflow=
"hidden"
/>
)
}
{
getGasFeature
.
name
}
</>
);
const
linkProps
=
{
display
:
'
flex
'
,
alignItems
:
'
center
'
,
fontSize
:
'
sm
'
,
lineHeight
:
5
,
onClick
:
onGetGasClick
,
};
try
{
const
getGasUrl
=
new
URL
(
getGasFeature
.
url
);
getGasUrl
.
searchParams
.
append
(
'
utm_source
'
,
'
blockscout
'
);
getGasUrl
.
searchParams
.
append
(
'
utm_medium
'
,
'
address
'
);
const
dappId
=
getGasFeature
.
dappId
;
getGasButton
=
(
<>
<
TextSeparator
mx=
{
2
}
color=
"gray.500"
/>
{
typeof
dappId
===
'
string
'
?
(
<
LinkInternal
href=
{
route
({
pathname
:
'
/apps/[id]
'
,
query
:
{
id
:
dappId
,
url
:
getGasUrl
.
toString
()
}
})
}
{
...
linkProps
}
>
{
buttonContent
}
</
LinkInternal
>
)
:
(
<
LinkExternal
href=
{
getGasUrl
.
toString
()
}
{
...
linkProps
}
>
{
buttonContent
}
</
LinkExternal
>
)
}
</>
);
}
catch
(
error
)
{}
}
return
(
return
(
<>
<>
<
DetailsInfoItem
.
Label
<
DetailsInfoItem
.
Label
...
@@ -155,7 +96,9 @@ const AddressBalance = ({ data, isLoading }: Props) => {
...
@@ -155,7 +96,9 @@ const AddressBalance = ({ data, isLoading }: Props) => {
flexWrap=
"wrap"
flexWrap=
"wrap"
isLoading=
{
isLoading
}
isLoading=
{
isLoading
}
/>
/>
{
!
isLoading
&&
getGasButton
}
{
!
isLoading
&&
(
<
GetGasButton
usdValue=
{
usdResult
}
isContract=
{
data
?.
is_contract
}
/>
)
}
</
DetailsInfoItem
.
Value
>
</
DetailsInfoItem
.
Value
>
</>
</>
);
);
...
...
ui/address/details/GetGasButton.tsx
0 → 100644
View file @
995e5630
import
{
Image
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
{
route
}
from
'
nextjs-routes
'
;
import
config
from
'
configs/app
'
;
import
*
as
mixpanel
from
'
lib/mixpanel/index
'
;
import
LinkExternal
from
'
ui/shared/links/LinkExternal
'
;
import
LinkInternal
from
'
ui/shared/links/LinkInternal
'
;
import
TextSeparator
from
'
ui/shared/TextSeparator
'
;
const
getGasFeature
=
config
.
features
.
getGasButton
;
interface
Props
{
usdValue
?:
string
;
isContract
?:
boolean
;
}
const
GetGasButton
=
({
usdValue
,
isContract
}:
Props
)
=>
{
const
onGetGasClick
=
React
.
useCallback
(()
=>
{
mixpanel
.
logEvent
(
mixpanel
.
EventTypes
.
BUTTON_CLICK
,
{
Content
:
'
Get gas
'
,
Source
:
'
address
'
});
},
[]);
if
(
getGasFeature
.
isEnabled
&&
!
isContract
&&
usdValue
&&
Number
(
usdValue
)
<
getGasFeature
.
usdThreshold
)
{
try
{
const
dappId
=
getGasFeature
.
dappId
;
const
urlObj
=
new
URL
(
getGasFeature
.
url
);
urlObj
.
searchParams
.
append
(
'
utm_source
'
,
'
blockscout
'
);
urlObj
.
searchParams
.
append
(
'
utm_medium
'
,
'
address
'
);
const
url
=
urlObj
.
toString
();
const
isInternal
=
typeof
dappId
===
'
string
'
;
const
Link
=
isInternal
?
LinkInternal
:
LinkExternal
;
const
href
=
isInternal
?
route
({
pathname
:
'
/apps/[id]
'
,
query
:
{
id
:
dappId
,
url
}
})
:
url
;
return
(
<>
<
TextSeparator
mx=
{
2
}
color=
"gray.500"
/>
<
Link
href=
{
href
}
display=
"flex"
alignItems=
"center"
fontSize=
"sm"
lineHeight=
{
5
}
onClick=
{
onGetGasClick
}
>
{
getGasFeature
.
logoUrl
&&
(
<
Image
src=
{
getGasFeature
.
logoUrl
}
alt=
{
getGasFeature
.
name
}
boxSize=
{
5
}
mr=
{
2
}
borderRadius=
"4px"
overflow=
"hidden"
/>
)
}
{
getGasFeature
.
name
}
</
Link
>
</>
);
}
catch
(
error
)
{}
}
return
null
;
};
export
default
GetGasButton
;
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