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
f45a4db7
Commit
f45a4db7
authored
Feb 08, 2024
by
Max Alekseenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rework queries
parent
adb1b0c9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
91 deletions
+65
-91
marketplace.ts
configs/app/features/marketplace.ts
+26
-22
resources.ts
lib/api/resources.ts
+0
-17
useMarketplaceApps.tsx
ui/marketplace/useMarketplaceApps.tsx
+13
-22
MarketplaceApp.tsx
ui/pages/MarketplaceApp.tsx
+26
-30
No files found.
configs/app/features/marketplace.ts
View file @
f45a4db7
...
@@ -11,28 +11,32 @@ const adminServiceApiHost = getEnvValue('NEXT_PUBLIC_ADMIN_SERVICE_API_HOST');
...
@@ -11,28 +11,32 @@ const adminServiceApiHost = getEnvValue('NEXT_PUBLIC_ADMIN_SERVICE_API_HOST');
const
title
=
'
Marketplace
'
;
const
title
=
'
Marketplace
'
;
const
config
:
Feature
<
{
const
config
:
Feature
<
(
configUrl
:
string
|
undefined
;
{
configUrl
:
string
}
|
submitFormUrl
:
string
;
{
api
:
{
endpoint
:
string
;
basePath
:
string
}
}
categoriesUrl
:
string
|
undefined
;
)
&
{
submitFormUrl
:
string
;
categoriesUrl
:
string
|
undefined
}
api
:
{
endpoint
:
string
;
basePath
:
string
}
|
undefined
;
>
=
(()
=>
{
}
>
=
(()
=>
{
if
(
chain
.
rpcUrl
&&
submitFormUrl
)
{
if
(
if
(
adminServiceApiHost
)
{
chain
.
rpcUrl
&&
return
Object
.
freeze
({
(
configUrl
||
adminServiceApiHost
)
&&
title
,
submitFormUrl
isEnabled
:
true
,
)
{
submitFormUrl
,
return
Object
.
freeze
({
categoriesUrl
,
title
,
api
:
{
isEnabled
:
true
,
endpoint
:
adminServiceApiHost
,
configUrl
:
adminServiceApiHost
?
undefined
:
configUrl
,
basePath
:
''
,
submitFormUrl
,
},
categoriesUrl
,
});
api
:
adminServiceApiHost
?
{
}
else
if
(
configUrl
)
{
endpoint
:
adminServiceApiHost
,
return
Object
.
freeze
({
basePath
:
''
,
title
,
}
:
undefined
,
isEnabled
:
true
,
});
configUrl
,
submitFormUrl
,
categoriesUrl
,
});
}
}
}
return
Object
.
freeze
({
return
Object
.
freeze
({
...
...
lib/api/resources.ts
View file @
f45a4db7
...
@@ -82,7 +82,6 @@ import type { VerifiedContractsSorting } from 'types/api/verifiedContracts';
...
@@ -82,7 +82,6 @@ import type { VerifiedContractsSorting } from 'types/api/verifiedContracts';
import
type
{
VisualizedContract
}
from
'
types/api/visualization
'
;
import
type
{
VisualizedContract
}
from
'
types/api/visualization
'
;
import
type
{
WithdrawalsResponse
,
WithdrawalsCounters
}
from
'
types/api/withdrawals
'
;
import
type
{
WithdrawalsResponse
,
WithdrawalsCounters
}
from
'
types/api/withdrawals
'
;
import
type
{
ZkEvmL2TxnBatch
,
ZkEvmL2TxnBatchesItem
,
ZkEvmL2TxnBatchesResponse
,
ZkEvmL2TxnBatchTxs
}
from
'
types/api/zkEvmL2TxnBatches
'
;
import
type
{
ZkEvmL2TxnBatch
,
ZkEvmL2TxnBatchesItem
,
ZkEvmL2TxnBatchesResponse
,
ZkEvmL2TxnBatchTxs
}
from
'
types/api/zkEvmL2TxnBatches
'
;
import
type
{
MarketplaceAppOverview
}
from
'
types/client/marketplace
'
;
import
type
{
ArrayElement
}
from
'
types/utils
'
;
import
type
{
ArrayElement
}
from
'
types/utils
'
;
import
config
from
'
configs/app
'
;
import
config
from
'
configs/app
'
;
...
@@ -215,20 +214,6 @@ export const RESOURCES = {
...
@@ -215,20 +214,6 @@ export const RESOURCES = {
filterFields
:
[
'
name
'
as
const
,
'
only_active
'
as
const
],
filterFields
:
[
'
name
'
as
const
,
'
only_active
'
as
const
],
},
},
// MARKETPLACE
marketplace_dapps
:
{
path
:
'
/api/v1/chains/:chainId/marketplace/dapps
'
,
pathParams
:
[
'
chainId
'
as
const
],
endpoint
:
getFeaturePayload
(
config
.
features
.
marketplace
)?.
api
?.
endpoint
,
basePath
:
getFeaturePayload
(
config
.
features
.
marketplace
)?.
api
?.
basePath
,
},
marketplace_dapp
:
{
path
:
'
/api/v1/chains/:chainId/marketplace/dapps/:dappId
'
,
pathParams
:
[
'
chainId
'
as
const
,
'
dappId
'
as
const
],
endpoint
:
getFeaturePayload
(
config
.
features
.
marketplace
)?.
api
?.
endpoint
,
basePath
:
getFeaturePayload
(
config
.
features
.
marketplace
)?.
api
?.
basePath
,
},
// VISUALIZATION
// VISUALIZATION
visualize_sol2uml
:
{
visualize_sol2uml
:
{
path
:
'
/api/v1/solidity
\\
:visualize-contracts
'
,
path
:
'
/api/v1/solidity
\\
:visualize-contracts
'
,
...
@@ -787,8 +772,6 @@ Q extends 'domains_lookup' ? EnsDomainLookupResponse :
...
@@ -787,8 +772,6 @@ Q extends 'domains_lookup' ? EnsDomainLookupResponse :
Q
extends
'
user_ops
'
?
UserOpsResponse
:
Q
extends
'
user_ops
'
?
UserOpsResponse
:
Q
extends
'
user_op
'
?
UserOp
:
Q
extends
'
user_op
'
?
UserOp
:
Q
extends
'
user_ops_account
'
?
UserOpsAccount
:
Q
extends
'
user_ops_account
'
?
UserOpsAccount
:
Q
extends
'
marketplace_dapps
'
?
Array
<
MarketplaceAppOverview
>
:
Q
extends
'
marketplace_dapp
'
?
MarketplaceAppOverview
:
never
;
never
;
/* eslint-enable @typescript-eslint/indent */
/* eslint-enable @typescript-eslint/indent */
...
...
ui/marketplace/useMarketplaceApps.tsx
View file @
f45a4db7
...
@@ -6,7 +6,6 @@ import { MarketplaceCategory } from 'types/client/marketplace';
...
@@ -6,7 +6,6 @@ import { MarketplaceCategory } from 'types/client/marketplace';
import
config
from
'
configs/app
'
;
import
config
from
'
configs/app
'
;
import
type
{
ResourceError
}
from
'
lib/api/resources
'
;
import
type
{
ResourceError
}
from
'
lib/api/resources
'
;
import
useApiQuery
from
'
lib/api/useApiQuery
'
;
import
useFeatureValue
from
'
lib/growthbook/useFeatureValue
'
;
import
useFeatureValue
from
'
lib/growthbook/useFeatureValue
'
;
import
useApiFetch
from
'
lib/hooks/useFetch
'
;
import
useApiFetch
from
'
lib/hooks/useFetch
'
;
import
{
MARKETPLACE_APP
}
from
'
stubs/marketplace
'
;
import
{
MARKETPLACE_APP
}
from
'
stubs/marketplace
'
;
...
@@ -47,36 +46,28 @@ function sortApps(apps: Array<MarketplaceAppOverview>, isExperiment: boolean) {
...
@@ -47,36 +46,28 @@ function sortApps(apps: Array<MarketplaceAppOverview>, isExperiment: boolean) {
});
});
}
}
function
useAppsQuery
(
)
{
export
default
function
useMarketplaceApps
(
filter
:
string
,
selectedCategoryId
:
string
=
MarketplaceCategory
.
ALL
,
favoriteApps
:
Array
<
string
>
=
[]
)
{
const
apiFetch
=
useApiFetch
();
const
apiFetch
=
useApiFetch
();
const
{
value
:
isExperiment
}
=
useFeatureValue
(
'
marketplace_exp
'
,
false
);
const
{
value
:
isExperiment
}
=
useFeatureValue
(
'
marketplace_exp
'
,
false
);
const
placeholderData
=
feature
.
isEnabled
?
Array
(
9
).
fill
(
MARKETPLACE_APP
)
:
undefined
;
const
{
isPlaceholderData
,
isError
,
error
,
data
}
=
useQuery
<
unknown
,
ResourceError
<
unknown
>
,
Array
<
MarketplaceAppOverview
>>
({
queryKey
:
[
'
marketplace-dapps
'
],
queryFn
:
async
()
=>
{
if
(
!
feature
.
isEnabled
)
{
return
[];
}
const
url
=
'
configUrl
'
in
feature
?
feature
.
configUrl
:
feature
.
api
.
endpoint
+
`/api/v1/chains/
${
config
.
chain
.
id
}
/marketplace/dapps`
;
const
data1
=
useQuery
<
unknown
,
ResourceError
<
unknown
>
,
Array
<
MarketplaceAppOverview
>>
({
return
apiFetch
<
Array
<
MarketplaceAppOverview
>
,
unknown
>
(
url
,
undefined
,
{
resource
:
'
marketplace-dapps
'
});
queryKey
:
[
'
marketplace-apps
'
],
},
queryFn
:
async
()
=>
apiFetch
(
feature
.
isEnabled
&&
feature
.
configUrl
?
feature
.
configUrl
:
''
,
undefined
,
{
resource
:
'
marketplace-apps
'
}),
select
:
(
data
)
=>
sortApps
(
data
as
Array
<
MarketplaceAppOverview
>
,
isExperiment
),
select
:
(
data
)
=>
sortApps
(
data
as
Array
<
MarketplaceAppOverview
>
,
isExperiment
),
placeholderData
,
placeholderData
:
feature
.
isEnabled
?
Array
(
9
).
fill
(
MARKETPLACE_APP
)
:
undefined
,
staleTime
:
Infinity
,
staleTime
:
Infinity
,
enabled
:
feature
.
isEnabled
,
enabled
:
feature
.
isEnabled
,
});
});
const
data2
=
useApiQuery
(
'
marketplace_dapps
'
,
{
pathParams
:
{
chainId
:
config
.
chain
.
id
},
queryOptions
:
{
select
:
(
data
)
=>
sortApps
(
data
as
Array
<
MarketplaceAppOverview
>
,
isExperiment
),
placeholderData
,
enabled
:
feature
.
isEnabled
,
},
});
return
feature
.
isEnabled
&&
feature
.
configUrl
?
data1
:
data2
;
}
export
default
function
useMarketplaceApps
(
filter
:
string
,
selectedCategoryId
:
string
=
MarketplaceCategory
.
ALL
,
favoriteApps
:
Array
<
string
>
=
[])
{
const
{
isPlaceholderData
,
isError
,
error
,
data
}
=
useAppsQuery
();
const
displayedApps
=
React
.
useMemo
(()
=>
{
const
displayedApps
=
React
.
useMemo
(()
=>
{
return
data
?.
filter
(
app
=>
isAppNameMatches
(
filter
,
app
)
&&
isAppCategoryMatches
(
selectedCategoryId
,
app
,
favoriteApps
))
||
[];
return
data
?.
filter
(
app
=>
isAppNameMatches
(
filter
,
app
)
&&
isAppCategoryMatches
(
selectedCategoryId
,
app
,
favoriteApps
))
||
[];
},
[
selectedCategoryId
,
data
,
filter
,
favoriteApps
]);
},
[
selectedCategoryId
,
data
,
filter
,
favoriteApps
]);
...
...
ui/pages/MarketplaceApp.tsx
View file @
f45a4db7
...
@@ -10,7 +10,6 @@ import { route } from 'nextjs-routes';
...
@@ -10,7 +10,6 @@ import { route } from 'nextjs-routes';
import
config
from
'
configs/app
'
;
import
config
from
'
configs/app
'
;
import
type
{
ResourceError
}
from
'
lib/api/resources
'
;
import
type
{
ResourceError
}
from
'
lib/api/resources
'
;
import
useApiQuery
from
'
lib/api/useApiQuery
'
;
import
throwOnResourceLoadError
from
'
lib/errors/throwOnResourceLoadError
'
;
import
throwOnResourceLoadError
from
'
lib/errors/throwOnResourceLoadError
'
;
import
useApiFetch
from
'
lib/hooks/useFetch
'
;
import
useApiFetch
from
'
lib/hooks/useFetch
'
;
import
*
as
metadata
from
'
lib/metadata
'
;
import
*
as
metadata
from
'
lib/metadata
'
;
...
@@ -94,44 +93,41 @@ const MarketplaceAppContent = ({ address, data, isPending }: Props) => {
...
@@ -94,44 +93,41 @@ const MarketplaceAppContent = ({ address, data, isPending }: Props) => {
);
);
};
};
function
useAppQuery
(
id
:
string
)
{
const
MarketplaceApp
=
()
=>
{
const
{
address
,
sendTransaction
,
signMessage
,
signTypedData
}
=
useMarketplaceWallet
();
const
apiFetch
=
useApiFetch
();
const
apiFetch
=
useApiFetch
();
const
data1
=
useQuery
<
unknown
,
ResourceError
<
unknown
>
,
MarketplaceAppOverview
>
({
const
router
=
useRouter
();
queryKey
:
[
'
marketplace-apps
'
,
id
],
const
id
=
getQueryParamString
(
router
.
query
.
id
);
const
query
=
useQuery
<
unknown
,
ResourceError
<
unknown
>
,
MarketplaceAppOverview
>
({
queryKey
:
[
'
marketplace-dapps
'
,
id
],
queryFn
:
async
()
=>
{
queryFn
:
async
()
=>
{
const
configUrl
=
feature
.
isEnabled
&&
feature
.
configUrl
?
feature
.
configUrl
:
''
;
if
(
!
feature
.
isEnabled
)
{
const
result
=
await
apiFetch
<
Array
<
MarketplaceAppOverview
>
,
unknown
>
(
configUrl
,
undefined
,
{
resource
:
'
marketplace-apps
'
});
return
null
;
if
(
!
Array
.
isArray
(
result
))
{
throw
result
;
}
}
const
item
=
result
.
find
((
app
:
MarketplaceAppOverview
)
=>
app
.
id
===
id
);
const
isConfigFile
=
'
configUrl
'
in
feature
;
if
(
!
item
)
{
const
url
=
isConfigFile
?
throw
{
status
:
404
};
feature
.
configUrl
:
feature
.
api
.
endpoint
+
`/api/v1/chains/
${
config
.
chain
.
id
}
/marketplace/dapps/
${
id
}
`
;
const
result
=
await
apiFetch
<
Array
<
MarketplaceAppOverview
>
,
unknown
>
(
url
,
undefined
,
{
resource
:
'
marketplace-dapps
'
});
if
(
isConfigFile
)
{
if
(
!
Array
.
isArray
(
result
))
{
throw
result
;
}
const
item
=
result
.
find
((
app
:
MarketplaceAppOverview
)
=>
app
.
id
===
id
);
if
(
!
item
)
{
throw
{
status
:
404
};
}
return
item
;
}
}
return
item
;
return
result
;
},
},
enabled
:
feature
.
isEnabled
,
enabled
:
feature
.
isEnabled
,
});
});
const
data2
=
useApiQuery
(
'
marketplace_dapp
'
,
{
pathParams
:
{
chainId
:
config
.
chain
.
id
,
dappId
:
id
},
queryOptions
:
{
enabled
:
feature
.
isEnabled
,
},
});
return
feature
.
isEnabled
&&
feature
.
configUrl
?
data1
:
data2
;
}
const
MarketplaceApp
=
()
=>
{
const
{
address
,
sendTransaction
,
signMessage
,
signTypedData
}
=
useMarketplaceWallet
();
const
router
=
useRouter
();
const
id
=
getQueryParamString
(
router
.
query
.
id
);
const
query
=
useAppQuery
(
id
);
const
{
data
,
isPending
}
=
query
;
const
{
data
,
isPending
}
=
query
;
useEffect
(()
=>
{
useEffect
(()
=>
{
...
...
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