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
1f696b90
Commit
1f696b90
authored
Apr 25, 2024
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change useAddressMetadataInfoQuery accordint to new version of the API
parent
c0bbc4c2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
94 additions
and
22 deletions
+94
-22
parseMetaPayload.ts
lib/address/parseMetaPayload.ts
+30
-0
useAddressMetadataInfoQuery.ts
lib/address/useAddressMetadataInfoQuery.ts
+38
-16
resources.ts
lib/api/resources.ts
+1
-1
address.ts
mocks/metadata/address.ts
+4
-4
addressMetadata.ts
types/api/addressMetadata.ts
+1
-1
addressMetadata.ts
types/client/addressMetadata.ts
+20
-0
No files found.
lib/address/parseMetaPayload.ts
0 → 100644
View file @
1f696b90
import
type
{
AddressMetadataTag
}
from
'
types/api/addressMetadata
'
;
import
type
{
AddressMetadataTagFormatted
}
from
'
types/client/addressMetadata
'
;
export
default
function
parseMetaPayload
(
meta
:
AddressMetadataTag
[
'
meta
'
]):
AddressMetadataTagFormatted
[
'
meta
'
]
{
try
{
const
parsedMeta
=
JSON
.
parse
(
meta
||
''
);
if
(
typeof
parsedMeta
!==
'
object
'
||
parsedMeta
===
null
||
Array
.
isArray
(
parsedMeta
))
{
throw
new
Error
(
'
Invalid JSON
'
);
}
const
result
:
AddressMetadataTagFormatted
[
'
meta
'
]
=
{};
if
(
'
textColor
'
in
parsedMeta
&&
typeof
parsedMeta
.
textColor
===
'
string
'
)
{
result
.
textColor
=
parsedMeta
.
textColor
;
}
if
(
'
bgColor
'
in
parsedMeta
&&
typeof
parsedMeta
.
bgColor
===
'
string
'
)
{
result
.
bgColor
=
parsedMeta
.
bgColor
;
}
if
(
'
actionURL
'
in
parsedMeta
&&
typeof
parsedMeta
.
actionURL
===
'
string
'
)
{
result
.
actionURL
=
parsedMeta
.
actionURL
;
}
return
result
;
}
catch
(
error
)
{
return
null
;
}
}
lib/address/useAddressMetadataInfoQuery.ts
View file @
1f696b90
import
_mapKeys
from
'
lodash/mapKeys
'
;
import
{
useQuery
}
from
'
@tanstack/react-query
'
;
import
type
{
AddressMetadataInfo
}
from
'
types/api/addressMetadata
'
;
import
type
{
AddressMetadataInfoFormatted
,
AddressMetadataTagFormatted
}
from
'
types/client/addressMetadata
'
;
import
config
from
'
configs/app
'
;
import
config
from
'
configs/app
'
;
import
useApiQuery
from
'
lib/api/useApiQuery
'
;
import
useApiFetch
from
'
lib/api/useApiFetch
'
;
import
{
getResourceKey
}
from
'
lib/api/useApiQuery
'
;
import
parseMetaPayload
from
'
./parseMetaPayload
'
;
export
default
function
useAddressMetadataInfoQuery
(
addresses
:
Array
<
string
>
)
{
export
default
function
useAddressMetadataInfoQuery
(
addresses
:
Array
<
string
>
)
{
return
useApiQuery
(
'
address_metadata_info
'
,
{
fetchParams
:
{
const
apiFetch
=
useApiFetch
();
method
:
'
POST
'
,
body
:
{
const
queryParams
=
{
addresses
,
addresses
,
chainId
:
config
.
chain
.
id
,
chainId
:
config
.
chain
.
id
,
tags
:
{
limit
:
'
20
'
},
tagsLimit
:
'
20
'
,
},
};
const
resource
=
'
address_metadata_info
'
;
// TODO @tom2drum: Improve the typing here
// since we are formatting the API data in the select function here
// we cannot use the useApiQuery hook because of its current typing
// enhance useApiQuery so it can accept an API data and the formatted data types
return
useQuery
<
AddressMetadataInfo
,
unknown
,
AddressMetadataInfoFormatted
>
({
queryKey
:
getResourceKey
(
resource
,
{
queryParams
}),
queryFn
:
async
()
=>
{
return
apiFetch
(
resource
,
{
queryParams
})
as
Promise
<
AddressMetadataInfo
>
;
},
},
queryOptions
:
{
enabled
:
addresses
.
length
>
0
&&
config
.
features
.
addressMetadata
.
isEnabled
,
enabled
:
addresses
.
length
>
0
&&
config
.
features
.
addressMetadata
.
isEnabled
,
select
:
(
data
)
=>
{
select
:
(
data
)
=>
{
const
addresses
=
Object
.
entries
(
data
.
addresses
)
const
addresses
=
_mapKeys
(
data
.
addresses
,
(
_
,
address
)
=>
address
.
toLowerCase
());
.
map
(([
address
,
{
tags
,
reputation
}
])
=>
{
const
formattedTags
:
Array
<
AddressMetadataTagFormatted
>
=
tags
.
map
((
tag
)
=>
({
...
tag
,
meta
:
parseMetaPayload
(
tag
.
meta
)
}));
return
[
address
.
toLowerCase
(),
{
tags
:
formattedTags
,
reputation
}
]
as
const
;
})
.
reduce
((
result
,
item
)
=>
{
result
[
item
[
0
]]
=
item
[
1
];
return
result
;
},
{}
as
AddressMetadataInfoFormatted
[
'
addresses
'
]);
return
{
addresses
};
return
{
addresses
};
},
},
},
});
});
}
}
lib/api/resources.ts
View file @
1f696b90
...
@@ -32,6 +32,7 @@ import type {
...
@@ -32,6 +32,7 @@ import type {
AddressCoinBalanceHistoryChartOld
,
AddressCoinBalanceHistoryChartOld
,
}
from
'
types/api/address
'
;
}
from
'
types/api/address
'
;
import
type
{
AddressesResponse
}
from
'
types/api/addresses
'
;
import
type
{
AddressesResponse
}
from
'
types/api/addresses
'
;
import
type
{
AddressMetadataInfo
}
from
'
types/api/addressMetadata
'
;
import
type
{
TxBlobs
,
Blob
}
from
'
types/api/blobs
'
;
import
type
{
TxBlobs
,
Blob
}
from
'
types/api/blobs
'
;
import
type
{
BlocksResponse
,
BlockTransactionsResponse
,
Block
,
BlockFilters
,
BlockWithdrawalsResponse
}
from
'
types/api/block
'
;
import
type
{
BlocksResponse
,
BlockTransactionsResponse
,
Block
,
BlockFilters
,
BlockWithdrawalsResponse
}
from
'
types/api/block
'
;
import
type
{
ChartMarketResponse
,
ChartSecondaryCoinPriceResponse
,
ChartTransactionResponse
}
from
'
types/api/charts
'
;
import
type
{
ChartMarketResponse
,
ChartSecondaryCoinPriceResponse
,
ChartTransactionResponse
}
from
'
types/api/charts
'
;
...
@@ -57,7 +58,6 @@ import type {
...
@@ -57,7 +58,6 @@ import type {
import
type
{
IndexingStatus
}
from
'
types/api/indexingStatus
'
;
import
type
{
IndexingStatus
}
from
'
types/api/indexingStatus
'
;
import
type
{
InternalTransactionsResponse
}
from
'
types/api/internalTransaction
'
;
import
type
{
InternalTransactionsResponse
}
from
'
types/api/internalTransaction
'
;
import
type
{
LogsResponseTx
,
LogsResponseAddress
}
from
'
types/api/log
'
;
import
type
{
LogsResponseTx
,
LogsResponseAddress
}
from
'
types/api/log
'
;
import
type
{
AddressMetadataInfo
}
from
'
types/api/metadata
'
;
import
type
{
NovesAccountHistoryResponse
,
NovesDescribeTxsResponse
,
NovesResponseData
}
from
'
types/api/noves
'
;
import
type
{
NovesAccountHistoryResponse
,
NovesDescribeTxsResponse
,
NovesResponseData
}
from
'
types/api/noves
'
;
import
type
{
import
type
{
OptimisticL2DepositsResponse
,
OptimisticL2DepositsResponse
,
...
...
mocks/metadata/address.ts
View file @
1f696b90
import
type
{
AddressMetadataInfo
,
AddressMetadataTag
}
from
'
types/api/
m
etadata
'
;
import
type
{
AddressMetadataInfo
,
AddressMetadataTag
}
from
'
types/api/
addressM
etadata
'
;
import
{
hash
}
from
'
../address/address
'
;
import
{
hash
}
from
'
../address/address
'
;
...
@@ -7,7 +7,7 @@ export const nameTag1: AddressMetadataTag = {
...
@@ -7,7 +7,7 @@ export const nameTag1: AddressMetadataTag = {
name
:
'
Ethermine.ru
'
,
name
:
'
Ethermine.ru
'
,
tagType
:
'
name
'
,
tagType
:
'
name
'
,
ordinal
:
0
,
ordinal
:
0
,
meta
:
{}
,
meta
:
null
,
};
};
export
const
genericTag1
:
AddressMetadataTag
=
{
export
const
genericTag1
:
AddressMetadataTag
=
{
...
@@ -15,7 +15,7 @@ export const genericTag1: AddressMetadataTag = {
...
@@ -15,7 +15,7 @@ export const genericTag1: AddressMetadataTag = {
name
:
'
Ethermine.ru
'
,
name
:
'
Ethermine.ru
'
,
tagType
:
'
generic
'
,
tagType
:
'
generic
'
,
ordinal
:
0
,
ordinal
:
0
,
meta
:
{}
,
meta
:
null
,
};
};
export
const
protocolTag1
:
AddressMetadataTag
=
{
export
const
protocolTag1
:
AddressMetadataTag
=
{
...
@@ -23,7 +23,7 @@ export const protocolTag1: AddressMetadataTag = {
...
@@ -23,7 +23,7 @@ export const protocolTag1: AddressMetadataTag = {
name
:
'
Aerodrome
'
,
name
:
'
Aerodrome
'
,
tagType
:
'
protocol
'
,
tagType
:
'
protocol
'
,
ordinal
:
0
,
ordinal
:
0
,
meta
:
{}
,
meta
:
null
,
};
};
export
const
baseInfo
:
AddressMetadataInfo
=
{
export
const
baseInfo
:
AddressMetadataInfo
=
{
...
...
types/api/
m
etadata.ts
→
types/api/
addressM
etadata.ts
View file @
1f696b90
...
@@ -12,5 +12,5 @@ export interface AddressMetadataTag {
...
@@ -12,5 +12,5 @@ export interface AddressMetadataTag {
name
:
string
;
name
:
string
;
tagType
:
AddressMetadataTagType
;
tagType
:
AddressMetadataTagType
;
ordinal
:
number
;
ordinal
:
number
;
meta
:
Record
<
string
,
unknown
>
;
meta
:
string
|
null
;
}
}
types/client/addressMetadata.ts
0 → 100644
View file @
1f696b90
import
type
{
AddressMetadataTagType
}
from
'
types/api/addressMetadata
'
;
export
interface
AddressMetadataInfoFormatted
{
addresses
:
Record
<
string
,
{
tags
:
Array
<
AddressMetadataTagFormatted
>
;
reputation
:
number
|
null
;
}
>
;
}
export
interface
AddressMetadataTagFormatted
{
slug
:
string
;
name
:
string
;
tagType
:
AddressMetadataTagType
;
ordinal
:
number
;
meta
:
{
textColor
?:
string
;
bgColor
?:
string
;
actionURL
?:
string
;
}
|
null
;
}
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