Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Commit

Permalink
Solana Integration (#2055)
Browse files Browse the repository at this point in the history
* solana init family

* solana add support page url

* solana fix lint

* solana parametrize memo too long error

* solana add opt in flow

* remove tokens related code
  • Loading branch information
konoart authored Jan 3, 2022
1 parent 8b7065e commit 16e609c
Show file tree
Hide file tree
Showing 8 changed files with 290 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/config/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,7 @@ export const urls = {
elrond: {
website: "https://elrond.com",
},
solana: {
supportPage: "https://support.ledger.com",
},
};
3 changes: 3 additions & 0 deletions src/const/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ export const ScreenName = {
RequestAccountsSelectAccount: "RequestAccountsSelectAccount",

VerifyAccount: "VerifyAccount",

// solana
SolanaEditMemo: "SolanaEditMemo",
};

export const NavigatorName = {
Expand Down
1 change: 1 addition & 0 deletions src/families/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from "./tron";
export * from "./cosmos";
export * from "./algorand";
export * from "./polkadot";
export * from "./solana";
116 changes: 116 additions & 0 deletions src/families/solana/ScreenEditMemo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// @flow
import React, { useCallback, useState } from "react";
import { View, StyleSheet, ScrollView } from "react-native";
import SafeAreaView from "react-native-safe-area-view";
import { useTranslation } from "react-i18next";
import i18next from "i18next";
import type { Account } from "@ledgerhq/live-common/lib/types";
import type { Transaction } from "@ledgerhq/live-common/lib/families/solana/types";
import { getAccountBridge } from "@ledgerhq/live-common/lib/bridge";
import { useTheme } from "@react-navigation/native";
import KeyboardView from "../../components/KeyboardView";
import Button from "../../components/Button";
import { ScreenName } from "../../const";
import TextInput from "../../components/FocusedTextInput";

const forceInset = { bottom: "always" };

type Props = {
navigation: any,
route: { params: RouteParams },
};

type RouteParams = {
account: Account,
transaction: Transaction,
};

function SolanaEditMemo({ navigation, route }: Props) {
const { colors } = useTheme();
const { t } = useTranslation();
const [memo, setMemo] = useState(route.params.transaction.model.uiState.memo);
const account = route.params.account;

const onValidateText = useCallback(() => {
const bridge = getAccountBridge(account);
const { transaction } = route.params;
const nextTx = bridge.updateTransaction(transaction, {
model: {
...transaction.model,
uiState: {
...transaction.model.uiState,
memo,
},
},
});
navigation.navigate(ScreenName.SendSummary, {
accountId: account.id,
transaction: nextTx,
});
}, [navigation, route.params, account, memo]);

return (
<SafeAreaView style={styles.root} forceInset={forceInset}>
<KeyboardView
style={[styles.body, { backgroundColor: colors.background }]}
>
<ScrollView
contentContainerStyle={styles.root}
keyboardShouldPersistTaps="always"
>
<TextInput
allowFontScaling={false}
autoFocus
style={[styles.textInputAS, { color: colors.darkBlue }]}
defaultValue={memo}
keyboardType="default"
returnKeyType="done"
onChangeText={setMemo}
multiline
onSubmitEditing={onValidateText}
/>

<View style={styles.flex}>
<Button
event="SolanaEditMemoContinue"
type="primary"
title={t("send.summary.validateMemo")}
onPress={onValidateText}
containerStyle={styles.buttonContainer}
/>
</View>
</ScrollView>
</KeyboardView>
</SafeAreaView>
);
}

const options = {
title: i18next.t("send.summary.memo.title"),
headerLeft: null,
};

export { SolanaEditMemo as component, options };

const styles = StyleSheet.create({
root: {
flex: 1,
},
body: {
flexDirection: "column",
flex: 1,
},
textInputAS: {
padding: 16,
fontSize: 30,
},
buttonContainer: {
marginHorizontal: 16,
},
flex: {
flex: 1,
flexDirection: "column",
justifyContent: "flex-end",
paddingBottom: 16,
},
});
81 changes: 81 additions & 0 deletions src/families/solana/SendRowsCustom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// @flow
import React, { useCallback } from "react";
import { View, StyleSheet } from "react-native";
import { useTranslation } from "react-i18next";
import { useTheme } from "@react-navigation/native";
import type { Account } from "@ledgerhq/live-common/lib/types";
import type { Transaction } from "@ledgerhq/live-common/lib/families/solana/types";
import LText from "../../components/LText";
import { ScreenName } from "../../const";
import SummaryRow from "../../screens/SendFunds/SummaryRow";

type Props = {
account: Account,
transaction: Transaction,
navigation: any,
};

export default function SolanaSendRowsCustom({
account,
transaction,
navigation,
}: Props) {
const { colors } = useTheme();
const { t } = useTranslation();

const editMemo = useCallback(() => {
navigation.navigate(ScreenName.SolanaEditMemo, {
account,
transaction,
});
}, [navigation, account, transaction]);

return (
<View>
<SummaryRow title={t("send.summary.memo.title")} onPress={editMemo}>
{transaction.model.uiState.memo ? (
<LText
semiBold
style={styles.tagText}
onPress={editMemo}
numberOfLines={1}
>
{transaction.model.uiState.memo}
</LText>
) : (
<LText
style={[
styles.link,
{
textDecorationColor: colors.live,
},
]}
color="live"
onPress={editMemo}
>
{t("common.edit")}
</LText>
)}
</SummaryRow>
</View>
);
}

const styles = StyleSheet.create({
memoContainer: {
flexDirection: "row",
},
tagText: {
flex: 1,
fontSize: 14,
textAlign: "right",
},
link: {
textDecorationStyle: "solid",
textDecorationLine: "underline",
marginLeft: 8,
},
memo: {
marginBottom: 10,
},
});
73 changes: 73 additions & 0 deletions src/families/solana/SendRowsFee.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// @flow
import React, { useCallback } from "react";
import { View, StyleSheet, Linking } from "react-native";
import type { AccountLike } from "@ledgerhq/live-common/lib/types";
import { Trans } from "react-i18next";
import type { Transaction } from "@ledgerhq/live-common/lib/families/solana/types";
import {
getAccountUnit,
getAccountCurrency,
} from "@ledgerhq/live-common/lib/account";
import { useTheme } from "@react-navigation/native";
import SummaryRow from "../../screens/SendFunds/SummaryRow";
import LText from "../../components/LText";
import CurrencyUnitValue from "../../components/CurrencyUnitValue";
import CounterValue from "../../components/CounterValue";
import ExternalLink from "../../icons/ExternalLink";
import { urls } from "../../config/urls";

type Props = {
account: AccountLike,
transaction: Transaction,
};

export default function SolanaFeeRow({ account, transaction }: Props) {
const { colors } = useTheme();
const extraInfoFees = useCallback(() => {
Linking.openURL(urls.solana.supportPage);
}, []);

const fees = transaction.feeCalculator?.lamportsPerSignature;
const unit = getAccountUnit(account);
const currency = getAccountCurrency(account);

return (
<SummaryRow
onPress={extraInfoFees}
title={<Trans i18nKey="send.fees.title" />}
additionalInfo={
<View>
<ExternalLink size={12} color={colors.grey} />
</View>
}
>
<View style={{ alignItems: "flex-end" }}>
<View style={styles.accountContainer}>
{fees ? (
<LText style={styles.valueText}>
<CurrencyUnitValue unit={unit} value={fees} />
</LText>
) : null}
</View>
<LText style={styles.countervalue} color="grey">
{fees ? (
<CounterValue before="≈ " value={fees} currency={currency} />
) : null}
</LText>
</View>
</SummaryRow>
);
}

const styles = StyleSheet.create({
accountContainer: {
flex: 1,
flexDirection: "row",
},
countervalue: {
fontSize: 12,
},
valueText: {
fontSize: 16,
},
});
4 changes: 4 additions & 0 deletions src/families/solana/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @flow
import * as SolanaEditMemo from "./ScreenEditMemo";

export { SolanaEditMemo };
9 changes: 9 additions & 0 deletions src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,15 @@
"generic": {
"title": "{{message}}",
"description": "Something went wrong. Please try again. If the problem persists, please save your logs using the button below and provide them to Ledger Support."
},
"SolanaAccountNotFunded": {
"title": "Account not funded"
},
"SolanaAddressOfEd25519": {
"title": "Address off ed25519 curve"
},
"SolanaMemoIsTooLong": {
"title": "Memo is too long. Max length is {{maxLength}}"
}
},
"bluetooth": {
Expand Down

0 comments on commit 16e609c

Please sign in to comment.