-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(LIVE-8241): implement call to v5 /currencies/from endpoint for s…
…wap (#4258) * feat(LIVE-8241): add api call and mock data for swap/from endpoint * feat(LIVE-8241): refactor code to use new helper * feat(LIVE-8241): changeset
- Loading branch information
1 parent
707e59f
commit e8a7bc5
Showing
11 changed files
with
296 additions
and
13 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@ledgerhq/live-common": patch | ||
--- | ||
|
||
feat(LIVE-8241): implement call to v5 /currencies/from endpoint for swap |
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
197 changes: 197 additions & 0 deletions
197
libs/ledger-live-common/src/exchange/swap/api/v5/__mocks__/fetchCurrencyFrom.mocks.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,197 @@ | ||
import { ResponseData } from "../fetchCurrencyFrom"; | ||
|
||
export const fetchCurrencyFromMock: ResponseData = { | ||
currencyGroups: [ | ||
{ | ||
network: "ethereum", | ||
supportedCurrencies: [ | ||
"ethereum/erc20/celer", | ||
"ethereum/erc20/powerledger", | ||
"ethereum/erc20/dydx", | ||
"ethereum/erc20/lcx", | ||
"ethereum/erc20/amp", | ||
"ethereum/erc20/pundi_x_token", | ||
"ethereum/erc20/usd_tether__erc20_", | ||
"ethereum/erc20/paxos_standard__pax_", | ||
"ethereum/erc20/gala", | ||
"ethereum/erc20/spell_token", | ||
"ethereum/erc20/alchemy", | ||
"ethereum/erc20/funfair", | ||
"ethereum/erc20/mask_network", | ||
"ethereum/erc20/ultratoken", | ||
"ethereum/erc20/dusk_network", | ||
"ethereum/erc20/alchemix", | ||
"ethereum/erc20/meta_masters_guild", | ||
"ethereum/erc20/makerdao", | ||
"ethereum/erc20/bitdegree_token", | ||
"ethereum/erc20/aave", | ||
"ethereum/erc20/revv", | ||
"ethereum/erc20/audius", | ||
"ethereum/erc20/gitcoin", | ||
"ethereum/erc20/radicle", | ||
"ethereum/erc20/perpetual", | ||
"ethereum/erc20/alice", | ||
"ethereum/erc20/selfkey", | ||
"ethereum/erc20/trace", | ||
"ethereum/erc20/injective_token", | ||
"ethereum/erc20/gods_unchained", | ||
"ethereum/erc20/bounce_token_auction", | ||
"ethereum/erc20/axie_infinity_shard", | ||
"ethereum/erc20/render_token", | ||
"ethereum/erc20/uma_voting_token_v1", | ||
"ethereum/erc20/ampleforth_governance", | ||
"ethereum/erc20/digix_dao", | ||
"ethereum/erc20/stpt", | ||
"ethereum/erc20/superrare", | ||
"ethereum/erc20/dent", | ||
"ethereum/erc20/eqifi_token", | ||
"ethereum/erc20/dai_stablecoin_v2_0", | ||
"ethereum/erc20/smooth_love_potion", | ||
"ethereum/erc20/telcoin", | ||
"ethereum/erc20/steth", | ||
"ethereum/erc20/wootrade_network", | ||
"ethereum/erc20/apecoin", | ||
"ethereum/erc20/status_network_token", | ||
"ethereum/erc20/nmr", | ||
"ethereum/erc20/orbs", | ||
"ethereum/erc20/vera_", | ||
"ethereum/erc20/polkastartertoken", | ||
"ethereum/erc20/akropolis", | ||
"ethereum/erc20/looksrare_token", | ||
"ethereum/erc20/concentrated_voting_power", | ||
"ethereum/erc20/chiliz", | ||
"ethereum/erc20/link_chainlink", | ||
"ethereum/erc20/fantom_token", | ||
"ethereum/erc20/sushi", | ||
"ethereum/erc20/omg", | ||
"ethereum/erc20/reserve_rights", | ||
"ethereum/erc20/gnosis", | ||
"ethereum/erc20/kucoin_token", | ||
"ethereum/erc20/zap", | ||
"ethereum/erc20/binance_usd", | ||
"ethereum/erc20/alphatoken", | ||
"ethereum/erc20/1inch_token", | ||
"ethereum/erc20/dentacoin", | ||
"ethereum/erc20/wliticapital", | ||
"ethereum/erc20/healthcare_administration_token", | ||
"ethereum/erc20/league_of_kingdoms_arena", | ||
"ethereum/erc20/marlin_pond", | ||
"ethereum/erc20/tribe", | ||
"ethereum/erc20/aragon_network_token", | ||
"ethereum/erc20/hedgetrade_token", | ||
"ethereum/erc20/stasis_eurs_token", | ||
"ethereum/erc20/reef_finance", | ||
"ethereum/erc20/bancor", | ||
"ethereum/erc20/chsb", | ||
"ethereum/erc20/trusttoken", | ||
"ethereum/erc20/metalpay", | ||
"ethereum/erc20/yield_guild_games_token", | ||
"ethereum/erc20/coin98", | ||
"ethereum/erc20/loom_token", | ||
"ethereum/erc20/biconomy_token", | ||
"ethereum/erc20/api3", | ||
"ethereum/erc20/ftx_token", | ||
"ethereum/erc20/pumapay", | ||
"ethereum/erc20/okb", | ||
"ethereum/erc20/terra_virtua_kolect", | ||
"ethereum/erc20/iexec_rlc", | ||
"ethereum/erc20/frax_share", | ||
"ethereum/erc20/jasmycoin", | ||
"ethereum/erc20/euro_stable_token", | ||
"ethereum/erc20/bluezelle", | ||
"ethereum/erc20/dodo_bird", | ||
"ethereum/erc20/stormx", | ||
"ethereum/erc20/yearn_finance", | ||
"ethereum/erc20/dogelon", | ||
"ethereum/erc20/illuvium", | ||
"ethereum/erc20/perlin", | ||
"ethereum/erc20/threshold_network_token", | ||
"ethereum/erc20/utrust_token", | ||
"ethereum/erc20/enjin", | ||
"ethereum/erc20/huobitoken", | ||
"ethereum/erc20/synthetix_network_token", | ||
"ethereum/erc20/nexo", | ||
"ethereum/erc20/idex_token", | ||
"ethereum/erc20/kyber_network_crystal_v2", | ||
"ethereum/erc20/ssv_token", | ||
"ethereum/erc20/naga_coin", | ||
"ethereum/erc20/republic_protocol", | ||
"ethereum/erc20/shiba_inu", | ||
"ethereum/erc20/celsius", | ||
"ethereum/erc20/0x_project", | ||
"ethereum/erc20/edgeless", | ||
"ethereum/erc20/ethereum_name_service", | ||
"ethereum/erc20/populous", | ||
"ethereum/erc20/derace_token", | ||
"ethereum/erc20/frontier_token", | ||
"ethereum/erc20/vib", | ||
"ethereum/erc20/golem_network_token", | ||
"ethereum/erc20/decentraland_mana", | ||
"ethereum/erc20/xy_oracle", | ||
"ethereum/erc20/berry", | ||
"ethereum/erc20/usd__coin", | ||
"ethereum/erc20/civic", | ||
"ethereum/erc20/ankr_network", | ||
"ethereum/erc20/paxos_gold", | ||
"ethereum/erc20/tenx", | ||
"ethereum/erc20/curve_dao_token", | ||
"ethereum/erc20/compound", | ||
"ethereum/erc20/origintoken", | ||
"ethereum/erc20/orion_protocol", | ||
"ethereum/erc20/sand", | ||
"ethereum/erc20/skale", | ||
"ethereum/erc20/singularitynet_token", | ||
"ethereum", | ||
"ethereum/erc20/dexe", | ||
"ethereum/erc20/yfii_finance", | ||
"ethereum/erc20/orchid", | ||
"ethereum/erc20/occ", | ||
"ethereum/erc20/btrst", | ||
"ethereum/erc20/graph_token", | ||
"ethereum/erc20/loopringcoin_v2", | ||
"ethereum/erc20/livepeer", | ||
"ethereum/erc20/hifi_finance", | ||
"ethereum/erc20/wrapped_bitcoin", | ||
"ethereum/erc20/stargatetoken", | ||
"ethereum/erc20/badger", | ||
"ethereum/erc20/melon_token", | ||
"ethereum/erc20/ripio_credit_network", | ||
"ethereum/erc20/immutable_x", | ||
"ethereum/erc20/quant", | ||
"ethereum/erc20/arpa_token", | ||
"ethereum/erc20/machine_xchange_coin", | ||
"ethereum/erc20/voyager_token", | ||
"ethereum/erc20/holotoken", | ||
"ethereum/erc20/convex_token", | ||
"ethereum/erc20/matic", | ||
"ethereum/erc20/storj", | ||
"ethereum/erc20/aergo", | ||
"ethereum/erc20/suku", | ||
"ethereum/erc20/merit_circle", | ||
"ethereum/erc20/efinity_token", | ||
"ethereum/erc20/farm_reward_token", | ||
"ethereum/erc20/linear_token", | ||
"ethereum/erc20/roobee", | ||
"ethereum/erc20/adventure_gold", | ||
"ethereum/erc20/student_coin", | ||
"ethereum/erc20/bat", | ||
"ethereum/erc20/rally", | ||
"ethereum/erc20/lido_dao_token", | ||
"ethereum/erc20/chroma", | ||
"ethereum/erc20/project_galaxy", | ||
"ethereum/erc20/standard", | ||
"ethereum/erc20/ocean", | ||
"ethereum/erc20/constitutiondao", | ||
"ethereum/erc20/starlink", | ||
"ethereum/erc20/kryll", | ||
"ethereum/erc20/dash_2_trade", | ||
"ethereum/erc20/uniswap", | ||
"ethereum/erc20/blur", | ||
"ethereum/erc20/leo_token", | ||
"ethereum/erc20/boson_token", | ||
"ethereum/erc20/trueusd", | ||
"ethereum/erc20/unbound", | ||
], | ||
}, | ||
], | ||
}; |
26 changes: 26 additions & 0 deletions
26
libs/ledger-live-common/src/exchange/swap/api/v5/__tests__/fetchCurrencyFrom.spec.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,26 @@ | ||
import network from "@ledgerhq/live-network/network"; | ||
import { fetchCurrencyFrom } from "../fetchCurrencyFrom"; | ||
import { fetchCurrencyFromMock } from "../__mocks__/fetchCurrencyFrom.mocks"; | ||
import { DEFAULT_SWAP_TIMEOUT_MS } from "../../../const/timeout"; | ||
|
||
jest.mock("@ledgerhq/live-network/network"); | ||
|
||
describe("fetchCurrencyFrom", () => { | ||
it("success with 200", async () => { | ||
(network as jest.Mock).mockImplementation(() => ({ | ||
data: fetchCurrencyFromMock, | ||
})); | ||
|
||
const result = await fetchCurrencyFrom({ | ||
providers: ["changelly", "cic", "oneinch"], | ||
currencyTo: "bitcoin", | ||
}); | ||
|
||
expect(result).toStrictEqual(fetchCurrencyFromMock); | ||
expect(network as jest.Mock).toHaveBeenCalledWith({ | ||
method: "GET", | ||
timeout: DEFAULT_SWAP_TIMEOUT_MS, | ||
url: "https://swap-stg.ledger.com/v5/currencies/from?providers-whitelist=changelly%2Ccic%2Coneinch&additional-coins-flag=false¤cyTo=bitcoin", | ||
}); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
libs/ledger-live-common/src/exchange/swap/api/v5/fetchCurrencyFrom.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,43 @@ | ||
import network from "@ledgerhq/live-network/network"; | ||
import { isPlaywrightEnv } from "../../utils/isPlaywrightEnv"; | ||
import { getEnv } from "../../../../env"; | ||
import { DEFAULT_SWAP_TIMEOUT_MS } from "../../const/timeout"; | ||
|
||
type Props = { | ||
providers: Array<string>; | ||
currencyTo?: string; | ||
additionalCoinsFlag?: boolean; | ||
}; | ||
|
||
export type ResponseData = { | ||
currencyGroups: Array<{ | ||
network: string; | ||
supportedCurrencies: Array<string>; | ||
}>; | ||
}; | ||
|
||
export async function fetchCurrencyFrom({ | ||
providers, | ||
currencyTo, | ||
additionalCoinsFlag = false, | ||
}: Props) { | ||
if (isPlaywrightEnv()) return Promise.resolve(fetchCurrencyFrom); | ||
|
||
const url = new URL(`${getEnv("SWAP_API_BASE_V5")}/currencies/from`); | ||
url.searchParams.append("providers-whitelist", providers.join(",")); | ||
url.searchParams.append("additional-coins-flag", additionalCoinsFlag.toString()); | ||
if (currencyTo) { | ||
url.searchParams.append("currencyTo", currencyTo); | ||
} | ||
|
||
try { | ||
const { data } = await network<ResponseData>({ | ||
method: "GET", | ||
url: url.toString(), | ||
timeout: DEFAULT_SWAP_TIMEOUT_MS, | ||
}); | ||
return data; | ||
} catch (e) { | ||
throw Error("Something went wrong in fetchCurrencyFrom call"); | ||
} | ||
} |
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 @@ | ||
export const DEFAULT_SWAP_TIMEOUT_MS = 10000; |
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
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
3 changes: 3 additions & 0 deletions
3
libs/ledger-live-common/src/exchange/swap/utils/isPlaywrightEnv.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,3 @@ | ||
import { getEnv } from "../../../env"; | ||
|
||
export const isPlaywrightEnv = () => getEnv("MOCK") && !getEnv("PLAYWRIGHT_RUN"); |
e8a7bc5
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.
Successfully deployed to the following URLs:
live-common-tools – ./
ledger-live.vercel.app
live-common-tools-ledgerhq.vercel.app
ledger-live-tools.vercel.app
live.ledger.tools
live-common-tools-git-develop-ledgerhq.vercel.app