Skip to content

Commit

Permalink
feat: rsk integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsan-javaiid committed Sep 12, 2022
1 parent 405f774 commit 51e4325
Show file tree
Hide file tree
Showing 21 changed files with 281 additions and 10 deletions.
Binary file added assets/img/currencies/png/RBTC.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/currencies/png/xusd.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/img/currencies/rbtc.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/img/currencies/xusd.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions src/constants/SupportedCurrencyOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React, {ReactElement} from 'react';
import BtcIcon from '../../assets/img/currencies/btc.svg';
import BchIcon from '../../assets/img/currencies/bch.svg';
import EthIcon from '../../assets/img/currencies/eth.svg';
import RbtcIcon from '../../assets/img/currencies/rbtc.svg';
import XUSDIcon from '../../assets/img/currencies/xusd.svg';
import DogeIcon from '../../assets/img/currencies/doge.svg';
import LtcIcon from '../../assets/img/currencies/ltc.svg';
import XrpIcon from '../../assets/img/currencies/xrp.svg';
Expand Down Expand Up @@ -32,6 +34,8 @@ export const CurrencyListIcons: {
btc: props => <BtcIcon {...props} />,
bch: props => <BchIcon {...props} />,
eth: props => <EthIcon {...props} />,
rbtc: props => <RbtcIcon {...props} />,
xusd: props => <XUSDIcon {...props} />,
doge: props => <DogeIcon {...props} />,
ltc: props => <LtcIcon {...props} />,
xrp: props => <XrpIcon {...props} />,
Expand Down Expand Up @@ -71,6 +75,14 @@ export const SupportedCurrencyOptions: Array<SupportedCurrencyOption> = [
hasMultisig: false, // TODO
imgSrc: require('../../assets/img/currencies/png/ETH.png'),
},
{
id: 'rbtc',
img: CurrencyListIcons.rbtc,
currencyName: 'RSK',
currencyAbbreviation: 'RBTC',
hasMultisig: false, // TODO
imgSrc: require('../../assets/img/currencies/png/RBTC.png'),
},
{
id: 'doge',
img: CurrencyListIcons.doge,
Expand Down Expand Up @@ -142,6 +154,14 @@ export const SupportedCurrencyOptions: Array<SupportedCurrencyOption> = [
isToken: true,
imgSrc: require('../../assets/img/currencies/png/BUSD.png'),
},
{
id: 'xusd',
img: CurrencyListIcons.xusd,
currencyName: 'Sovryn XUSD',
currencyAbbreviation: 'XUSD',
isToken: true,
imgSrc: require('../../assets/img/currencies/png/xusd.png'),
},
{
id: 'dai',
img: CurrencyListIcons.dai,
Expand Down
13 changes: 13 additions & 0 deletions src/constants/config.card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import BUSDShape from '../navigation/card/assets/currency-shapes/BUSD-shape.svg'
import DAIShape from '../navigation/card/assets/currency-shapes/DAI-shape.svg';
import DOGEShape from '../navigation/card/assets/currency-shapes/DOGE-shape.svg';
import ETHShape from '../navigation/card/assets/currency-shapes/ETH-shape.svg';
import RBTCShape from '../navigation/card/assets/currency-shapes/RBTC-shape.svg';
import GUSDShape from '../navigation/card/assets/currency-shapes/GUSD-shape.svg';
import USDPShape from '../navigation/card/assets/currency-shapes/USDP-shape.svg';
import USDCShape from '../navigation/card/assets/currency-shapes/USDC-shape.svg';
Expand Down Expand Up @@ -192,6 +193,18 @@ export const SUPPORTED_DESIGN_CURRENCIES: SupportedDesignCurrenciesConfig = {
pillCircleBackground: '#FFF',
},
},
RBTC: {
currency: 'RBTC',
enabled: true,
palette: {
BackgroundShape: RBTCShape,
stopColor1: '#9A9FF1',
stopColor2: '#575DC2',
pillColor: '#FFF',
pillBackground: '#595FC6',
pillCircleBackground: '#FFF',
},
},
GUSD: {
currency: 'GUSD',
enabled: true,
Expand Down
118 changes: 115 additions & 3 deletions src/constants/currencies.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type SupportedCoins = 'btc' | 'bch' | 'ltc' | 'doge' | 'eth';
export type SupportedCoins = 'btc' | 'bch' | 'ltc' | 'doge' | 'eth' | 'rbtc';
export type SupportedTokens =
| 'usdc'
| 'gusd'
Expand All @@ -8,7 +8,8 @@ export type SupportedTokens =
| 'wbtc'
| 'shib'
| 'ape'
| 'euroc';
| 'euroc'
| 'xusd';
export type SupportedCurrencies = SupportedCoins | SupportedTokens;

export interface CurrencyOpts {
Expand Down Expand Up @@ -168,6 +169,117 @@ export const Currencies: {[key in string]: CurrencyOpts} = {
gradientBackgroundColor: '#6b71d6',
},
},
rbtc: {
name: 'Smart Bitcoin',
chain: 'RSK',
coin: 'rbtc',
unitInfo: {
unitName: 'RBTC',
unitToSatoshi: 1e18,
unitDecimals: 18,
unitCode: 'rbtc'
},
properties: {
hasMultiSig: false,
hasMultiSend: false,
isUtxo: false,
isERCToken: false,
isStableCoin: false,
singleAddress: true
},
paymentInfo: {
paymentCode: 'EIP681',
protocolPrefix: { livenet: 'rsk', testnet: 'rsk' },
ratesApi: 'https://bws.bitpay.com/bws/api/v3/fiatrates/rbtc',
blockExplorerUrls: 'explorer.rsk.co/',
blockExplorerUrlsTestnet: 'explorer.testet.rsk.co/'
},
feeInfo: {
feeUnit: 'Gwei',
feeUnitAmount: 1e9,
blockTime: 0.53,
maxMerchantFee: 'urgent'
},
theme: {
coinColor: '#41d434',
backgroundColor: '#1e90ff',
gradientBackgroundColor: '#1e90ff'
}
},
rsk: { // This entry is because exchange-rates assumes that chain and coin are the same and asks for theme to 'rsk'
name: 'Smart Bitcoin',
chain: 'RSK',
coin: 'rbtc',
unitInfo: {
unitName: 'RBTC',
unitToSatoshi: 1e18,
unitDecimals: 18,
unitCode: 'rbtc'
},
properties: {
hasMultiSig: false,
hasMultiSend: false,
isUtxo: false,
isERCToken: false,
isStableCoin: false,
singleAddress: true
},
paymentInfo: {
paymentCode: 'EIP681',
protocolPrefix: { livenet: 'rsk', testnet: 'rsk' },
ratesApi: 'https://bws.bitpay.com/bws/api/v3/fiatrates/btc',
blockExplorerUrls: 'explorer.rsk.co/',
blockExplorerUrlsTestnet: 'explorer.testet.rsk.co/'
},
feeInfo: {
feeUnit: 'Gwei',
feeUnitAmount: 1e9,
blockTime: 0.53,
maxMerchantFee: 'urgent'
},
theme: {
coinColor: '#41d434',
backgroundColor: '#1e90ff',
gradientBackgroundColor: '#1e90ff'
},
},
xusd: {
name: 'Sovryn XUSD',
chain: 'RSK',
coin: 'xusd',
unitInfo: {
unitName: 'XUSD',
unitToSatoshi: 1e18,
unitDecimals: 18,
unitCode: 'xusd',
},
properties: {
hasMultiSig: false,
hasMultiSend: false,
isUtxo: false,
isERCToken: true,
isStableCoin: true,
singleAddress: true,
},
paymentInfo: {
paymentCode: 'EIP681',
protocolPrefix: { livenet: 'rsk', testnet: 'rsk' },
ratesApi: 'https://bws.bitpay.com/bws/api/v3/fiatrates/xusd',
blockExplorerUrls: 'explorer.rsk.co/',
blockExplorerUrlsTestnet: 'explorer.testet.rsk.co/'
},
feeInfo: {
feeUnit: 'Gwei',
feeUnitAmount: 1e9,
blockTime: 0.2,
maxMerchantFee: 'urgent',
},
theme: {
coinColor: '#f3ba2d',
backgroundColor: 'rgba(135,206,250,1)',
gradientBackgroundColor: 'rgba(30,144,255, 0.2)',
},
},
xrp: {
name: 'XRP',
chain: 'XRP',
Expand Down Expand Up @@ -628,7 +740,7 @@ export const SUPPORTED_TOKENS = [
'ape',
'euroc',
];
export const SUPPORTED_COINS = ['btc', 'bch', 'eth', 'doge', 'ltc', 'xrp'];
export const SUPPORTED_COINS = ['btc', 'bch', 'eth', 'rbtc', 'doge', 'ltc', 'xrp'];
export const SUPPORTED_CURRENCIES = [...SUPPORTED_COINS, ...SUPPORTED_TOKENS];
export const POPULAR_TOKENS = [
'UNI',
Expand Down
1 change: 1 addition & 0 deletions src/constants/defaultDerivationPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export enum DefaultDerivationPath {
defaultBTC = "m/44'/0'/0'",
defaultBCH = "m/44'/145'/0'",
defaultETH = "m/44'/60'/0'",
defaultRBTC = "m/44'/137'/0'",
defaultXRP = "m/44'/144'/0'",
defaultDOGE = "m/44'/3'/0'",
defaultLTC = "m/44'/2'/0'",
Expand Down
12 changes: 12 additions & 0 deletions src/constants/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export const BitpaySupportedTokenOpts: TokenOptsType = {
decimals: 18,
address: '0x4fabb145d64652a948d72533023f6e7a623c7c53',
},
xusd: {
name: 'Sovryn XUSD',
symbol: 'XUSD',
decimals: 18,
address: '0xb5999795BE0EbB5bAb23144AA5FD6A02D080299F',
},
dai: {
name: 'Dai',
symbol: 'DAI',
Expand Down Expand Up @@ -89,6 +95,12 @@ export const BitpaySupportedTokenOptsByAddress: TokenOptsType = {
decimals: 18,
address: '0x4fabb145d64652a948d72533023f6e7a623c7c53',
},
'0xb5999795BE0EbB5bAb23144AA5FD6A02D080299F': {
name: 'Sovryn XUSD',
symbol: 'XUSD',
decimals: 18,
address: '0xb5999795BE0EbB5bAb23144AA5FD6A02D080299F',
},
'0x6b175474e89094c44da98b954eedeac495271d0f': {
name: 'Dai',
symbol: 'DAI',
Expand Down
1 change: 1 addition & 0 deletions src/navigation/card/assets/currency-shapes/RBTC-shape.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/navigation/wallet/screens/CurrencySelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ const DESCRIPTIONS: Record<string, string> = {

const POPULAR_TOKENS: Record<string, string[]> = {
eth: ['usdc', 'busd', 'ape'],
rsk: ['xusd'],
matic: ['usdc', 'busd', 'gusd'],
};

Expand Down Expand Up @@ -256,7 +257,7 @@ const CurrencySelection: React.VFC<CurrencySelectionScreenProps> = ({

const tokenData =
Currencies[k] || appTokenData[k] || appCustomTokenData[k];
const chainData = chainMap[tokenData.chain.toLowerCase()];
const chainData = chainMap[tokenData.chain.toLowerCase() === 'rsk' ? 'rbtc' : tokenData.chain.toLowerCase()];
const imgSrc = SupportedCurrencyOptions.find(c => c.id === k)?.imgSrc;
const isReqSrc = (
src: ImageSourcePropType | undefined,
Expand Down
6 changes: 6 additions & 0 deletions src/navigation/wallet/screens/WalletDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,12 @@ const WalletDetails: React.FC<WalletDetailsScreenProps> = ({route}) => {
? `https://${Currencies.eth.paymentInfo.blockExplorerUrls}address/${address}`
: `https://${Currencies.eth.paymentInfo.blockExplorerUrlsTestnet}address/${address}`;
}
if (coin === 'rbtc') {
url =
fullWalletObj.network === 'livenet'
? `https://${Currencies.rbtc.paymentInfo.blockExplorerUrls}address/${address}`
: `https://${Currencies.rbtc.paymentInfo.blockExplorerUrlsTestnet}address/${address}`;
}
if (dispatch(IsERCToken(coin))) {
url =
fullWalletObj.network === 'livenet'
Expand Down
2 changes: 2 additions & 0 deletions src/navigation/wallet/screens/send/SendTo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ const ValidDataTypes: string[] = [
'BitcoinAddress',
'BitcoinCashAddress',
'EthereumAddress',
'RSKAddress',
'RippleAddress',
'DogecoinAddress',
'LitecoinAddress',
'RippleUri',
'BitcoinUri',
'BitcoinCashUri',
'EthereumUri',
'RSKUri',
'DogecoinUri',
'LitecoinUri',
'BitPayUri',
Expand Down
1 change: 1 addition & 0 deletions src/store/card/card.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type SupportedCurrencies =
| 'BTC'
| 'BCH'
| 'ETH'
| 'RBTC'
| 'GUSD'
| 'USDP'
| 'BUSD'
Expand Down
41 changes: 41 additions & 0 deletions src/store/scan/scan.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
IsValidDogecoinUri,
IsValidEthereumAddress,
IsValidEthereumUri,
IsValidRSKAddress,
IsValidRSKUri,
IsValidImportPrivateKey,
IsValidJoinCode,
IsValidLitecoinAddress,
Expand Down Expand Up @@ -98,6 +100,9 @@ export const incomingData =
// Ethereum URI
} else if (IsValidEthereumUri(data)) {
dispatch(handleEthereumUri(data, opts?.wallet));
// RSK URI
} else if (IsValidRSKUri(data)) {
dispatch(handleRSKUri(data, opts?.wallet));
// Ripple URI
} else if (IsValidRippleUri(data)) {
dispatch(handleRippleUri(data, opts?.wallet));
Expand Down Expand Up @@ -128,6 +133,9 @@ export const incomingData =
// Address (Ethereum)
} else if (IsValidEthereumAddress(data)) {
dispatch(handlePlainAddress(data, coin || 'eth', opts));
// Address RSK
} else if (IsValidRSKAddress(data)) {
dispatch(handlePlainAddress(data, coin || 'rsk' || 'rbtc', opts));
// Address (Ripple)
} else if (IsValidRippleAddress(data)) {
dispatch(handlePlainAddress(data, coin || 'xrp', opts));
Expand Down Expand Up @@ -721,6 +729,39 @@ const handleEthereumUri =
}
};

const handleRSKUri =
(data: string, wallet?: Wallet): Effect<void> =>
dispatch => {
dispatch(LogActions.info('[scan] Incoming-data: RSK URI'));
const coin = 'rbtc';
const value = /[\?\&]value=(\d+([\,\.]\d+)?)/i;
const gasPrice = /[\?\&]gasPrice=(\d+([\,\.]\d+)?)/i;
let feePerKb;
if (gasPrice.exec(data)) {
feePerKb = Number(gasPrice.exec(data)![1]);
}
const address = ExtractBitPayUriAddress(data);
const recipient = {
type: 'address',
currency: coin,
address,
};
if (!value.exec(data)) {
dispatch(goToAmount({coin, recipient, wallet, opts: {feePerKb}}));
} else {
const parsedAmount = value.exec(data)![1];
const amount = Number(dispatch(FormatAmount(coin, Number(parsedAmount))));
dispatch(
goToConfirm({
recipient,
amount,
wallet,
opts: {feePerKb},
}),
);
}
};

const handleRippleUri =
(data: string, wallet?: Wallet): Effect<void> =>
dispatch => {
Expand Down

0 comments on commit 51e4325

Please sign in to comment.