-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor useMainProcess #324
Merged
Sharqiewicz
merged 45 commits into
polygon-prototype-staging
from
refactor/useMainProcess
Dec 31, 2024
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
e6a3cdc
modify autodeploy.yaml
gianfra-t 1665a3c
Merge branch 'polygon-prototype-staging' into upgrade-polyon-prototype
TorstenStueber 0148805
Merge pull request #151 from pendulum-chain/upgrade-polyon-prototype
TorstenStueber 3fe70bb
Merge branch 'polygon-prototype-staging' into release-polygon-prototy…
TorstenStueber 0c0a818
Merge pull request #161 from pendulum-chain/release-polygon-prototype…
TorstenStueber 1379abf
Merge pull request #176 from pendulum-chain/polygon-prototype-staging
gianfra-t 91fc9ac
Merge pull request #194 from pendulum-chain/polygon-prototype-staging
TorstenStueber 8e28135
Merge pull request #200 from pendulum-chain/polygon-prototype-staging
ebma 238a73a
Merge pull request #202 from pendulum-chain/polygon-prototype-staging
ebma e732ab7
Merge pull request #207 from pendulum-chain/polygon-prototype-staging
ebma 8ee1efd
Merge pull request #232 from pendulum-chain/polygon-prototype-staging
TorstenStueber 9d5d5f4
Merge pull request #253 from pendulum-chain/polygon-prototype-staging
TorstenStueber 8332dca
Merge pull request #287 from pendulum-chain/polygon-prototype-staging
ebma 6cb8f38
Update the Mykobo home domain
TorstenStueber 1dd389c
Merge pull request #304 from pendulum-chain/TorstenStueber-patch-1
TorstenStueber 50872e2
Merge pull request #312 from pendulum-chain/polygon-prototype-staging
ebma fb37af3
add useOfframpingEvents custom hook
Sharqiewicz acb0e80
add useOfframpingAdvancement custom hook
Sharqiewicz ebaf886
reduce cognitive load of useMainProcess hook
Sharqiewicz bd10823
implement zustand for useMainProcess
Sharqiewicz b8ece4f
improve zustand config
Sharqiewicz 0607559
refactor offrampStore
Sharqiewicz 3e3358c
update offrampStore property names to reduce cognitive load
Sharqiewicz 677421b
Don't show terms and conditions
ebma bd3a8a9
export default postcss config
Sharqiewicz 5715082
change postcss config to .js from .mjs
Sharqiewicz 1cb8896
export default tailwindcss config
Sharqiewicz fc0d870
change daisyui import
Sharqiewicz 3bf312c
rename Offramping to Offramp
Sharqiewicz a4c7b7a
Merge pull request #330 from pendulum-chain/remove-t-and-c-dialog
ebma b4136ff
add fromAmount and showFees url params
Sharqiewicz 84628fb
max 2 decimal places fromAmount url param
Sharqiewicz ac71195
fromAmount url param accept only bigger than 0
Sharqiewicz 0e7fdbc
add showCompareFees param
Sharqiewicz 77750b7
remove compareFees param
Sharqiewicz 0fd6726
remove unused setEvents code
Sharqiewicz 90a8245
add renderEvent
Sharqiewicz 1ea84b3
remove unnecessary comment
Sharqiewicz aa37e1e
Merge branch 'polygon-prototype-staging' into refactor/useMainProcess
Sharqiewicz 5e0f00b
Merge branch 'polygon-prototype-staging' into refactor/useMainProcess
Sharqiewicz c740ec0
fix conflict
Sharqiewicz 40c5a32
Merge pull request #333 from pendulum-chain/321-add-prefill-form-url
ebma 3e166e8
Merge branch 'polygon-prototype' into polygon-prototype-staging
Sharqiewicz 9b73bcc
fix autodeploy config
Sharqiewicz 81dca9f
Merge branch 'polygon-prototype-staging' into refactor/useMainProcess
Sharqiewicz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { useEffect } from 'preact/hooks'; | ||
import { useConfig } from 'wagmi'; | ||
|
||
import { advanceOfframpingState } from '../../services/offrampingFlow'; | ||
|
||
import { usePolkadotWalletState } from '../../contexts/polkadotWallet'; | ||
import { useAssetHubNode } from '../../contexts/polkadotNode'; | ||
import { usePendulumNode } from '../../contexts/polkadotNode'; | ||
import { useEventsContext } from '../../contexts/events'; | ||
|
||
import { useOfframpActions, useOfframpState } from '../../stores/offrampStore'; | ||
import { EventStatus } from '../../components/GenericEvent'; | ||
|
||
export const useOfframpAdvancement = () => { | ||
const { walletAccount } = usePolkadotWalletState(); | ||
const { trackEvent } = useEventsContext(); | ||
const wagmiConfig = useConfig(); | ||
|
||
const { apiComponents: pendulumNode } = usePendulumNode(); | ||
const { apiComponents: assetHubNode } = useAssetHubNode(); | ||
|
||
const offrampState = useOfframpState(); | ||
const { updateOfframpHookStateFromState, setOfframpSigningPhase } = useOfframpActions(); | ||
|
||
useEffect(() => { | ||
if (wagmiConfig.state.status !== 'connected') return; | ||
|
||
(async () => { | ||
if (!pendulumNode || !assetHubNode) { | ||
console.error('Polkadot nodes not initialized'); | ||
return; | ||
} | ||
|
||
const nextState = await advanceOfframpingState(offrampState, { | ||
wagmiConfig, | ||
setOfframpSigningPhase, | ||
trackEvent, | ||
pendulumNode, | ||
assetHubNode, | ||
walletAccount, | ||
renderEvent: (message: string, status: EventStatus) => { | ||
console.log('renderEvent: ', message, status); | ||
}, | ||
}); | ||
|
||
if (JSON.stringify(offrampState) !== JSON.stringify(nextState)) { | ||
updateOfframpHookStateFromState(nextState); | ||
} | ||
})(); | ||
|
||
// @todo: investigate and remove this | ||
// This effect has dependencies that are used inside the async function (assetHubNode, pendulumNode, walletAccount) | ||
// but we intentionally exclude them from the dependency array to prevent unnecessary re-renders. | ||
// These dependencies are stable and won't change during the lifecycle of this hook. | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [offrampState, trackEvent, updateOfframpHookStateFromState, wagmiConfig]); | ||
}; |
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,35 @@ | ||
import { useCallback } from 'preact/compat'; | ||
import { createTransactionEvent } from '../../contexts/events'; | ||
import { useEventsContext } from '../../contexts/events'; | ||
import { useNetwork } from '../../contexts/network'; | ||
|
||
import { getInputTokenDetailsOrDefault } from '../../constants/tokenConfig'; | ||
import { OfframpingState } from '../../services/offrampingFlow'; | ||
import { OFFRAMPING_PHASE_SECONDS } from '../../pages/progress'; | ||
|
||
export const useOfframpEvents = () => { | ||
const { trackEvent, resetUniqueEvents } = useEventsContext(); | ||
const { selectedNetwork } = useNetwork(); | ||
|
||
const trackOfframpingEvent = useCallback( | ||
(state: OfframpingState | undefined) => { | ||
if (!state) return; | ||
|
||
if (state.phase === 'success') { | ||
trackEvent(createTransactionEvent('transaction_success', state, selectedNetwork)); | ||
} else if (state.failure) { | ||
trackEvent({ | ||
...createTransactionEvent('transaction_failure', state, selectedNetwork), | ||
event: 'transaction_failure', | ||
phase_name: state.phase, | ||
phase_index: Object.keys(OFFRAMPING_PHASE_SECONDS).indexOf(state.phase), | ||
from_asset: getInputTokenDetailsOrDefault(selectedNetwork, state.inputTokenType).assetSymbol, | ||
error_message: state.failure.message, | ||
}); | ||
} | ||
}, | ||
[trackEvent, selectedNetwork], | ||
); | ||
|
||
return { trackOfframpingEvent, trackEvent, resetUniqueEvents }; | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we could move this to
useEventsContext
? Especially since we remove theaddEvent
thingy. ThisuseOfframpEvents
is a bit intermediary.If it's too much trouble then no need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gianfra-t I think we should keep the logic in a custom hook and in the Events Context keep only state-related code. The Event Context file is actually quite big right now