-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from multiversx/scroll-to-section
Scroll to Section
- Loading branch information
Showing
14 changed files
with
438 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { useLocation } from 'react-router-dom'; | ||
|
||
import { DecodeMethodEnum } from 'components/DataDecode'; | ||
|
||
export const useGetTransactionUrlHashParams = () => { | ||
const { hash } = useLocation(); | ||
|
||
// hash order: hashId/hashIndex/hashDecodeMethod/secondHashDecodeMethod/thirdHashDecodeMethod | ||
|
||
const hashArray = hash.replace('#', '').split('/'); | ||
const [firstParam, secondParam, thirdParam, fourthParam, fifthParam] = | ||
hashArray; | ||
|
||
if ( | ||
hashArray.length === 1 && | ||
Object.values<string>(DecodeMethodEnum).includes(firstParam) | ||
) { | ||
return { | ||
hashId: '', | ||
hashIndex: 0, | ||
hashDecodeMethod: firstParam as DecodeMethodEnum, | ||
secondHashDecodeMethod: DecodeMethodEnum.raw, | ||
thirdHashDecodeMethod: DecodeMethodEnum.raw | ||
}; | ||
} | ||
|
||
if ( | ||
hashArray.length === 2 && | ||
Object.values<string>(DecodeMethodEnum).includes(secondParam) | ||
) { | ||
return { | ||
hashId: firstParam, | ||
hashIndex: 0, | ||
hashDecodeMethod: secondParam as DecodeMethodEnum, | ||
secondHashDecodeMethod: DecodeMethodEnum.raw, | ||
thirdHashDecodeMethod: DecodeMethodEnum.raw | ||
}; | ||
} | ||
|
||
const hashDecodeMethod = Object.values<string>(DecodeMethodEnum).includes( | ||
thirdParam | ||
) | ||
? (thirdParam as DecodeMethodEnum) | ||
: DecodeMethodEnum.raw; | ||
|
||
const secondHashDecodeMethod = Object.values<string>( | ||
DecodeMethodEnum | ||
).includes(fourthParam) | ||
? (fourthParam as DecodeMethodEnum) | ||
: DecodeMethodEnum.raw; | ||
|
||
const thirdHashDecodeMethod = Object.values<string>( | ||
DecodeMethodEnum | ||
).includes(fifthParam) | ||
? (fifthParam as DecodeMethodEnum) | ||
: DecodeMethodEnum.raw; | ||
|
||
return { | ||
hashId: firstParam, | ||
hashIndex: secondParam, | ||
hashDecodeMethod, | ||
secondHashDecodeMethod, | ||
thirdHashDecodeMethod | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { RefObject, useEffect } from 'react'; | ||
|
||
import { useGetTransactionUrlHashParams } from 'hooks'; | ||
|
||
export const useScrollToTransactionSection = ( | ||
ref?: RefObject<HTMLDivElement> | ||
) => { | ||
const { hashId } = useGetTransactionUrlHashParams(); | ||
|
||
useEffect(() => { | ||
setTimeout(() => { | ||
if (hashId && ref?.current && ref.current !== null) { | ||
ref.current.scrollIntoView({ | ||
behavior: 'smooth', | ||
block: 'start', | ||
inline: 'start' | ||
}); | ||
} | ||
}, 200); | ||
}, [hashId]); | ||
}; |
28 changes: 28 additions & 0 deletions
28
src/pages/TransactionDetails/components/EventsList/EventExtraData.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Dispatch, SetStateAction } from 'react'; | ||
|
||
import { DataDecode, DecodeMethodEnum } from 'components'; | ||
|
||
interface EventExtraDataUIType { | ||
data: string[]; | ||
identifier?: string; | ||
initialDecodeMethod?: DecodeMethodEnum; | ||
setDecodeMethod?: Dispatch<SetStateAction<DecodeMethodEnum>>; | ||
} | ||
|
||
export const EventExtraData = ({ | ||
data, | ||
identifier, | ||
initialDecodeMethod, | ||
setDecodeMethod | ||
}: EventExtraDataUIType) => { | ||
const mergedData = data.join('\n'); | ||
|
||
return ( | ||
<DataDecode | ||
value={mergedData} | ||
identifier={identifier} | ||
initialDecodeMethod={initialDecodeMethod} | ||
setDecodeMethod={setDecodeMethod} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.