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
7ea03ef8
Commit
7ea03ef8
authored
May 28, 2024
by
Max Alekseenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move app url logic to separate file
parent
ce259c4d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
54 deletions
+60
-54
utils.ts
ui/marketplace/utils.ts
+58
-0
MarketplaceApp.tsx
ui/pages/MarketplaceApp.tsx
+2
-54
No files found.
ui/marketplace/utils.ts
0 → 100644
View file @
7ea03ef8
import
type
{
NextRouter
}
from
'
next/router
'
;
import
getQueryParamString
from
'
lib/router/getQueryParamString
'
;
import
removeQueryParam
from
'
lib/router/removeQueryParam
'
;
export
function
getAppUrl
(
url
:
string
|
undefined
,
router
:
NextRouter
)
{
if
(
!
url
)
{
return
;
}
try
{
// get the custom url from the query
const
customUrl
=
getQueryParamString
(
router
.
query
.
url
);
if
(
customUrl
)
{
const
customOrigin
=
new
URL
(
customUrl
).
origin
;
const
appOrigin
=
new
URL
(
url
).
origin
;
if
(
customOrigin
===
appOrigin
)
{
return
customUrl
;
}
else
{
removeQueryParam
(
router
,
'
url
'
);
}
}
}
catch
(
err
)
{}
try
{
// get hash and params (using asPath to avoid conflicts with dynamic route params)
const
[
,
queryAndHash
]
=
router
.
asPath
.
split
(
'
?
'
);
const
[
queryString
,
hash
]
=
queryAndHash
?
queryAndHash
.
split
(
'
#
'
)
:
[
''
,
''
];
const
customHash
=
hash
?
`#
${
hash
}
`
:
''
;
const
customParams
=
new
URLSearchParams
(
queryString
);
// remove reserved params
[
'
url
'
,
'
action
'
].
forEach
((
param
)
=>
customParams
.
delete
(
param
));
if
(
customParams
.
toString
()
||
customHash
)
{
const
targetUrl
=
new
URL
(
url
);
const
targetParams
=
new
URLSearchParams
(
targetUrl
.
search
);
let
customPath
=
customParams
.
get
(
'
path
'
);
if
(
customPath
)
{
customPath
=
customPath
.
startsWith
(
'
/
'
)
?
customPath
:
`/
${
customPath
}
`
;
targetUrl
.
pathname
=
customPath
;
customParams
.
delete
(
'
path
'
);
}
customParams
.
forEach
((
value
,
key
)
=>
{
targetParams
.
append
(
key
,
value
);
});
targetUrl
.
search
=
targetParams
.
toString
();
targetUrl
.
hash
=
customHash
;
return
targetUrl
.
toString
();
}
}
catch
(
err
)
{}
return
url
;
}
ui/pages/MarketplaceApp.tsx
View file @
7ea03ef8
...
...
@@ -16,13 +16,13 @@ import throwOnResourceLoadError from 'lib/errors/throwOnResourceLoadError';
import
useFetch
from
'
lib/hooks/useFetch
'
;
import
*
as
metadata
from
'
lib/metadata
'
;
import
getQueryParamString
from
'
lib/router/getQueryParamString
'
;
import
removeQueryParam
from
'
lib/router/removeQueryParam
'
;
import
ContentLoader
from
'
ui/shared/ContentLoader
'
;
import
MarketplaceAppTopBar
from
'
../marketplace/MarketplaceAppTopBar
'
;
import
useAutoConnectWallet
from
'
../marketplace/useAutoConnectWallet
'
;
import
useMarketplaceWallet
from
'
../marketplace/useMarketplaceWallet
'
;
import
useSecurityReports
from
'
../marketplace/useSecurityReports
'
;
import
{
getAppUrl
}
from
'
../marketplace/utils
'
;
const
feature
=
config
.
features
.
marketplace
;
...
...
@@ -134,59 +134,7 @@ const MarketplaceApp = () => {
const
{
data
,
isPending
}
=
query
;
const
{
setIsAutoConnectDisabled
}
=
useMarketplaceContext
();
const
appUrl
=
useMemo
(()
=>
{
if
(
!
data
?.
url
)
{
return
;
}
try
{
// get the custom url from the query
const
customUrl
=
getQueryParamString
(
router
.
query
.
url
);
if
(
customUrl
)
{
const
customOrigin
=
new
URL
(
customUrl
).
origin
;
const
appOrigin
=
new
URL
(
data
.
url
).
origin
;
if
(
customOrigin
===
appOrigin
)
{
return
customUrl
;
}
else
{
removeQueryParam
(
router
,
'
url
'
);
}
}
}
catch
(
err
)
{}
try
{
// get hash and params (using asPath to avoid conflicts with dynamic route params)
const
[
,
queryAndHash
]
=
router
.
asPath
.
split
(
'
?
'
);
const
[
queryString
,
hash
]
=
queryAndHash
?
queryAndHash
.
split
(
'
#
'
)
:
[
''
,
''
];
const
customHash
=
hash
?
`#
${
hash
}
`
:
''
;
const
customParams
=
new
URLSearchParams
(
queryString
);
// remove reserved params
[
'
url
'
,
'
action
'
].
forEach
((
param
)
=>
customParams
.
delete
(
param
));
if
(
customParams
.
toString
()
||
customHash
)
{
const
targetUrl
=
new
URL
(
data
.
url
);
const
targetParams
=
new
URLSearchParams
(
targetUrl
.
search
);
let
customPath
=
customParams
.
get
(
'
path
'
);
if
(
customPath
)
{
customPath
=
customPath
.
startsWith
(
'
/
'
)
?
customPath
:
`/
${
customPath
}
`
;
targetUrl
.
pathname
=
customPath
;
customParams
.
delete
(
'
path
'
);
}
customParams
.
forEach
((
value
,
key
)
=>
{
targetParams
.
append
(
key
,
value
);
});
targetUrl
.
search
=
targetParams
.
toString
();
targetUrl
.
hash
=
customHash
;
return
targetUrl
.
toString
();
}
}
catch
(
err
)
{}
return
data
.
url
;
},
[
data
?.
url
,
router
]);
const
appUrl
=
useMemo
(()
=>
getAppUrl
(
data
?.
url
,
router
),
[
data
?.
url
,
router
]);
useEffect
(()
=>
{
if
(
data
)
{
...
...
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