Skip to content

Commit 13ee818

Browse files
committed
feat: rsk integration
1 parent e4cbd3a commit 13ee818

File tree

18 files changed

+169
-9
lines changed

18 files changed

+169
-9
lines changed

assets/img/currencies/png/RBTC.png

29.8 KB
Loading

assets/img/currencies/png/xusd.png

12.2 KB
Loading

assets/img/currencies/rbtc.svg

+1
Loading

assets/img/currencies/xusd.svg

+1
Loading

src/constants/SupportedCurrencyOptions.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React, {ReactElement} from 'react';
22
import BtcIcon from '../../assets/img/currencies/btc.svg';
33
import BchIcon from '../../assets/img/currencies/bch.svg';
44
import EthIcon from '../../assets/img/currencies/eth.svg';
5+
import RbtcIcon from '../../assets/img/currencies/rbtc.svg';
6+
import XUSDIcon from '../../assets/img/currencies/xusd.svg';
57
import DogeIcon from '../../assets/img/currencies/doge.svg';
68
import LtcIcon from '../../assets/img/currencies/ltc.svg';
79
import XrpIcon from '../../assets/img/currencies/xrp.svg';
@@ -32,6 +34,8 @@ export const CurrencyListIcons: {
3234
btc: props => <BtcIcon {...props} />,
3335
bch: props => <BchIcon {...props} />,
3436
eth: props => <EthIcon {...props} />,
37+
rbtc: props => <RbtcIcon {...props} />,
38+
xusd: props => <XUSDIcon {...props} />,
3539
doge: props => <DogeIcon {...props} />,
3640
ltc: props => <LtcIcon {...props} />,
3741
xrp: props => <XrpIcon {...props} />,
@@ -71,6 +75,14 @@ export const SupportedCurrencyOptions: Array<SupportedCurrencyOption> = [
7175
hasMultisig: false, // TODO
7276
imgSrc: require('../../assets/img/currencies/png/ETH.png'),
7377
},
78+
{
79+
id: 'rbtc',
80+
img: CurrencyListIcons.rbtc,
81+
currencyName: 'RSK',
82+
currencyAbbreviation: 'RBTC',
83+
hasMultisig: false, // TODO
84+
imgSrc: require('../../assets/img/currencies/png/RBTC.png'),
85+
},
7486
{
7587
id: 'doge',
7688
img: CurrencyListIcons.doge,
@@ -142,6 +154,14 @@ export const SupportedCurrencyOptions: Array<SupportedCurrencyOption> = [
142154
isToken: true,
143155
imgSrc: require('../../assets/img/currencies/png/BUSD.png'),
144156
},
157+
{
158+
id: 'xusd',
159+
img: CurrencyListIcons.xusd,
160+
currencyName: 'Sovryn XUSD',
161+
currencyAbbreviation: 'XUSD',
162+
isToken: true,
163+
imgSrc: require('../../assets/img/currencies/png/xusd.png'),
164+
},
145165
{
146166
id: 'dai',
147167
img: CurrencyListIcons.dai,

src/constants/config.card.ts

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import BUSDShape from '../navigation/card/assets/currency-shapes/BUSD-shape.svg'
88
import DAIShape from '../navigation/card/assets/currency-shapes/DAI-shape.svg';
99
import DOGEShape from '../navigation/card/assets/currency-shapes/DOGE-shape.svg';
1010
import ETHShape from '../navigation/card/assets/currency-shapes/ETH-shape.svg';
11+
import RBTCShape from '../navigation/card/assets/currency-shapes/RBTC-shape.svg';
1112
import GUSDShape from '../navigation/card/assets/currency-shapes/GUSD-shape.svg';
1213
import USDPShape from '../navigation/card/assets/currency-shapes/USDP-shape.svg';
1314
import USDCShape from '../navigation/card/assets/currency-shapes/USDC-shape.svg';
@@ -192,6 +193,18 @@ export const SUPPORTED_DESIGN_CURRENCIES: SupportedDesignCurrenciesConfig = {
192193
pillCircleBackground: '#FFF',
193194
},
194195
},
196+
RBTC: {
197+
currency: 'RBTC',
198+
enabled: true,
199+
palette: {
200+
BackgroundShape: RBTCShape,
201+
stopColor1: '#9A9FF1',
202+
stopColor2: '#575DC2',
203+
pillColor: '#FFF',
204+
pillBackground: '#595FC6',
205+
pillCircleBackground: '#FFF',
206+
},
207+
},
195208
GUSD: {
196209
currency: 'GUSD',
197210
enabled: true,

src/constants/currencies.ts

+78-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type SupportedCoins = 'btc' | 'bch' | 'ltc' | 'doge' | 'eth';
1+
export type SupportedCoins = 'btc' | 'bch' | 'ltc' | 'doge' | 'eth' | 'rbtc';
22
export type SupportedTokens =
33
| 'usdc'
44
| 'gusd'
@@ -8,7 +8,8 @@ export type SupportedTokens =
88
| 'wbtc'
99
| 'shib'
1010
| 'ape'
11-
| 'euroc';
11+
| 'euroc'
12+
| 'xusd';
1213
export type SupportedCurrencies = SupportedCoins | SupportedTokens;
1314

1415
export interface CurrencyOpts {
@@ -168,6 +169,80 @@ export const Currencies: {[key in string]: CurrencyOpts} = {
168169
gradientBackgroundColor: '#6b71d6',
169170
},
170171
},
172+
rbtc: {
173+
name: 'Smart Bitcoin',
174+
chain: 'RSK',
175+
coin: 'rbtc',
176+
unitInfo: {
177+
unitName: 'RBTC',
178+
unitToSatoshi: 1e18,
179+
unitDecimals: 18,
180+
unitCode: 'rbtc'
181+
},
182+
properties: {
183+
hasMultiSig: false,
184+
hasMultiSend: false,
185+
isUtxo: false,
186+
isERCToken: false,
187+
isStableCoin: false,
188+
singleAddress: true
189+
},
190+
paymentInfo: {
191+
paymentCode: 'EIP681',
192+
protocolPrefix: { livenet: 'rsk', testnet: 'rsk' },
193+
ratesApi: 'https://bws.bitpay.com/bws/api/v3/fiatrates/rbtc',
194+
blockExplorerUrls: 'explorer.rsk.co/',
195+
blockExplorerUrlsTestnet: 'explorer.testet.rsk.co/'
196+
},
197+
feeInfo: {
198+
feeUnit: 'Gwei',
199+
feeUnitAmount: 1e9,
200+
blockTime: 0.53,
201+
maxMerchantFee: 'urgent'
202+
},
203+
theme: {
204+
coinColor: '#41d434',
205+
backgroundColor: '#1e90ff',
206+
gradientBackgroundColor: '#1e90ff'
207+
}
208+
},
209+
xusd: {
210+
name: 'Sovryn XUSD',
211+
chain: 'RSK',
212+
coin: 'xusd',
213+
unitInfo: {
214+
unitName: 'XUSD',
215+
unitToSatoshi: 1e18,
216+
unitDecimals: 18,
217+
unitCode: 'xusd',
218+
},
219+
properties: {
220+
hasMultiSig: false,
221+
hasMultiSend: false,
222+
isUtxo: false,
223+
isERCToken: true,
224+
isStableCoin: true,
225+
singleAddress: true,
226+
},
227+
paymentInfo: {
228+
paymentCode: 'EIP681',
229+
protocolPrefix: { livenet: 'rsk', testnet: 'rsk' },
230+
ratesApi: 'https://bws.bitpay.com/bws/api/v3/fiatrates/xusd',
231+
blockExplorerUrls: 'explorer.rsk.co/',
232+
blockExplorerUrlsTestnet: 'explorer.testet.rsk.co/'
233+
},
234+
feeInfo: {
235+
feeUnit: 'Gwei',
236+
feeUnitAmount: 1e9,
237+
blockTime: 0.2,
238+
maxMerchantFee: 'urgent',
239+
},
240+
theme: {
241+
coinColor: '#f3ba2d',
242+
backgroundColor: 'rgba(135,206,250,1)',
243+
gradientBackgroundColor: 'rgba(30,144,255, 0.2)',
244+
},
245+
},
171246
xrp: {
172247
name: 'XRP',
173248
chain: 'XRP',
@@ -628,7 +703,7 @@ export const SUPPORTED_TOKENS = [
628703
'ape',
629704
'euroc',
630705
];
631-
export const SUPPORTED_COINS = ['btc', 'bch', 'eth', 'doge', 'ltc', 'xrp'];
706+
export const SUPPORTED_COINS = ['btc', 'bch', 'eth', 'rbtc', 'doge', 'ltc', 'xrp'];
632707
export const SUPPORTED_CURRENCIES = [...SUPPORTED_COINS, ...SUPPORTED_TOKENS];
633708
export const POPULAR_TOKENS = [
634709
'UNI',

src/constants/defaultDerivationPath.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export enum DefaultDerivationPath {
22
defaultBTC = "m/44'/0'/0'",
33
defaultBCH = "m/44'/145'/0'",
44
defaultETH = "m/44'/60'/0'",
5+
defaultRBTC = "m/44'/137'/0'",
56
defaultXRP = "m/44'/144'/0'",
67
defaultDOGE = "m/44'/3'/0'",
78
defaultLTC = "m/44'/2'/0'",

src/constants/tokens.ts

+12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ export const BitpaySupportedTokenOpts: TokenOptsType = {
3232
decimals: 18,
3333
address: '0x4fabb145d64652a948d72533023f6e7a623c7c53',
3434
},
35+
xusd: {
36+
name: 'Sovryn XUSD',
37+
symbol: 'XUSD',
38+
decimals: 18,
39+
address: '0xb5999795BE0EbB5bAb23144AA5FD6A02D080299F',
40+
},
3541
dai: {
3642
name: 'Dai',
3743
symbol: 'DAI',
@@ -89,6 +95,12 @@ export const BitpaySupportedTokenOptsByAddress: TokenOptsType = {
8995
decimals: 18,
9096
address: '0x4fabb145d64652a948d72533023f6e7a623c7c53',
9197
},
98+
'0xb5999795be0ebb5bab23144aa5fd6a02d080299f': {
99+
name: 'Binance USD Coin',
100+
symbol: 'XUSD',
101+
decimals: 18,
102+
address: '0xb5999795be0ebb5bab23144aa5fd6a02d080299f',
103+
},
92104
'0x6b175474e89094c44da98b954eedeac495271d0f': {
93105
name: 'Dai',
94106
symbol: 'DAI',

src/navigation/card/assets/currency-shapes/RBTC-shape.svg

+1
Loading

src/navigation/wallet/screens/CurrencySelection.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ const DESCRIPTIONS: Record<string, string> = {
129129

130130
const POPULAR_TOKENS: Record<string, string[]> = {
131131
eth: ['usdc', 'busd', 'ape'],
132+
rsk: ['xusd'],
132133
matic: ['usdc', 'busd', 'gusd'],
133134
};
134135

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

257258
const tokenData =
258259
Currencies[k] || appTokenData[k] || appCustomTokenData[k];
259-
const chainData = chainMap[tokenData.chain.toLowerCase()];
260+
const chainData = chainMap[tokenData.chain.toLowerCase() === 'rsk' ? 'rbtc' : tokenData.chain.toLowerCase()];
260261
const imgSrc = SupportedCurrencyOptions.find(c => c.id === k)?.imgSrc;
261262
const isReqSrc = (
262263
src: ImageSourcePropType | undefined,

src/navigation/wallet/screens/WalletDetails.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,12 @@ const WalletDetails: React.FC<WalletDetailsScreenProps> = ({route}) => {
712712
? `https://${Currencies.eth.paymentInfo.blockExplorerUrls}address/${address}`
713713
: `https://${Currencies.eth.paymentInfo.blockExplorerUrlsTestnet}address/${address}`;
714714
}
715+
if (coin === 'rbtc') {
716+
url =
717+
fullWalletObj.network === 'livenet'
718+
? `https://${Currencies.rbtc.paymentInfo.blockExplorerUrls}address/${address}`
719+
: `https://${Currencies.rbtc.paymentInfo.blockExplorerUrlsTestnet}address/${address}`;
720+
}
715721
if (dispatch(IsERCToken(coin))) {
716722
url =
717723
fullWalletObj.network === 'livenet'

src/store/card/card.types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export type SupportedCurrencies =
2727
| 'BTC'
2828
| 'BCH'
2929
| 'ETH'
30+
| 'RBTC'
3031
| 'GUSD'
3132
| 'USDP'
3233
| 'BUSD'

src/store/wallet/effects/create/create.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
buildWalletObj,
1616
checkEncryptPassword,
1717
} from '../../utils/wallet';
18+
import { getRSKChainAbbrevation } from '../../utils/currency';
1819
import {
1920
failedAddWallet,
2021
successAddWallet,
@@ -244,7 +245,7 @@ const createMultipleWallets =
244245
})) as Wallet;
245246
wallets.push(wallet);
246247

247-
if (coin === 'eth') {
248+
if (coin === 'eth' || coin === 'rbtc') {
248249
wallet.preferences = wallet.preferences || {
249250
tokenAddresses: [],
250251
};
@@ -307,7 +308,7 @@ const createWallet = (params: {
307308

308309
bwcClient.fromString(
309310
key.createCredentials(password, {
310-
coin,
311+
coin: getRSKChainAbbrevation(coin),
311312
network,
312313
account,
313314
n: 1,
@@ -323,7 +324,7 @@ const createWallet = (params: {
323324
{
324325
network,
325326
singleAddress,
326-
coin,
327+
coin: getRSKChainAbbrevation(coin),
327328
useNativeSegwit,
328329
},
329330
(err: any) => {

src/store/wallet/effects/transactions/transactions.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
IsCustomERCToken,
1313
IsERCToken,
1414
IsUtxoCoin,
15+
getRSKCurrencyAbbrevation,
1516
} from '../../utils/currency';
1617
import {ToAddress, ToLtcAddress} from '../address/address';
1718
import {
@@ -125,6 +126,7 @@ const ProcessTx =
125126
tx: TransactionProposal,
126127
): Effect<TransactionProposal> =>
127128
dispatch => {
129+
currencyAbbreviation = getRSKCurrencyAbbrevation(currencyAbbreviation);
128130
if (!tx || tx.action === 'invalid') {
129131
return tx;
130132
}
@@ -820,7 +822,8 @@ export const buildTransactionDetails =
820822
time,
821823
hasMultiplesOutputs,
822824
} = transaction;
823-
const {coin: currency} = wallet.credentials;
825+
let {coin: currency} = wallet.credentials;
826+
currency = getRSKCurrencyAbbrevation(currency);
824827
const chain = dispatch(GetChain(currency)).toLowerCase();
825828
const _fee = fees || fee;
826829

src/store/wallet/utils/currency.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const GetPrecision =
3434
WALLET: {tokenData, customTokenData},
3535
} = getState();
3636
const tokens = {...tokenData, ...customTokenData};
37-
const currency = currencyAbbreviation.toLowerCase();
37+
const currency = getRSKCurrencyAbbrevation(currencyAbbreviation.toLowerCase());
3838
return Currencies[currency]?.unitInfo || tokens[currency]?.unitInfo;
3939
};
4040

@@ -76,6 +76,7 @@ export const IsERCToken =
7676
export const GetBlockExplorerUrl =
7777
(currencyAbbreviation: string, network: string = 'livenet'): Effect<string> =>
7878
(dispatch, getState) => {
79+
currencyAbbreviation = getRSKCurrencyAbbrevation(currencyAbbreviation);
7980
const {
8081
WALLET: {tokenData, customTokenData},
8182
} = getState();
@@ -147,3 +148,19 @@ export const isSingleAddressCoin =
147148
tokens[currency]?.properties.singleAddress
148149
);
149150
};
151+
152+
/**
153+
* In case of rsk chain and currency having different names.
154+
* This function will return the currency name for rsk.
155+
*/
156+
export const getRSKCurrencyAbbrevation = (name: string) => {
157+
return name === 'rsk' ? 'rbtc': name;
158+
}
159+
160+
/**
161+
* In case of rsk chain and currency having different names.
162+
* This function will return the chain name for rsk.
163+
*/
164+
export const getRSKChainAbbrevation = (name: string) => {
165+
return name === 'rbtc' ? 'rsk': name;
166+
}

src/store/wallet/utils/validations.ts

+1
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ export const ValidateCoinAddress = (
329329
const addressLtc = BWC.getBitcoreLtc().Address;
330330
return !!addressLtc.isValid(str, network);
331331
case 'eth':
332+
case 'rsk':
332333
case 'xrp':
333334
const {Validation} = BWC.getCore();
334335
return !!Validation.validateAddress(coin.toUpperCase(), network, str);

src/utils/helper-methods.ts

+6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ export const getNetworkName = (path: string): string => {
6464
case "60'": // for ETH
6565
networkName = 'livenet';
6666
break;
67+
case "137'": // for RSK
68+
networkName = 'livenet';
69+
break;
6770
case "144'": // for XRP
6871
networkName = 'livenet';
6972
break;
@@ -114,6 +117,9 @@ export const isValidDerivationPathCoin = (
114117
case 'eth':
115118
isValid = ["60'", "0'", "1'"].indexOf(coinCode) > -1;
116119
break;
120+
case 'rbtc':
121+
isValid = ["137'", "0'", "1'"].indexOf(coinCode) > -1;
122+
break;
117123
case 'xrp':
118124
isValid = ["144'", "0'", "1'"].indexOf(coinCode) > -1;
119125
break;

0 commit comments

Comments
 (0)