-
-
Notifications
You must be signed in to change notification settings - Fork 4
Fixes and Performance Improvements #489
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
Changes from 1 commit
ae5570e
5cc3e6f
53bed83
c411d86
bacff60
3e40c58
77ef1e0
26870c4
8135396
c6a93c6
b4c89ba
f973013
e719e08
3ab27bc
e892ffa
2954294
43e9e99
f60b3b0
a2c83ae
144a083
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,88 +17,87 @@ import { ScheduleBackgroundEventMethod } from './ScheduleBackgroundEventMethod'; | |
| export const refreshSend: OnCronjobHandler = async () => { | ||
| const logger = createPrefixedLogger(baseLogger, '[refreshSend]'); | ||
|
|
||
| try { | ||
| // try { | ||
| logger.info( | ||
| `[${ScheduleBackgroundEventMethod.RefreshSend}] Background event triggered`, | ||
xavier-brochard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
|
|
||
| const [assets, mapInterfaceNameToId, preferences] = await Promise.all([ | ||
| assetsService.getAll(), | ||
| state.getKey<UnencryptedStateValue['mapInterfaceNameToId']>( | ||
| 'mapInterfaceNameToId', | ||
| ), | ||
| getPreferences().catch(() => DEFAULT_SEND_CONTEXT.preferences), | ||
| ]); | ||
|
|
||
| const assetTypes = assets.flatMap((asset) => asset.assetType); | ||
|
|
||
| const sendFormInterfaceId = mapInterfaceNameToId?.[SEND_FORM_INTERFACE_NAME]; | ||
|
|
||
| // Don't do anything if the send form interface is not open | ||
| if (!sendFormInterfaceId) { | ||
| logger.info( | ||
| `[${ScheduleBackgroundEventMethod.RefreshSend}] Background event triggered`, | ||
| `[${ScheduleBackgroundEventMethod.RefreshSend}] ❌ No send form interface found`, | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| const [assets, mapInterfaceNameToId, preferences] = await Promise.all([ | ||
| assetsService.getAll(), | ||
| state.getKey<UnencryptedStateValue['mapInterfaceNameToId']>( | ||
| 'mapInterfaceNameToId', | ||
| ), | ||
| getPreferences().catch(() => DEFAULT_SEND_CONTEXT.preferences), | ||
| ]); | ||
|
|
||
| const assetTypes = assets.flatMap((asset) => asset.assetType); | ||
|
|
||
| const sendFormInterfaceId = | ||
| mapInterfaceNameToId?.[SEND_FORM_INTERFACE_NAME]; | ||
|
|
||
| // Don't do anything if the send form interface is not open | ||
| if (!sendFormInterfaceId) { | ||
| logger.info( | ||
| `[${ScheduleBackgroundEventMethod.RefreshSend}] ❌ No send form interface found`, | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| // Schedule the next run | ||
| await snap.request({ | ||
| method: 'snap_scheduleBackgroundEvent', | ||
| params: { duration: 'PT30S', request: { method: 'refreshSend' } }, | ||
| }); | ||
|
|
||
| // First, fetch the token prices | ||
| const tokenPrices = await priceApiClient.getMultipleSpotPrices( | ||
| assetTypes, | ||
| preferences.currency, | ||
| ); | ||
| // Schedule the next run | ||
| await snap.request({ | ||
| method: 'snap_scheduleBackgroundEvent', | ||
| params: { duration: 'PT30S', request: { method: 'refreshSend' } }, | ||
| }); | ||
|
|
||
| // Save them in the state | ||
| await state.setKey('tokenPrices', tokenPrices); | ||
|
|
||
| // Get the current context | ||
| const interfaceContext = | ||
| await getInterfaceContextOrThrow<SendContext>(sendFormInterfaceId); | ||
|
|
||
| // We only want to refresh the token prices when the user is in the transaction confirmation stage | ||
| if (interfaceContext.stage !== 'transaction-confirmation') { | ||
| logger.info( | ||
| `[${ScheduleBackgroundEventMethod.RefreshSend}] ❌ Not in transaction confirmation stage`, | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| if (!interfaceContext.assets) { | ||
| logger.info( | ||
| `[${ScheduleBackgroundEventMethod.RefreshSend}] ❌ No assets found`, | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| // Update the current context with the new rates | ||
| const updatedInterfaceContext = { | ||
| ...interfaceContext, | ||
| tokenPrices: { | ||
| ...interfaceContext.tokenPrices, | ||
| ...tokenPrices, | ||
| }, | ||
| }; | ||
|
|
||
| await updateInterface( | ||
| sendFormInterfaceId, | ||
| <Send context={updatedInterfaceContext} />, | ||
| updatedInterfaceContext, | ||
| ); | ||
| // First, fetch the token prices | ||
| const tokenPrices = await priceApiClient.getMultipleSpotPrices( | ||
| assetTypes, | ||
| preferences.currency, | ||
| ); | ||
|
|
||
| // Save them in the state | ||
| await state.setKey('tokenPrices', tokenPrices); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Token Refresh Errors and Unnecessary SchedulingThe
|
||
|
|
||
| // Get the current context | ||
| const interfaceContext = | ||
| await getInterfaceContextOrThrow<SendContext>(sendFormInterfaceId); | ||
|
|
||
| // We only want to refresh the token prices when the user is in the transaction confirmation stage | ||
| if (interfaceContext.stage !== 'transaction-confirmation') { | ||
| logger.info( | ||
| `[${ScheduleBackgroundEventMethod.RefreshSend}] ✅ Background event suceeded`, | ||
| `[${ScheduleBackgroundEventMethod.RefreshSend}] ❌ Not in transaction confirmation stage`, | ||
| ); | ||
| } catch (error) { | ||
| logger.warn( | ||
| { error }, | ||
| `[${ScheduleBackgroundEventMethod.RefreshSend}] ❌ Background event failed`, | ||
| return; | ||
| } | ||
|
|
||
| if (!interfaceContext.assets) { | ||
| logger.info( | ||
| `[${ScheduleBackgroundEventMethod.RefreshSend}] ❌ No assets found`, | ||
| ); | ||
| return; | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Update the current context with the new rates | ||
| const updatedInterfaceContext = { | ||
| ...interfaceContext, | ||
| tokenPrices: { | ||
| ...interfaceContext.tokenPrices, | ||
| ...tokenPrices, | ||
| }, | ||
| }; | ||
|
|
||
| await updateInterface( | ||
| sendFormInterfaceId, | ||
| <Send context={updatedInterfaceContext} />, | ||
| updatedInterfaceContext, | ||
| ); | ||
|
|
||
| logger.info( | ||
| `[${ScheduleBackgroundEventMethod.RefreshSend}] ✅ Background event suceeded`, | ||
| ); | ||
| // } catch (error) { | ||
| // logger.warn( | ||
| // { error }, | ||
| // `[${ScheduleBackgroundEventMethod.RefreshSend}] ❌ Background event failed`, | ||
| // ); | ||
| // } | ||
cursor[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BugThe
As a result:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
Uh oh!
There was an error while loading. Please reload this page.