Skip to content
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

Feat: integrate cic provider #1817

Merged
merged 17 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lazy-dingos-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-common": minor
---

CIC swap integration
5 changes: 5 additions & 0 deletions .changeset/metal-guests-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": minor
---

CIC swap integration
5 changes: 5 additions & 0 deletions .changeset/wise-dryers-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": minor
---

CIC swap integration
5 changes: 5 additions & 0 deletions apps/ledger-live-desktop/src/config/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ export const urls = {
tos: "https://changelly.com/terms-of-use",
support: "https://support.changelly.com/en/support/tickets/new",
},
cic: {
main: "https://criptointercambio.com/",
tos: "https://criptointercambio.com/terms-of-use",
support: "mailto:support@criptointercambio.com",
},
wyre: {
main: "https://support.sendwyre.com/hc/en-us/requests/new",
tos: "https://www.sendwyre.com/user-agreement/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import styled from "styled-components";
import { TokenCurrency } from "@ledgerhq/types-cryptoassets";
import { Transaction, TransactionStatus } from "@ledgerhq/live-common/generated/types";
import { ExchangeRate, Exchange } from "@ledgerhq/live-common/exchange/swap/types";
import { getProviderName } from "@ledgerhq/live-common/exchange/swap/utils/index";

import { getProviderName, getNoticeType } from "@ledgerhq/live-common/exchange/swap/utils/index";
import { WrongDeviceForAccount, UpdateYourApp, LockedDeviceError } from "@ledgerhq/errors";

import { LatestFirmwareVersionRequired } from "@ledgerhq/live-common/errors";
import { DeviceModelId, getDeviceModel } from "@ledgerhq/devices";
import { Device } from "@ledgerhq/live-common/hw/actions/types";
Expand Down Expand Up @@ -720,6 +722,9 @@ export const renderSwapDeviceConfirmation = ({
getAccountName(exchange.toAccount),
getAccountCurrency(exchange.toAccount),
];
const providerName = getProviderName(exchangeRate.provider);
const noticeType = getNoticeType(exchangeRate.provider);
const alertProperties = noticeType.learnMore ? { learnMoreUrl: urls.swap.learnMore } : {};
return (
<>
<ConfirmWrapper>
Expand All @@ -732,8 +737,8 @@ export const renderSwapDeviceConfirmation = ({
swapVersion={SWAP_VERSION}
/>
<Box flex={0}>
<Alert type="primary" learnMoreUrl={urls.swap.learnMore} mb={7} mx={4}>
<Trans i18nKey="DeviceAction.swap.notice" />
<Alert type="primary" {...alertProperties} mb={7} mx={4}>
<Trans i18nKey={`DeviceAction.swap.notice.${noticeType.message}`} />
</Alert>
</Box>
<Box mx={6} data-test-id="device-swap-summary">
Expand All @@ -758,7 +763,7 @@ export const renderSwapDeviceConfirmation = ({
provider: (
<Box horizontal alignItems="center" style={{ gap: "6px" }}>
<ProviderIcon size={18} />
<Text>{getProviderName(exchangeRate.provider)}</Text>
<Text>{providerName}</Text>
</Box>
),
fees: (
Expand Down
24 changes: 24 additions & 0 deletions apps/ledger-live-desktop/src/renderer/icons/Cic.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// @flow
This conversation was marked as resolved.
Show resolved Hide resolved

import React from "react";

const Cic = ({ size, color = "currentColor" }: { size: number, color?: string }) => (
<svg width={size} height={size}>
<g clipPath="url(#clip0_2553_24519)">
<path
fillRule="evenodd"
clipRule="evenodd"
d="M0 20.4387V28C8.37632 28 15.1667 21.732 15.1667 14C15.1667 6.26801 8.37632 0 0 0V7.56125C3.86599 7.56125 7 10.444 7 14C7 17.556 3.86599 20.4387 0 20.4387Z"
fill="#3A57CA"
/>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M27.1667 8.46154V0C18.7903 0 12 6.26801 12 14C12 21.732 18.7903 28 27.1667 28V19.5385C23.853 19.5385 21.1667 17.0588 21.1667 14C21.1667 10.9412 23.853 8.46154 27.1667 8.46154Z"
fill="#F57382"
/>
</g>
</svg>
);

export default Cic;
sarneijim marked this conversation as resolved.
Show resolved Hide resolved
24 changes: 24 additions & 0 deletions apps/ledger-live-desktop/src/renderer/icons/providers/Cic.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// @flow
This conversation was marked as resolved.
Show resolved Hide resolved

import React from "react";

const Cic = ({ size }: { size: number }) => (
<svg width={size} height={size}>
<g clipPath="url(#clip0_2553_24519)">
<path
fillRule="evenodd"
clipRule="evenodd"
d="M0 20.4387V28C8.37632 28 15.1667 21.732 15.1667 14C15.1667 6.26801 8.37632 0 0 0V7.56125C3.86599 7.56125 7 10.444 7 14C7 17.556 3.86599 20.4387 0 20.4387Z"
fill="#3A57CA"
/>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M27.1667 8.46154V0C18.7903 0 12 6.26801 12 14C12 21.732 18.7903 28 27.1667 28V19.5385C23.853 19.5385 21.1667 17.0588 21.1667 14C21.1667 10.9412 23.853 8.46154 27.1667 8.46154Z"
fill="#F57382"
/>
</g>
</svg>
);

export default Cic;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Changelly from "./Changelly";
import Cic from "./Cic";
import Coinify from "./Coinify";
import CoinifySquare from "./CoinifySquare";
import MoonPay from "./MoonPay";
Expand All @@ -10,4 +11,4 @@ import FTXLogo from "./FTX";
const FTX = FTXLogo();
const FTXUS = FTXLogo(true);

export { Changelly, Coinify, CoinifySquare, MoonPay, Oneinch, Paraswap, Wyre, FTX, FTXUS };
export { Changelly, Cic, Coinify, CoinifySquare, MoonPay, Oneinch, Paraswap, Wyre, FTX, FTXUS };
5 changes: 4 additions & 1 deletion apps/ledger-live-desktop/static/i18n/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,10 @@
"listApps": "Checking App dependencies",
"listAppsDescription": "Please wait while we make sure you have all the required apps",
"swap": {
"notice": "Verify the Swap details on your device before sending it. The addresses are exchanged securely so you don’t have to verify them.",
"notice": {
"default": "Verify the Swap details on your device before sending it. The addresses are exchanged securely so you don’t have to verify them.",
"cic": "Verify the Swap details on your device before sending it. CIC may need to perform additional verification for some transactions, resulting in a delay."
},
"confirm": "Confirm Swap transaction",
"amountSent": "Amount to send",
"amountReceived": "Amount to receive",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { getDeviceModel } from "@ledgerhq/devices";
import { Device } from "@ledgerhq/live-common/hw/actions/types";
import { AppRequest } from "@ledgerhq/live-common/hw/actions/app";
import firmwareUpdateRepair from "@ledgerhq/live-common/hw/firmwareUpdate-repair";
import { getProviderName } from "@ledgerhq/live-common/exchange/swap/utils/index";
import {
getProviderName,
getNoticeType,
} from "@ledgerhq/live-common/exchange/swap/utils/index";
import {
InfiniteLoader,
Text,
Expand Down Expand Up @@ -264,12 +267,16 @@ export function renderConfirmSwap({
estimatedFees?: string | null;
}) {
const ProviderIcon = providerIcons[exchangeRate.provider.toLowerCase()];

const providerName = getProviderName(exchangeRate.provider);
const noticeType = getNoticeType(exchangeRate.provider);
const alertProperties = noticeType.learnMore
? { learnMoreUrl: urls.swap.learnMore }
: {};
return (
<ScrollView>
<Wrapper width="100%">
<Alert type="primary" learnMoreUrl={urls.swap.learnMore}>
{t("DeviceAction.confirmSwap.alert")}
<Alert type="primary" {...alertProperties}>
{t(`DeviceAction.confirmSwap.alert.${noticeType.message}`)}
</Alert>
<AnimationContainer
marginTop="16px"
Expand Down Expand Up @@ -314,7 +321,7 @@ export function renderConfirmSwap({
<ProviderIcon size={14} />
</Flex>

<Text>{getProviderName(exchangeRate.provider)}</Text>
<Text>{providerName}</Text>
</Flex>
</FieldItem>

Expand Down
5 changes: 5 additions & 0 deletions apps/ledger-live-mobile/src/config/urls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ export const urls = {
main: "https://changelly.com/",
tos: "https://changelly.com/terms-of-use",
},
cic: {
main: "https://criptointercambio.com/",
support: "mailto:support@criptointercambio.com",
tos: "https://criptointercambio.com/terms-of-use",
},
wyre: {
main: "https://support.sendwyre.com/hc/en-us/requests/new",
tos: "https://www.sendwyre.com/user-agreement/",
Expand Down
21 changes: 21 additions & 0 deletions apps/ledger-live-mobile/src/icons/swap/Cic.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from "react";
import Svg, { G, Path } from "react-native-svg";

export const Cic = React.memo(({ size }: { size: number }) => (
<Svg width={size} height={size}>
<G clipPath="url(#clip0_2553_24519)">
<Path
fillRule="evenodd"
clipRule="evenodd"
d="M0 20.4387V28C8.37632 28 15.1667 21.732 15.1667 14C15.1667 6.26801 8.37632 0 0 0V7.56125C3.86599 7.56125 7 10.444 7 14C7 17.556 3.86599 20.4387 0 20.4387Z"
fill="#3A57CA"
/>
<Path
fillRule="evenodd"
clipRule="evenodd"
d="M27.1667 8.46154V0C18.7903 0 12 6.26801 12 14C12 21.732 18.7903 28 27.1667 28V19.5385C23.853 19.5385 21.1667 17.0588 21.1667 14C21.1667 10.9412 23.853 8.46154 27.1667 8.46154Z"
fill="#F57382"
/>
</G>
</Svg>
));
2 changes: 2 additions & 0 deletions apps/ledger-live-mobile/src/icons/swap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import React from "react";
import Svg, { Path } from "react-native-svg";
import { getFTXLogo } from "./FTX";
import { Changelly } from "./Changelly";
import { Cic } from "./Cic";
import { Wyre } from "./Wyre";

export { Paraswap } from "./Paraswap";

export const providerIcons: Record<string, React.FC<{ size: number }>> = {
changelly: React.memo(Changelly),
cic: React.memo(Cic),
ftx: getFTXLogo(),
ftxus: getFTXLogo(true),
wyre: React.memo(Wyre),
Expand Down
5 changes: 4 additions & 1 deletion apps/ledger-live-mobile/src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -3531,7 +3531,10 @@
},
"confirmSwap": {
"title": "Confirm swap operation on device",
"alert": "Verify the Swap details on your device before sending it. The addresses are exchanged securely so you don’t have to verify them.",
"alert": {
"default": "Verify the Swap details on your device before sending it. The addresses are exchanged securely so you don’t have to verify them.",
"cic": "Verify the Swap details on your device before sending it. CIC may need to perform additional verification for some transactions, resulting in a delay."
},
"acceptTerms": "By validating this transaction, I accept\n<0><0>{{provider}}</0>'s terms of use</0>",
"notice": "Verify the Swap details on your device before sending it. The addresses are exchanged securely so you don’t have to verify them."
},
Expand Down
9 changes: 9 additions & 0 deletions apps/ledger-live-mobile/src/screens/DebugSwap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ export default function DebugSwap() {
{"Disable Changelly"}
</LText>
</Touchable>
<Touchable
onPress={() => onToggleProvider("cic")}
style={styles.switchRow}
>
<CheckBox isChecked={currentDisabledProviders.includes("cic")} />
<LText semiBold style={styles.switchLabel}>
{"Disable CIC"}
</LText>
</Touchable>
<Touchable
onPress={() => onToggleProvider("wyre")}
style={styles.switchRow}
Expand Down
45 changes: 31 additions & 14 deletions libs/ledger-live-common/src/exchange/swap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,19 @@ const getSwapAPIVersion: () => number = () => {
return version;
};

const getNameAndPubKey = (name: string, publicKey: string): Buffer => {
return Buffer.concat([
Buffer.from([name.length]),
sarneijim marked this conversation as resolved.
Show resolved Hide resolved
Buffer.from(name, "ascii"),
Buffer.from(publicKey, "hex"),
]);
};

const ftx = {
nameAndPubkey: Buffer.concat([
Buffer.from([3]),
Buffer.from("FTX", "ascii"),
Buffer.from(
"04c89f3e48cde252f6cd6fcccc47c2f6ca6cf05f9f921703d31b7a7dddbf0bd6a690744662fe599f8761612021ba1fc0e8a5a4b7d5910c625b6dd09aa40762e5cd",
"hex"
),
]),
nameAndPubkey: getNameAndPubKey(
"FTX",
"04c89f3e48cde252f6cd6fcccc47c2f6ca6cf05f9f921703d31b7a7dddbf0bd6a690744662fe599f8761612021ba1fc0e8a5a4b7d5910c625b6dd09aa40762e5cd"
),
signature: Buffer.from(
"3044022029c0fb80d6e524f811f30cc04a349fa7f8896ce1ba84010da55f7be5eb9d528802202727985361cab969ad9b4f56570f3f6120c1d77d04ba10e5d99366d8eecee8e2",
"hex"
Expand All @@ -70,9 +74,9 @@ const ftx = {

const swapProviders: Record<string, SwapProviderConfig> = {
changelly: {
nameAndPubkey: Buffer.from(
"094368616e67656c6c790480d7c0d3a9183597395f58dda05999328da6f18fabd5cda0aff8e8e3fc633436a2dbf48ecb23d40df7c3c7d3e774b77b4b5df0e9f7e08cf1cdf2dba788eb085b",
"hex"
nameAndPubkey: getNameAndPubKey(
"Changelly",
"0480d7c0d3a9183597395f58dda05999328da6f18fabd5cda0aff8e8e3fc633436a2dbf48ecb23d40df7c3c7d3e774b77b4b5df0e9f7e08cf1cdf2dba788eb085b"
),
signature: Buffer.from(
"3045022100e73339e5071b5d232e8cacecbd7c118c919122a43f8abb8b2062d4bfcd58274e022050b11605d8b7e199f791266146227c43fd11d7645b1d881f705a2f8841d21de5",
Expand All @@ -82,11 +86,24 @@ const swapProviders: Record<string, SwapProviderConfig> = {
needsKYC: false,
needsBearerToken: false,
},
wyre: {
nameAndPubkey: Buffer.from(
"045779726504AD01A6241929A5EC331046868FBACB424696FD7C8A4D824FEE61268374E9F4F87FFC5301F0E0A84CEA69FFED46E14C771F9CA1EEA345F6531994291C816E8AE6",
cic: {
nameAndPubkey: getNameAndPubKey(
"CIC",
"0444a71652995d15ef0d4d6fe8de21a0c8ad48bdbfea7f789319973669785ca96abca9fd0c504c3074d9b654f0e3a76dde642a03efe4ccdee3af3ca4ba4afa202d"
),
signature: Buffer.from(
"3044022078a73433ab6289027b7a169a260f180d16346f7ab55b06a22109f68a756d691d0220190edd6e1214c3309dc1b0afe90d217b728377491561383f2ee543e2c90188eb",
"hex"
),
curve: "secpk256k1",
needsKYC: false,
needsBearerToken: false,
},
wyre: {
nameAndPubkey: getNameAndPubKey(
"Wyre",
"04AD01A6241929A5EC331046868FBACB424696FD7C8A4D824FEE61268374E9F4F87FFC5301F0E0A84CEA69FFED46E14C771F9CA1EEA345F6531994291C816E8AE6"
),
signature: Buffer.from(
"304402207b49e46d458a55daee9bc8ed96e1b404c2d99dbbc3d3c3c15430026eb7e01a05022011ab86db08a4c956874a83f23d918319a073fdd9df23a1c7eed8a0a22c98b1e3",
"hex"
Expand Down
27 changes: 27 additions & 0 deletions libs/ledger-live-common/src/exchange/swap/utils/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getAvailableAccountsById,
isRegistrationRequired,
getProviderName,
getNoticeType,
shouldShowKYCBanner,
shouldShowLoginBanner,
} from "./index";
Expand Down Expand Up @@ -347,3 +348,29 @@ describe("swap/utils/getProviderName", () => {
expect(result).toBe(expectedResult);
});
});

describe("swap/utils/getNoticeType", function () {
test("should return notice type for CIC", () => {
const expectedResult = { message: "cic", learnMore: false };

const result = getNoticeType("cic");

expect(result).toBe(expectedResult);
});

test("should return notice type for ftx", () => {
const expectedResult = { message: "default", learnMore: true };

const result = getNoticeType("ftx");

expect(result).toBe(expectedResult);
});

test("should return notice type for Changelly", () => {
const expectedResult = { message: "default", learnMore: true };

const result = getNoticeType("changelly");

expect(result).toBe(expectedResult);
});
});
12 changes: 12 additions & 0 deletions libs/ledger-live-common/src/exchange/swap/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,22 @@ export const isRegistrationRequired = (provider: string): boolean => {

export const getProviderName = (provider: string): string => {
switch (provider) {
case "cic":
case "ftx":
case "ftxus":
return provider.toUpperCase();
default:
return provider.charAt(0).toUpperCase() + provider.slice(1);
}
};

export const getNoticeType = (
provider: string
): { message: string; learnMore: boolean } => {
switch (provider) {
case "cic":
return { message: "cic", learnMore: false };
default:
return { message: "default", learnMore: true };
}
};