Skip to content

Commit

Permalink
Merge pull request #1061 from oasisprotocol/ml/fix-address-formatting…
Browse files Browse the repository at this point in the history
…-on-empty-account-follow-up

Fix address formatting on empty account follow up
  • Loading branch information
lubej authored Dec 5, 2023
2 parents 4062b25 + d794cf3 commit 196fd6d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions .changelog/1061.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix address formatting on empty account
2 changes: 1 addition & 1 deletion src/app/hooks/useTransformToOasisAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const useTransformToOasisAddress = (ethOrOasisAddress: string): string |
let shouldUpdate = true

const transformToOasisAddress = async (addr: string) => {
const oasisAddr = await getOasisAddress(addr)
const oasisAddr = await getOasisAddress(addr).catch(() => Promise.resolve(null))
if (shouldUpdate) {
setOasisAddress(oasisAddr)
}
Expand Down
5 changes: 3 additions & 2 deletions src/app/pages/TokenDashboardPage/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,19 @@ export const useAccountTokenInventory = (scope: SearchScope, address: string, to
}

const oasisAddress = useTransformToOasisAddress(address)
const oasisTokenAddress = useTransformToOasisAddress(tokenAddress)
const query = useGetRuntimeAccountsAddressNfts(
network,
layer,
oasisAddress!,
{
limit: NUMBER_OF_INVENTORY_ITEMS,
offset: offset,
token_address: tokenAddress,
token_address: oasisTokenAddress!,
},
{
query: {
enabled: !!oasisAddress,
enabled: !!oasisAddress && !!oasisTokenAddress,
},
},
)
Expand Down
10 changes: 6 additions & 4 deletions src/app/utils/route-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,13 @@ const validateTxHashParam = (hash: string) => {
return true
}

export const addressParamLoader = ({ params }: LoaderFunctionArgs): string => {
validateAddressParam(params.address!)
export const addressParamLoader =
(queryParam: string = 'address') =>
({ params }: LoaderFunctionArgs): string => {
validateAddressParam(params[queryParam]!)

return params.address!
}
return params[queryParam]!
}

export const blockHeightParamLoader = async ({ params }: LoaderFunctionArgs) => {
return validateBlockHeightParam(params.blockHeight!)
Expand Down
8 changes: 4 additions & 4 deletions src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const routes: RouteObject[] = [
{
path: `address/:address`,
element: <AccountDetailsPage />,
loader: addressParamLoader,
loader: addressParamLoader(),
children: [
{
path: '',
Expand All @@ -107,7 +107,7 @@ export const routes: RouteObject[] = [
{
path: ':contractAddress',
Component: () => <AccountNFTCollectionCard {...useAccountDetailsProps()} />,
loader: addressParamLoader,
loader: addressParamLoader('contractAddress'),
},
],
},
Expand All @@ -133,7 +133,7 @@ export const routes: RouteObject[] = [
{
path: 'token/:address/instance/:instanceId',
element: <NFTInstanceDashboardPage />,
loader: addressParamLoader,
loader: addressParamLoader(),
children: [
{
path: '',
Expand All @@ -144,7 +144,7 @@ export const routes: RouteObject[] = [
{
path: `token/:address`,
element: <TokenDashboardPage />,
loader: addressParamLoader,
loader: addressParamLoader(),
children: [
{
path: '',
Expand Down

0 comments on commit 196fd6d

Please sign in to comment.