Skip to content

Commit

Permalink
[FEAT] Litecoin Support
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbazan7 committed Jul 13, 2021
1 parent 6a32d6f commit f06bd39
Show file tree
Hide file tree
Showing 26 changed files with 185 additions and 16 deletions.
1 change: 1 addition & 0 deletions app-template/build-electron-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ builder
'ethereum',
'ripple',
'dogecoin',
'litecoin',
'*NAME*'
]
},
Expand Down
3 changes: 2 additions & 1 deletion app-template/config-template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<plugin name="cordova-plugin-vibration" spec="3.1.1" />
<plugin name="cordova-plugin-file" spec="6.0.2" />
<plugin name="cordova-custom-config" spec="5.1.0" />
<plugin name="cordova-plugin-customurlscheme-ng" spec="10.0.0">
<plugin name="cordova-plugin-customurlscheme-ng" spec="11.0.0">
<variable name="URL_SCHEME" value="bitcoin" />
<variable name="SECOND_URL_SCHEME" value="*APPURI*" />
<variable name="THIRD_URL_SCHEME" value="bitcoincash" />
Expand All @@ -100,6 +100,7 @@
<variable name="SIXTH_URL_SCHEME" value="ripple" />
<variable name="SEVENTH_URL_SCHEME" value="wc" />
<variable name="EIGHTH_URL_SCHEME" value="dogecoin" />
<variable name="NINTH_URL_SCHEME" value="litecoin" />
<variable name="ANDROID_SCHEME" value="" />
<variable name="ANDROID_HOST" value="" />
<variable name="ANDROID_PATHPREFIX" value="" />
Expand Down
2 changes: 2 additions & 0 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ if (!app.isDefaultProtocolClient('ripple'))
app.setAsDefaultProtocolClient('ripple');
if (!app.isDefaultProtocolClient('dogecoin'))
app.setAsDefaultProtocolClient('dogecoin');
if (!app.isDefaultProtocolClient('litecoin'))
app.setAsDefaultProtocolClient('litecoin');
if (!app.isDefaultProtocolClient(appConfig.name))
app.setAsDefaultProtocolClient(appConfig.name);

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"apple-wallet-ng": "1.1.1",
"base64-js": "1.3.0",
"bitauth": "git+https://github.com/bitpay/bitauth.git#68cf0353bf517a7e5293478608839fa904351eb6",
"bitcore-wallet-client": "8.25.11",
"bitcore-wallet-client": "8.25.13",
"buffer-compare": "1.1.1",
"chart.js": "2.9.4",
"cordova": "9.0.0",
Expand All @@ -144,7 +144,7 @@
"cordova-plugin-add-swift-support": "2.0.2",
"cordova-plugin-advanced-http": "2.1.0",
"cordova-plugin-compat": "1.2.0",
"cordova-plugin-customurlscheme-ng": "10.0.0",
"cordova-plugin-customurlscheme-ng": "11.0.0",
"cordova-plugin-device": "2.0.1",
"cordova-plugin-dialogs": "2.0.2",
"cordova-plugin-fcm-ng": "8.3.0",
Expand Down
3 changes: 3 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,9 @@ export class CopayApp {
} else if (pathData.indexOf('dogecoin:/') != -1) {
this.logger.debug('Dogecoin URL found');
this.handleOpenUrl(pathData.substring(pathData.indexOf('dogecoin:/')));
} else if (pathData.indexOf('litecoin:/') != -1) {
this.logger.debug('Litecoin URL found');
this.handleOpenUrl(pathData.substring(pathData.indexOf('litecoin:/')));
} else if (pathData.indexOf(this.appProvider.info.name + '://') != -1) {
this.logger.debug(this.appProvider.info.name + ' URL found');
this.handleOpenUrl(
Expand Down
4 changes: 4 additions & 0 deletions src/app/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ ion-spinner * {
background-color: #d8c172;
}

.ltc-background {
background-color: #2962ff;
}

button.item {
&.activated {
background-color: $feather;
Expand Down
1 change: 1 addition & 0 deletions src/assets/img/currencies/ltc.svg
Loading
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 src/assets/img/icon-ltc-small.svg
Loading
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 src/components/coin-icon/coin-icon.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'background_dai': coin == 'dai',
'background_wbtc': coin == 'wbtc',
'background_doge': coin == 'doge',
'background_ltc': coin == 'ltc',
'testnet': network === 'testnet'
}" item-start>
<img src="assets/img/currencies/{{coin}}.svg" />
Expand Down
3 changes: 3 additions & 0 deletions src/components/coin-icon/coin-icon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ coin-icon {
&_doge {
background-color: #d8c172;
}
&_ltc {
background-color: #2962ff;
}
&_default {
background-color: #e6f8e9;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/incoming-data-menu/incoming-data-menu.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<action-sheet>
<ion-list class="bp-list" *ngIf="type === 'bitcoinAddress' || type === 'ethereumAddress' || type === 'rippleAddress' || type === 'dogecoinAddress'">
<ion-list class="bp-list" *ngIf="type === 'bitcoinAddress' || type === 'ethereumAddress' || type === 'rippleAddress' || type === 'dogecoinAddress' || type === 'litecoinAddress'">
<ion-item-divider *ngIf="coinName">{{'{coinName} Address' | translate: { coinName: coinName } }}</ion-item-divider>
<ion-item>
{{data}}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/add/select-currency/select-currency.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</div>
</div>
<div footer-content *ngIf="isZeroState && !isJoin">
<button ion-button class="button-standard" [ngClass]="{'no-margin-bottom': !isOnboardingFlow}" [disabled]="!coinsSelected.btc && !coinsSelected.bch && !coinsSelected.eth && !coinsSelected.xrp && !coinsSelected.doge" (click)="createWallets()">
<button ion-button class="button-standard" [ngClass]="{'no-margin-bottom': !isOnboardingFlow}" [disabled]="!coinsSelected.btc && !coinsSelected.bch && !coinsSelected.eth && !coinsSelected.xrp && !coinsSelected.doge && !coinsSelected.ltc" (click)="createWallets()">
{{isOnboardingFlow ? 'Continue' : 'Create' | translate}}
</button>
<button ion-button clear class="button-standard" (click)="goToImportWallet()" *ngIf="!isOnboardingFlow">
Expand Down
1 change: 1 addition & 0 deletions src/pages/send/confirm/confirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,7 @@ export class ConfirmPage {
'BitcoinCashUri',
'EthereumUri',
'DogecoinUri',
'LitecoinUri',
'RippleUri',
'InvoiceUri'
]);
Expand Down
7 changes: 5 additions & 2 deletions src/pages/send/multi-send/multi-send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ export class MultiSendPage {
'BitcoinCashAddress',
'EthereumAddress',
'DogecoinAddress',
'LitecoinAddress',
'EthereumUri',
'BitcoinUri',
'BitcoinCashUri',
'DogecoinUri'
'DogecoinUri',
'LitecoinUri'
];

constructor(
Expand All @@ -78,7 +80,8 @@ export class MultiSendPage {
this.bitcore = {
btc: this.bwcProvider.getBitcore(),
bch: this.bwcProvider.getBitcoreCash(),
doge: this.bwcProvider.getBitcoreDoge()
doge: this.bwcProvider.getBitcoreDoge(),
ltc: this.bwcProvider.getBitcoreLtc()
};
this.isCordova = this.platformProvider.isCordova;
this.isDisabledContinue = true;
Expand Down
7 changes: 5 additions & 2 deletions src/pages/send/select-inputs/select-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ export class SelectInputsPage {
'BitcoinCashAddress',
'EthereumAddress',
'DogecoinAddress',
'LitecoinAddress',
'EthereumUri',
'BitcoinUri',
'BitcoinCashUri',
'DogecoinUri'
'DogecoinUri',
'LitecoinUri'
];
constructor(
private navCtrl: NavController,
Expand All @@ -76,7 +78,8 @@ export class SelectInputsPage {
this.bitcore = {
btc: this.bwcProvider.getBitcore(),
bch: this.bwcProvider.getBitcoreCash(),
doge: this.bwcProvider.getBitcoreDoge()
doge: this.bwcProvider.getBitcoreDoge(),
ltc: this.bwcProvider.getBitcoreLtc()
};
this.reverse = false;
this.isCordova = this.platformProvider.isCordova;
Expand Down
2 changes: 2 additions & 0 deletions src/pages/send/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ export class SendPage {
'EthereumUri',
'RippleAddress',
'DogecoinAddress',
'LitecoinAddress',
'RippleUri',
'BitcoinUri',
'BitcoinCashUri',
'DogecoinUri',
'LitecoinUri',
'BitPayUri'
];
private pageMap = {
Expand Down
15 changes: 14 additions & 1 deletion src/providers/address/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ export class AddressProvider {
private bitcore;
private bitcoreCash;
private bitcoreDoge;
private bitcoreLtc;
private core;

constructor(private bwcProvider: BwcProvider, private logger: Logger) {
this.bitcore = this.bwcProvider.getBitcore();
this.bitcoreCash = this.bwcProvider.getBitcoreCash();
this.bitcoreDoge = this.bwcProvider.getBitcoreDoge();
this.bitcoreLtc = this.bwcProvider.getBitcoreLtc();
this.core = this.bwcProvider.getCore();
}

Expand Down Expand Up @@ -77,7 +79,12 @@ export class AddressProvider {
network = this.bitcoreDoge.Address(address).network.name;
return { coin: 'doge', network };
} catch (e) {
return null;
try {
network = this.bitcoreLtc.Address(address).network.name;
return { coin: 'ltc', network };
} catch (e) {
return null;
}
}
}
}
Expand All @@ -94,12 +101,16 @@ export class AddressProvider {
const URICash = this.bitcoreCash.URI;
const AddressDoge = this.bitcoreDoge.Address;
const URIDoge = this.bitcoreDoge.URI;
const AddressLtc = this.bitcoreLtc.Address;
const URILtc = this.bitcoreLtc.URI;

const { Validation } = this.core;

// Bip21 uri
if (URI.isValid(str)) return true;
if (URICash.isValid(str)) return true;
if (URIDoge.isValid(str)) return true;
if (URILtc.isValid(str)) return true;
if (Validation.validateUri('ETH', str)) return true;
if (Validation.validateUri('XRP', str)) return true;

Expand All @@ -110,6 +121,8 @@ export class AddressProvider {
if (AddressCash.isValid(str, 'testnet')) return true;
if (AddressDoge.isValid(str, 'livenet')) return true;
if (AddressDoge.isValid(str, 'testnet')) return true;
if (AddressLtc.isValid(str, 'livenet')) return true;
if (AddressLtc.isValid(str, 'testnet')) return true;
if (Validation.validateAddress('XRP', 'livenet', str)) return true;
if (Validation.validateAddress('ETH', 'livenet', str)) return true;

Expand Down
4 changes: 4 additions & 0 deletions src/providers/bwc/bwc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export class BwcProvider {
return BWC.BitcoreDoge;
}

public getBitcoreLtc() {
return BWC.BitcoreLtc;
}

public getCore() {
return BWC.Core;
}
Expand Down
3 changes: 2 additions & 1 deletion src/providers/changelly/changelly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export class ChangellyProvider {
'usdc',
'gusd',
'dai',
'doge'
'doge',
'ltc'
];
}

Expand Down
3 changes: 2 additions & 1 deletion src/providers/clipboard/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const validDataByCoin = {
bch: ['BitcoinCashUri', 'BitcoinCashAddress'],
eth: ['EthereumUri', 'EthereumAddress'],
xrp: ['RippleUri', 'RippleAddress'],
doge: ['DogecoinUri', 'DogecoinAddress']
doge: ['DogecoinUri', 'DogecoinAddress'],
ltc: ['LitecoinUri', 'LitecoinAddress']
};

@Injectable()
Expand Down
37 changes: 37 additions & 0 deletions src/providers/currency/coin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,5 +450,42 @@ export const availableCoins: CoinsMap<CoinOpts> = {
backgroundColor: '#d8c172',
gradientBackgroundColor: '#d8c172'
}
},
ltc: {
name: 'Litecoin',
chain: 'LTC',
coin: 'ltc',
unitInfo: {
unitName: 'LTC',
unitToSatoshi: 100000000,
unitDecimals: 8,
unitCode: 'ltc'
},
properties: {
hasMultiSig: true,
hasMultiSend: true,
isUtxo: true,
isERCToken: false,
isStableCoin: false,
singleAddress: false
},
paymentInfo: {
paymentCode: 'BIP73',
protocolPrefix: { livenet: 'litecoin', testnet: 'litecoin' },
ratesApi: 'https://bws.bitpay.com/bws/api/v3/fiatrates/ltc',
blockExplorerUrls: 'bitpay.com/insight/#/LTC/mainnet/',
blockExplorerUrlsTestnet: 'bitpay.com/insight/#/LTC/testnet/'
},
feeInfo: {
feeUnit: 'sat/byte',
feeUnitAmount: 1000,
blockTime: 10,
maxMerchantFee: 'urgent'
},
theme: {
coinColor: '#f7931a',
backgroundColor: '#f7921a',
gradientBackgroundColor: '#f7921a'
}
}
};
3 changes: 2 additions & 1 deletion src/providers/currency/currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export enum Coin {
BUSD = 'busd',
DAI = 'dai',
WBTC = 'wbtc',
DOGE = 'doge'
DOGE = 'doge',
LTC = 'ltc'
}

export type CoinsMap<T> = { [key in Coin]: T };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class DerivationPathHelperProvider {
public defaultETH: string;
public defaultXRP: string;
public defaultDOGE: string;
public defaultLTC: string;
public defaultTestnet: string;
public defaultMultisigBTC: string;
public defaultMultisigBCH: string;
Expand All @@ -18,6 +19,7 @@ export class DerivationPathHelperProvider {
this.defaultETH = "m/44'/60'/0'";
this.defaultXRP = "m/44'/144'/0'";
this.defaultDOGE = "m/44'/3'/0'";
this.defaultLTC = "m/44'/2'/0'";
this.defaultMultisigBTC = "m/48'/0'/0'";
this.defaultMultisigBCH = "m/48'/145'/0'";
this.defaultMultisigDOGE = "m/48'/3'/0'";
Expand Down Expand Up @@ -77,6 +79,9 @@ export class DerivationPathHelperProvider {
case "3'": // for DOGE
networkName = 'livenet';
break;
case "2'": // for LTC
networkName = 'livenet';
break;
}
return networkName;
}
Expand Down Expand Up @@ -115,6 +120,9 @@ export class DerivationPathHelperProvider {
case 'doge':
isValid = ["3'", "1'"].indexOf(coinCode) > -1;
break;
case 'ltc':
isValid = ["2'", "1'"].indexOf(coinCode) > -1;
break;
}

return isValid;
Expand Down
Loading

0 comments on commit f06bd39

Please sign in to comment.