diff --git a/packages/checkout/widgets-lib/src/widgets/add-funds/functions/sortRoutesByFastestTime.ts b/packages/checkout/widgets-lib/src/widgets/add-funds/functions/sortRoutesByFastestTime.ts new file mode 100644 index 0000000000..858d8094cc --- /dev/null +++ b/packages/checkout/widgets-lib/src/widgets/add-funds/functions/sortRoutesByFastestTime.ts @@ -0,0 +1,11 @@ +import { RouteData } from '../types'; + +export const sortRoutesByFastestTime = (routes: RouteData[] | undefined): RouteData[] | undefined => { + if (!routes) return undefined; + + return routes.slice().sort((a, b) => { + const timeA = a.route.route.estimate.estimatedRouteDuration; + const timeB = b.route.route.estimate.estimatedRouteDuration; + return timeA - timeB; + }); +};