feat(wallet)!: return routerV2 suggested routes whenever available, on top of error if the best route doesn't pass all checks

This commit is contained in:
Dario Gabriel Lipicar 2024-07-10 18:06:56 -03:00 committed by dlipicar
parent a006d80acf
commit 21101c9444
3 changed files with 3286 additions and 3145 deletions

View File

@ -133,9 +133,13 @@ type SuggestedRoutesV2 struct {
NativeChainTokenPrice float64 NativeChainTokenPrice float64
} }
type ErrorResponseWithUUID struct { type SuggestedRoutesV2Response struct {
Uuid string Uuid string `json:"Uuid"`
ErrorResponse error Best []*PathV2 `json:"Best,omitempty"`
Candidates []*PathV2 `json:"Candidates,omitempty"`
TokenPrice *float64 `json:"TokenPrice,omitempty"`
NativeChainTokenPrice *float64 `json:"NativeChainTokenPrice,omitempty"`
ErrorResponse *errors.ErrorResponse `json:"ErrorResponse,omitempty"`
} }
type GraphV2 []*NodeV2 type GraphV2 []*NodeV2
@ -449,15 +453,23 @@ func (r *Router) SuggestedRoutesV2Async(input *RouteInputParams) {
r.scheduler.Enqueue(routerTask, func(ctx context.Context) (interface{}, error) { r.scheduler.Enqueue(routerTask, func(ctx context.Context) (interface{}, error) {
return r.SuggestedRoutesV2(ctx, input) return r.SuggestedRoutesV2(ctx, input)
}, func(result interface{}, taskType async.TaskType, err error) { }, func(result interface{}, taskType async.TaskType, err error) {
if err != nil { routesResponse := SuggestedRoutesV2Response{
errResponse := &ErrorResponseWithUUID{
Uuid: input.Uuid, Uuid: input.Uuid,
ErrorResponse: errors.CreateErrorResponseFromError(err),
} }
signal.SendWalletEvent(signal.SuggestedRoutes, errResponse)
return if err != nil {
errorResponse := errors.CreateErrorResponseFromError(err)
routesResponse.ErrorResponse = errorResponse.(*errors.ErrorResponse)
} }
signal.SendWalletEvent(signal.SuggestedRoutes, result)
if suggestedRoutes, ok := result.(*SuggestedRoutesV2); ok && suggestedRoutes != nil {
routesResponse.Best = suggestedRoutes.Best
routesResponse.Candidates = suggestedRoutes.Candidates
routesResponse.TokenPrice = &suggestedRoutes.TokenPrice
routesResponse.NativeChainTokenPrice = &suggestedRoutes.NativeChainTokenPrice
}
signal.SendWalletEvent(signal.SuggestedRoutes, routesResponse)
}) })
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff