-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "[fix/LIVE-11122]: update quotes when timeout reaches 0 in swa…
- Loading branch information
1 parent
6531594
commit 70a2a2d
Showing
14 changed files
with
144 additions
and
72 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
31 changes: 25 additions & 6 deletions
31
apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Form/Rates/Countdown.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
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
58 changes: 58 additions & 0 deletions
58
apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/utils/getRefreshTime.test.ts
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,58 @@ | ||
import { describe, it, expect, jest } from "@jest/globals"; | ||
import { ExchangeRate } from "@ledgerhq/live-common/exchange/swap/types"; | ||
import { getRefreshTime } from "~/renderer/screens/exchange/Swap2/utils/getRefreshTime"; | ||
const mockDate = new Date("2020-01-01"); | ||
jest.useFakeTimers().setSystemTime(mockDate); | ||
describe("getRefreshTime", () => { | ||
it("returns default refresh time when no rates provided", () => { | ||
expect(getRefreshTime(undefined)).toEqual(20000); | ||
}); | ||
|
||
it("returns the default refresh time when no rates have an expirationTime", () => { | ||
expect( | ||
getRefreshTime([ | ||
{ | ||
rateId: "1", | ||
} as ExchangeRate, | ||
]), | ||
).toEqual(20000); | ||
}); | ||
|
||
it("returns the a refresh time that is the earliest expirationTime in the list of rates if it's under 60s", () => { | ||
const mockTimeSinceEpoch = mockDate.getTime(); | ||
expect( | ||
getRefreshTime([ | ||
{ | ||
rateId: "1", | ||
expirationTime: mockTimeSinceEpoch + 19000, | ||
}, | ||
{ | ||
rateId: "2", | ||
expirationTime: mockTimeSinceEpoch + 18000, | ||
}, | ||
{ | ||
rateId: "3", | ||
}, | ||
] as ExchangeRate[]), | ||
).toEqual(18000); | ||
}); | ||
|
||
it("returns 60s when the earliest expirationTime in the list of rates is over 60s", () => { | ||
const mockTimeSinceEpoch = mockDate.getTime(); | ||
expect( | ||
getRefreshTime([ | ||
{ | ||
rateId: "1", | ||
expirationTime: mockTimeSinceEpoch + 21000, | ||
}, | ||
{ | ||
rateId: "2", | ||
expirationTime: mockTimeSinceEpoch + 22000, | ||
}, | ||
{ | ||
rateId: "3", | ||
}, | ||
] as ExchangeRate[]), | ||
).toEqual(20000); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/utils/getRefreshTime.ts
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,19 @@ | ||
import { DEFAULT_SWAP_RATES_INTERVAL_MS } from "@ledgerhq/live-common/exchange/swap/const/timeout"; | ||
import { ExchangeRate } from "@ledgerhq/live-common/exchange/swap/types"; | ||
|
||
const getMinimumExpirationTime = (rates: ExchangeRate[]): number => { | ||
return rates.reduce((acc, rate) => { | ||
if (!rate.expirationTime) return acc; | ||
return acc ? Math.min(acc, rate.expirationTime) : rate.expirationTime; | ||
}, 0); | ||
}; | ||
|
||
export const getRefreshTime = (rates: ExchangeRate[] | undefined) => { | ||
const minimumExpirationTime = rates ? getMinimumExpirationTime(rates) : null; | ||
if (minimumExpirationTime) { | ||
const timeMs = minimumExpirationTime - Date.now(); | ||
return Math.min(timeMs, DEFAULT_SWAP_RATES_INTERVAL_MS); | ||
} else { | ||
return DEFAULT_SWAP_RATES_INTERVAL_MS; | ||
} | ||
}; |
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
Oops, something went wrong.