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
7f39c554
Commit
7f39c554
authored
Feb 06, 2024
by
Max Alekseenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
post-review fixes
parent
4ccffbeb
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
72 additions
and
45 deletions
+72
-45
swapButton.ts
configs/app/features/swapButton.ts
+26
-8
removeQueryParam.ts
lib/router/removeQueryParam.ts
+3
-2
updateQueryParam.ts
lib/router/updateQueryParam.ts
+3
-2
useAutoConnectWallet.tsx
ui/marketplace/useAutoConnectWallet.tsx
+1
-1
MarketplaceApp.tsx
ui/pages/MarketplaceApp.tsx
+2
-2
LinkExternal.tsx
ui/shared/LinkExternal.tsx
+2
-5
SwapButton.tsx
ui/snippets/topBar/SwapButton.tsx
+23
-19
TopBar.tsx
ui/snippets/topBar/TopBar.tsx
+3
-4
WalletTooltip.tsx
ui/snippets/walletMenu/WalletTooltip.tsx
+9
-2
No files found.
configs/app/features/swapButton.ts
View file @
7f39c554
import
type
{
Feature
}
from
'
./types
'
;
import
type
{
Feature
}
from
'
./types
'
;
import
{
getEnvValue
}
from
'
../utils
'
;
import
{
getEnvValue
}
from
'
../utils
'
;
import
marketplace
from
'
./marketplace
'
;
const
appUrl
=
getEnvValue
(
'
NEXT_PUBLIC_SWAP_BUTTON_URL
'
);
const
value
=
getEnvValue
(
'
NEXT_PUBLIC_SWAP_BUTTON_URL
'
);
const
title
=
'
Swap button
'
;
const
title
=
'
Swap button
'
;
const
config
:
Feature
<
{
appUrl
:
string
}
>
=
(()
=>
{
function
isValidUrl
(
string
:
string
)
{
if
(
appUrl
)
{
try
{
return
Object
.
freeze
({
new
URL
(
string
);
title
,
return
true
;
isEnabled
:
true
,
}
catch
(
error
)
{
appUrl
,
return
false
;
});
}
}
const
config
:
Feature
<
{
dappId
:
string
}
|
{
url
:
string
}
>
=
(()
=>
{
if
(
value
)
{
if
(
isValidUrl
(
value
))
{
return
Object
.
freeze
({
title
,
isEnabled
:
true
,
url
:
value
,
});
}
else
if
(
marketplace
.
isEnabled
)
{
return
Object
.
freeze
({
title
,
isEnabled
:
true
,
dappId
:
value
,
});
}
}
}
return
Object
.
freeze
({
return
Object
.
freeze
({
...
...
lib/router/removeQueryParam.ts
View file @
7f39c554
...
@@ -2,6 +2,7 @@ import type { NextRouter } from 'next/router';
...
@@ -2,6 +2,7 @@ import type { NextRouter } from 'next/router';
export
default
function
removeQueryParam
(
router
:
NextRouter
,
param
:
string
)
{
export
default
function
removeQueryParam
(
router
:
NextRouter
,
param
:
string
)
{
const
{
pathname
,
query
}
=
router
;
const
{
pathname
,
query
}
=
router
;
delete
router
.
query
[
param
];
const
newQuery
=
{
...
query
};
router
.
replace
({
pathname
,
query
},
undefined
,
{
shallow
:
true
});
delete
newQuery
[
param
];
router
.
replace
({
pathname
,
query
:
newQuery
},
undefined
,
{
shallow
:
true
});
}
}
lib/router/updateQueryParam.ts
View file @
7f39c554
...
@@ -2,6 +2,7 @@ import type { NextRouter } from 'next/router';
...
@@ -2,6 +2,7 @@ import type { NextRouter } from 'next/router';
export
default
function
updateQueryParam
(
router
:
NextRouter
,
param
:
string
,
newValue
:
string
)
{
export
default
function
updateQueryParam
(
router
:
NextRouter
,
param
:
string
,
newValue
:
string
)
{
const
{
pathname
,
query
}
=
router
;
const
{
pathname
,
query
}
=
router
;
query
[
param
]
=
newValue
;
const
newQuery
=
{
...
query
};
router
.
replace
({
pathname
,
query
},
undefined
,
{
shallow
:
true
});
newQuery
[
param
]
=
newValue
;
router
.
replace
({
pathname
,
query
:
newQuery
},
undefined
,
{
shallow
:
true
});
}
}
ui/marketplace/use
WalletConnection
.tsx
→
ui/marketplace/use
AutoConnectWallet
.tsx
View file @
7f39c554
...
@@ -5,7 +5,7 @@ import removeQueryParam from 'lib/router/removeQueryParam';
...
@@ -5,7 +5,7 @@ import removeQueryParam from 'lib/router/removeQueryParam';
import
updateQueryParam
from
'
lib/router/updateQueryParam
'
;
import
updateQueryParam
from
'
lib/router/updateQueryParam
'
;
import
useWallet
from
'
ui/snippets/walletMenu/useWallet
'
;
import
useWallet
from
'
ui/snippets/walletMenu/useWallet
'
;
export
default
function
use
Marketplace
Wallet
()
{
export
default
function
use
AutoConnect
Wallet
()
{
const
router
=
useRouter
();
const
router
=
useRouter
();
const
{
isWalletConnected
,
isModalOpen
,
connect
}
=
useWallet
({
source
:
'
Swap button
'
});
const
{
isWalletConnected
,
isModalOpen
,
connect
}
=
useWallet
({
source
:
'
Swap button
'
});
const
isConnectionStarted
=
useRef
(
false
);
const
isConnectionStarted
=
useRef
(
false
);
...
...
ui/pages/MarketplaceApp.tsx
View file @
7f39c554
...
@@ -16,8 +16,8 @@ import * as metadata from 'lib/metadata';
...
@@ -16,8 +16,8 @@ import * as metadata from 'lib/metadata';
import
getQueryParamString
from
'
lib/router/getQueryParamString
'
;
import
getQueryParamString
from
'
lib/router/getQueryParamString
'
;
import
ContentLoader
from
'
ui/shared/ContentLoader
'
;
import
ContentLoader
from
'
ui/shared/ContentLoader
'
;
import
useAutoConnectWallet
from
'
../marketplace/useAutoConnectWallet
'
;
import
useMarketplaceWallet
from
'
../marketplace/useMarketplaceWallet
'
;
import
useMarketplaceWallet
from
'
../marketplace/useMarketplaceWallet
'
;
import
useWalletConnection
from
'
../marketplace/useWalletConnection
'
;
const
feature
=
config
.
features
.
marketplace
;
const
feature
=
config
.
features
.
marketplace
;
const
configUrl
=
feature
.
isEnabled
?
feature
.
configUrl
:
''
;
const
configUrl
=
feature
.
isEnabled
?
feature
.
configUrl
:
''
;
...
@@ -97,7 +97,7 @@ const MarketplaceAppContent = ({ address, data, isPending }: Props) => {
...
@@ -97,7 +97,7 @@ const MarketplaceAppContent = ({ address, data, isPending }: Props) => {
const
MarketplaceApp
=
()
=>
{
const
MarketplaceApp
=
()
=>
{
const
{
address
,
sendTransaction
,
signMessage
,
signTypedData
}
=
useMarketplaceWallet
();
const
{
address
,
sendTransaction
,
signMessage
,
signTypedData
}
=
useMarketplaceWallet
();
use
WalletConnection
();
use
AutoConnectWallet
();
const
apiFetch
=
useApiFetch
();
const
apiFetch
=
useApiFetch
();
const
router
=
useRouter
();
const
router
=
useRouter
();
...
...
ui/shared/LinkExternal.tsx
View file @
7f39c554
...
@@ -10,10 +10,9 @@ interface Props {
...
@@ -10,10 +10,9 @@ interface Props {
children
:
React
.
ReactNode
;
children
:
React
.
ReactNode
;
isLoading
?:
boolean
;
isLoading
?:
boolean
;
variant
?:
'
subtle
'
;
variant
?:
'
subtle
'
;
hideIcon
?:
boolean
;
}
}
const
LinkExternal
=
({
href
,
children
,
className
,
isLoading
,
variant
,
hideIcon
}:
Props
)
=>
{
const
LinkExternal
=
({
href
,
children
,
className
,
isLoading
,
variant
}:
Props
)
=>
{
const
subtleLinkBg
=
useColorModeValue
(
'
gray.100
'
,
'
gray.700
'
);
const
subtleLinkBg
=
useColorModeValue
(
'
gray.100
'
,
'
gray.700
'
);
const
styleProps
:
ChakraProps
=
(()
=>
{
const
styleProps
:
ChakraProps
=
(()
=>
{
...
@@ -60,9 +59,7 @@ const LinkExternal = ({ href, children, className, isLoading, variant, hideIcon
...
@@ -60,9 +59,7 @@ const LinkExternal = ({ href, children, className, isLoading, variant, hideIcon
return
(
return
(
<
Link
className=
{
className
}
{
...
styleProps
}
target=
"_blank"
href=
{
href
}
>
<
Link
className=
{
className
}
{
...
styleProps
}
target=
"_blank"
href=
{
href
}
>
{
children
}
{
children
}
{
!
hideIcon
&&
(
<
IconSvg
name=
"arrows/north-east"
boxSize=
{
4
}
verticalAlign=
"middle"
color=
"gray.400"
flexShrink=
{
0
}
/>
<
IconSvg
name=
"arrows/north-east"
boxSize=
{
4
}
verticalAlign=
"middle"
color=
"gray.400"
flexShrink=
{
0
}
/>
)
}
</
Link
>
</
Link
>
);
);
};
};
...
...
ui/snippets/topBar/SwapButton.tsx
View file @
7f39c554
...
@@ -3,33 +3,37 @@ import React from 'react';
...
@@ -3,33 +3,37 @@ import React from 'react';
import
{
route
}
from
'
nextjs-routes
'
;
import
{
route
}
from
'
nextjs-routes
'
;
import
*
as
regexp
from
'
lib/regex
p
'
;
import
config
from
'
configs/ap
p
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
import
LinkExternal
from
'
ui/shared/LinkExternal
'
;
import
LinkInternal
from
'
ui/shared/LinkInternal
'
;
const
SwapButton
=
({
appUrl
}:
{
appUrl
:
string
})
=>
{
const
feature
=
config
.
features
.
swapButton
;
const
button
=
(
<
Button
variant=
"solid"
size=
"xs"
borderRadius=
"sm"
height=
{
5
}
px=
{
1.5
}
>
const
SwapButton
=
()
=>
{
if
(
!
feature
.
isEnabled
)
{
return
null
;
}
const
href
=
'
url
'
in
feature
?
feature
.
url
:
route
({
pathname
:
'
/apps/[id]
'
,
query
:
{
id
:
feature
.
dappId
,
action
:
'
connect
'
}
});
return
(
<
Button
as=
"a"
href=
{
href
}
target=
{
'
url
'
in
feature
?
'
_blank
'
:
'
_self
'
}
variant=
"solid"
size=
"xs"
borderRadius=
"sm"
height=
{
5
}
px=
{
1.5
}
>
<
IconSvg
name=
"swap"
boxSize=
{
3
}
mr=
{
{
base
:
0
,
sm
:
1
}
}
/>
<
IconSvg
name=
"swap"
boxSize=
{
3
}
mr=
{
{
base
:
0
,
sm
:
1
}
}
/>
<
Box
display=
{
{
base
:
'
none
'
,
sm
:
'
inline
'
}
}
>
<
Box
display=
{
{
base
:
'
none
'
,
sm
:
'
inline
'
}
}
>
Swap
Swap
</
Box
>
</
Box
>
</
Button
>
</
Button
>
);
);
return
regexp
.
URL_PREFIX
.
test
(
appUrl
)
?
(
<
LinkExternal
href=
{
appUrl
}
hideIcon
>
{
button
}
</
LinkExternal
>
)
:
(
<
LinkInternal
href=
{
route
({
pathname
:
'
/apps/[id]
'
,
query
:
{
id
:
appUrl
,
action
:
'
connect
'
}
})
}
display=
"contents"
>
{
button
}
</
LinkInternal
>
);
};
};
export
default
React
.
memo
(
SwapButton
);
export
default
React
.
memo
(
SwapButton
);
ui/snippets/topBar/TopBar.tsx
View file @
7f39c554
...
@@ -8,14 +8,13 @@ import SwapButton from './SwapButton';
...
@@ -8,14 +8,13 @@ import SwapButton from './SwapButton';
import
TopBarStats
from
'
./TopBarStats
'
;
import
TopBarStats
from
'
./TopBarStats
'
;
const
feature
=
config
.
features
.
swapButton
;
const
feature
=
config
.
features
.
swapButton
;
const
appUrl
=
feature
.
isEnabled
&&
feature
.
appUrl
;
const
TopBar
=
()
=>
{
const
TopBar
=
()
=>
{
const
bgColor
=
useColorModeValue
(
'
gray.50
'
,
'
whiteAlpha.100
'
);
const
bgColor
=
useColorModeValue
(
'
gray.50
'
,
'
whiteAlpha.100
'
);
return
(
return
(
<
Flex
<
Flex
height=
"34px"
py=
{
2
}
px=
{
6
}
px=
{
6
}
bgColor=
{
bgColor
}
bgColor=
{
bgColor
}
justifyContent=
"space-between"
justifyContent=
"space-between"
...
@@ -23,9 +22,9 @@ const TopBar = () => {
...
@@ -23,9 +22,9 @@ const TopBar = () => {
>
>
<
TopBarStats
/>
<
TopBarStats
/>
<
Flex
alignItems=
"center"
>
<
Flex
alignItems=
"center"
>
{
appUrl
&&
(
{
feature
.
isEnabled
&&
(
<>
<>
<
SwapButton
appUrl=
{
appUrl
}
/>
<
SwapButton
/>
<
Divider
mr=
{
3
}
ml=
{
{
base
:
2
,
sm
:
3
}
}
height=
{
4
}
orientation=
"vertical"
/>
<
Divider
mr=
{
3
}
ml=
{
{
base
:
2
,
sm
:
3
}
}
height=
{
4
}
orientation=
"vertical"
/>
</>
</>
)
}
)
}
...
...
ui/snippets/walletMenu/WalletTooltip.tsx
View file @
7f39c554
...
@@ -33,17 +33,24 @@ const WalletTooltip = ({ children, isDisabled, isMobile }: Props) => {
...
@@ -33,17 +33,24 @@ const WalletTooltip = ({ children, isDisabled, isMobile }: Props) => {
const
isTooltipShowAction
=
router
.
query
.
action
===
'
tooltip
'
;
const
isTooltipShowAction
=
router
.
query
.
action
===
'
tooltip
'
;
const
isConnectWalletAction
=
router
.
query
.
action
===
'
connect
'
;
const
isConnectWalletAction
=
router
.
query
.
action
===
'
connect
'
;
const
needToShow
=
(
!
wasShown
&&
!
isConnectWalletAction
)
||
isTooltipShowAction
;
const
needToShow
=
(
!
wasShown
&&
!
isConnectWalletAction
)
||
isTooltipShowAction
;
let
timer1
:
ReturnType
<
typeof
setTimeout
>
;
let
timer2
:
ReturnType
<
typeof
setTimeout
>
;
if
(
!
isDisabled
&&
isMarketplacePage
&&
needToShow
)
{
if
(
!
isDisabled
&&
isMarketplacePage
&&
needToShow
)
{
setTimeout
(()
=>
{
timer1
=
setTimeout
(()
=>
{
setIsTooltipShown
.
on
();
setIsTooltipShown
.
on
();
window
.
localStorage
.
setItem
(
localStorageKey
,
'
true
'
);
window
.
localStorage
.
setItem
(
localStorageKey
,
'
true
'
);
setTimeout
(()
=>
setIsTooltipShown
.
off
(),
5
*
SECOND
);
timer2
=
setTimeout
(()
=>
setIsTooltipShown
.
off
(),
5
*
SECOND
);
if
(
isTooltipShowAction
)
{
if
(
isTooltipShowAction
)
{
removeQueryParam
(
router
,
'
action
'
);
removeQueryParam
(
router
,
'
action
'
);
}
}
},
isTooltipShowAction
?
0
:
SECOND
);
},
isTooltipShowAction
?
0
:
SECOND
);
}
}
return
()
=>
{
clearTimeout
(
timer1
);
clearTimeout
(
timer2
);
};
},
[
setIsTooltipShown
,
localStorageKey
,
isDisabled
,
router
]);
},
[
setIsTooltipShown
,
localStorageKey
,
isDisabled
,
router
]);
return
(
return
(
...
...
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