Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class PriceUpdateModuleComponent extends React.Component<IReduxProps & IExternal
JSON.stringify(this.props[key]) !== JSON.stringify(prevProps[key])
) {
this.fetchDataTimeout && clearTimeout(this.fetchDataTimeout);
this.fetchDataTimeout = setTimeout(() => this.fetchData(), 200);
this.fetchDataTimeout = setTimeout(() => this.fetchData(), 300);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import React from 'react';
import { View } from 'react-native';
import { NavigationEvents } from 'react-navigation';
import { connect } from 'react-redux';
import { smartConnect } from '../../../../core/utils/smart-connect';
import { IReduxState } from '../../../../redux/state';
import { setScreenInputData } from '../../../../redux/ui/screens/input-data/actions';
import { IScreenContext, IScreenModule, ISmartScreenActions, ITimerUpdateData } from '../../types';
import { getStateSelectors } from '../ui-state-selectors';
import { HttpClient } from '../../../../core/utils/http-client';

interface IExternalProps {
module: IScreenModule;
context: IScreenContext;
actions: ISmartScreenActions;
options?: {
screenKey?: string;
flowId?: string;
};
}

interface IReduxProps {
setScreenInputData: typeof setScreenInputData;
}

const mapStateToProps = (state: IReduxState, ownProps: IExternalProps) => {
return getStateSelectors(state, ownProps.module, {
flowId: ownProps?.options?.flowId,
screenKey: ownProps?.options?.screenKey
});
};

const mapDispatchToProps = {
setScreenInputData
};

class TimerIntervalPriceUpdateModuleComponent extends React.Component<
IReduxProps & IExternalProps
> {
private interval: any;
private remainingTime: number;
private httpClient: HttpClient;

public componentDidMount() {
this.startTimer();
}

// public componentDidUpdate(prevProps: IExternalProps & IReduxProps) {
// const data = this.props.module?.data as ITimerUpdateData;

// const screenKey = this.props.options.screenKey;

// this.props.setScreenInputData(screenKey, {
// [data.reduxKey]: 1
// });
// }

public componentWillUnmount() {
this.interval && clearInterval(this.interval);
}

private onFocus() {
this.startTimer();
}

private onWillBlur() {
this.interval && clearInterval(this.interval);
}

private async getData(data: ITimerUpdateData, endpointData: any) {
try {
let response;

switch (data.endpoint.method) {
case 'POST':
response = await this.httpClient.post('', endpointData);
break;

case 'GET':
response = await this.httpClient.get('');
break;

default:
break;
}

if (response?.result?.data) {
// response price
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wll, we should do something with the prices, right ?

}
} catch (error) {
// TODO: maybe do something here
}
}

private async startTimer() {
const screenKey = this.props.options.screenKey;
const data = this.props.module?.data as ITimerUpdateData;

const selector = this.props.module?.state?.selectors;

if (data.numberOfSeconds) {
this.interval && clearInterval(this.interval);
this.remainingTime = data.numberOfSeconds;
this.interval = setInterval(async () => {
if (this.remainingTime !== 0) {
this.props.setScreenInputData(screenKey, {
[data.reduxKey]: this.remainingTime
});
this.remainingTime--;
} else {
// fetch price;

const endpointData = data.endpoint.data;

Object.keys(data.endpoint.data).map(key => {
if (selector.hasOwnProperty(key)) {
endpointData[key] = this.props[key];
}
});

await this.getData(data, endpointData);
}
}, 1000); // interval is in seconds
}
}

public render() {
return (
<View>
<NavigationEvents
onWillFocus={() => this.onFocus()}
onWillBlur={() => this.onWillBlur()}
/>
</View>
);
}
}

export const TimerIntervalPriceUpdateModule = smartConnect<IExternalProps>(
TimerIntervalPriceUpdateModuleComponent,
[connect(mapStateToProps, mapDispatchToProps)]
);
12 changes: 12 additions & 0 deletions src/components/widgets/render-module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { TextLineIcon } from './components/text-line-icon/text-line-icon';
import { PubSub } from '../../core/blockchain/common/pub-sub';
import { PriceUpdateModule } from './components/price-update/price-update';
import { AbsoluteModules } from './components/absolute-modules/absolute-modules';
import { TimerIntervalPriceUpdateModule } from './components/timer-interval-price-update/timer-interval-price-update';

const renderModules = (
modules: IScreenModule[],
Expand Down Expand Up @@ -292,6 +293,17 @@ export const renderModule = (
);
break;

case ModuleTypes.TIMER_INTERVAL_PRICE_UPDATE:
moduleJSX = (
<TimerIntervalPriceUpdateModule
module={module}
context={context}
actions={actions}
options={options}
/>
);
break;

case ModuleTypes.ABSOLUTE_MODULES:
moduleJSX = (
<AbsoluteModules
Expand Down
12 changes: 12 additions & 0 deletions src/components/widgets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export interface IScreenModule {
| ModuleTypes.ICON_TWO_LINES
| ModuleTypes.IMAGE_BANNER
| ModuleTypes.INPUT
| ModuleTypes.TIMER_INTERVAL_PRICE_UPDATE
| ModuleTypes.MD_TEXT
| ModuleTypes.MODULE_COLUMNS_WRAPPER
| ModuleTypes.MODULE_SELECTABLE_WRAPPER
Expand Down Expand Up @@ -261,6 +262,7 @@ export enum ModuleTypes {
ICON_TWO_LINES = 'icon-two-lines',
IMAGE_BANNER = 'image-banner',
INPUT = 'input',
TIMER_INTERVAL_PRICE_UPDATE = 'timer-interval-price-update',
MD_TEXT = 'md-text',
MODULE_COLUMNS_WRAPPER = 'module-columns-wrapper',
MODULE_SELECTABLE_WRAPPER = 'module-selectable-wrapper',
Expand Down Expand Up @@ -422,6 +424,16 @@ export interface IPriceUpdateData {
interval: number; // miliseconds
}

export interface ITimerUpdateData {
numberOfSeconds: number;
reduxKey: string;
endpoint: {
url: string;
method: 'POST' | 'GET';
data: any;
};
}

export interface IThreeLinesIconData {
firstLine: IData[];
secondLine: IData[];
Expand Down
15 changes: 11 additions & 4 deletions src/core/wallet/hw-wallet/ledger/apps/zil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import ZilApp from './zil-interface';
import * as zcrypto from '@zilliqa-js/crypto';
import { IBlockchainTransaction } from '../../../../blockchain/types';
import BigNumber from 'bignumber.js';
import { isBech32 } from '@zilliqa-js/util/dist/validation';
// import Long from 'long';
// import * as ZilliqaJsAccountUtil from '@zilliqa-js/account/dist/util';

Expand Down Expand Up @@ -31,14 +32,18 @@ export class Zil {
path: string,
tx: IBlockchainTransaction
): Promise<any> => {
const toAddr = isBech32(tx.toAddress)
? zcrypto
.fromBech32Address(tx.toAddress)
.replace('0x', '')
.toLowerCase()
: tx.toAddress.toLowerCase();

const transaction: any = {
// tslint:disable-next-line: no-bitwise
version: (Number(tx.chainId) << 16) + 1,
nonce: tx.nonce,
toAddr: zcrypto
.fromBech32Address(tx.toAddress)
.replace('0x', '')
.toLowerCase(),
toAddr,
amount: tx.amount ? new BigNumber(tx.amount).toFixed() : '0',
pubKey: tx.publicKey,
gasPrice: new BigNumber(tx.feeOptions.gasPrice).toString(),
Expand All @@ -48,13 +53,15 @@ export class Zil {
data: tx.data ? tx.data.raw : '',
priority: true
};

const signed = await this.app.signTxn(index, transaction);

transaction.signature = signed.sig;
transaction.amount = transaction.amount.toString();
transaction.gasLimit = transaction.gasLimit.toString();
transaction.gasPrice = transaction.gasPrice.toString();
transaction.toAddr = zcrypto.toChecksumAddress(transaction.toAddr).replace('0x', '');

return transaction;
};

Expand Down
1 change: 1 addition & 0 deletions src/redux/wallets/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export const getSelectedAccountTransactions = (state: IReduxState): IBlockchainT
tx2.date?.created - tx1.date?.created
);
}
return [];
};

export const getAccounts = (state: IReduxState, blockchain: Blockchain): IAccountState[] => {
Expand Down
3 changes: 3 additions & 0 deletions src/screens/token/components/default-token/default-token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ export class DefaultTokenScreenComponent extends React.Component<
step: 'SwapEnterAmount',
key: 'swap-enter-amount'
},
navigationOptions: {
title: translate('App.labels.swap')
},
newFlow: true
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ export class AccountTabComponent extends React.Component<
step: 'SwapEnterAmount',
key: 'swap-enter-amount'
},
navigationOptions: {
title: translate('App.labels.swap')
},
newFlow: true
})
}
Expand Down