mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 09:18:09 +00:00
trezor-connect response flowtype
This commit is contained in:
parent
80fa9cfe21
commit
1a08e4be6a
@ -135,7 +135,7 @@ const begin = (device: TrezorDevice, network: string): AsyncAction => {
|
||||
});
|
||||
|
||||
// get xpub from TREZOR
|
||||
const response: Object = await TrezorConnect.getPublicKey({
|
||||
const response = await TrezorConnect.getPublicKey({
|
||||
device: {
|
||||
path: device.path,
|
||||
instance: device.instance,
|
||||
|
@ -434,7 +434,7 @@ export const onAmountChange = (amount: string): ThunkAction => {
|
||||
}
|
||||
}
|
||||
|
||||
export const onCurrencyChange = (currency: any): ThunkAction => {
|
||||
export const onCurrencyChange = (currency: { value: string, label: string }): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
const accountState: ?AccountState = getState().abstractAccount;
|
||||
if (!accountState) return;
|
||||
@ -789,7 +789,7 @@ const estimateGasPrice = (): AsyncAction => {
|
||||
|
||||
const data: string = '0x' + (currentState.data.length % 2 === 0 ? currentState.data : '0' + currentState.data);
|
||||
const gasLimit = await estimateGas(web3instance.web3, {
|
||||
to: '0xdb6e09ddca62d0959dc4725697e66b8152222aee',
|
||||
to: '0xdb6e09ddca62d0959dc4725697e66b8152222aee', // TODO: real adress
|
||||
data,
|
||||
value: web3.toHex(web3.toWei(currentState.amount, 'ether')),
|
||||
gasPrice: web3.toHex( EthereumjsUnits.convert(currentState.gasPrice, 'gwei', 'wei') ),
|
||||
@ -861,20 +861,6 @@ export const onSend = (): AsyncAction => {
|
||||
v: ''
|
||||
}
|
||||
|
||||
|
||||
// const gasOptions = {
|
||||
// to: txData.to,
|
||||
// data: txData.data
|
||||
// }
|
||||
|
||||
// const gasPrice = await getGasPrice(web3);
|
||||
|
||||
|
||||
|
||||
// txData.nonce = web3.toHex(nonce);
|
||||
// txData.gasLimit = web3.toHex(gasLimit);
|
||||
// txData.gasPrice = web3.toHex( EthereumjsUnits.convert(gasPrice, 'gwei', 'wei') );
|
||||
|
||||
const selected: ?TrezorDevice = findSelectedDevice(getState().connect);
|
||||
if (!selected) return;
|
||||
|
||||
@ -914,17 +900,13 @@ export const onSend = (): AsyncAction => {
|
||||
txData.s = '0x' + signedTransaction.payload.s;
|
||||
txData.v = web3.toHex(signedTransaction.payload.v);
|
||||
|
||||
// const gasLimit2 = await estimateGas(web3, txData);
|
||||
|
||||
const { config } = getState().localStorage;
|
||||
if (!config) return;
|
||||
const selectedCoin: ?Coin = config.coins.find(c => c.network === currentState.network);
|
||||
if (!selectedCoin) return;
|
||||
|
||||
try {
|
||||
const tx = new EthereumjsTx(txData);
|
||||
const serializedTx = '0x' + tx.serialize().toString('hex');
|
||||
const txid: string = await pushTx(web3, serializedTx);
|
||||
const coin: Coin = accountState.coin;
|
||||
|
||||
dispatch({
|
||||
type: SEND.TX_COMPLETE,
|
||||
@ -940,13 +922,13 @@ export const onSend = (): AsyncAction => {
|
||||
payload: {
|
||||
type: 'success',
|
||||
title: 'Transaction success',
|
||||
message: `<a href="${selectedCoin.explorer.tx}${txid}" class="green" target="_blank" rel="noreferrer noopener">See transaction detail</a>`,
|
||||
message: `<a href="${coin.explorer.tx}${txid}" class="green" target="_blank" rel="noreferrer noopener">See transaction detail</a>`,
|
||||
cancelable: true,
|
||||
actions: []
|
||||
}
|
||||
});
|
||||
|
||||
} catch(error) {
|
||||
} catch (error) {
|
||||
|
||||
dispatch({
|
||||
type: NOTIFICATION.ADD,
|
||||
|
@ -201,7 +201,7 @@ const sortDevices = (devices: Array<TrezorDevice>): Array<TrezorDevice> => {
|
||||
});
|
||||
}
|
||||
|
||||
export const initConnectedDevice = (device: any): ThunkAction => {
|
||||
export const initConnectedDevice = (device: TrezorDevice | Device): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
|
||||
const selected = findSelectedDevice(getState().connect);
|
||||
|
@ -441,9 +441,9 @@ export const estimateGas = (web3: Web3, options: EstimateGasOptions): Promise<nu
|
||||
})
|
||||
}
|
||||
|
||||
export const pushTx = (web3: Web3, tx: any): Promise<any> => {
|
||||
export const pushTx = (web3: Web3, tx: any): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
web3.eth.sendRawTransaction(tx, (error, result) => {
|
||||
web3.eth.sendRawTransaction(tx, (error: Error, result: string) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
|
@ -79,10 +79,10 @@ declare module 'trezor-connect' {
|
||||
};
|
||||
|
||||
|
||||
|
||||
declare type T_RESPONSE_EVENT = 'RESPONSE_EVENT';
|
||||
declare export type ResponseMessage = {
|
||||
event: string;
|
||||
type: string;
|
||||
event: T_RESPONSE_EVENT;
|
||||
type: T_RESPONSE_EVENT;
|
||||
id: number;
|
||||
success: boolean;
|
||||
payload: Object;
|
||||
@ -163,7 +163,57 @@ declare module 'trezor-connect' {
|
||||
declare type TransportEventListener = (type: T_TRANSPORT_EVENT, handler: (event: TransportMessage) => void) => void;
|
||||
|
||||
|
||||
declare type ResponseUnsuccessful = {
|
||||
success: false;
|
||||
payload: {
|
||||
error: string;
|
||||
}
|
||||
}
|
||||
|
||||
declare type ResponseEthereumSignTransaction = {
|
||||
success: true;
|
||||
payload: {
|
||||
r: string;
|
||||
s: string;
|
||||
v: string;
|
||||
}
|
||||
} | ResponseUnsuccessful;
|
||||
|
||||
declare type ResponseEthereumGetAddress = {
|
||||
success: true;
|
||||
payload: {
|
||||
address: string,
|
||||
path: Array <number>
|
||||
}
|
||||
} | ResponseUnsuccessful;
|
||||
|
||||
declare type ResponseGetDeviceState = {
|
||||
success: true;
|
||||
payload: {
|
||||
state: string;
|
||||
}
|
||||
} | ResponseUnsuccessful;
|
||||
|
||||
declare type ResponseGetFeatures = {
|
||||
success: true;
|
||||
payload: {
|
||||
// TODO
|
||||
}
|
||||
} | ResponseUnsuccessful;
|
||||
|
||||
declare type ResponseGetPublicKey = {
|
||||
success: true;
|
||||
payload: {
|
||||
chainCode: string,
|
||||
childNum: number,
|
||||
depth: number,
|
||||
fingerprint: number,
|
||||
path: Array <number>,
|
||||
publicKey: string,
|
||||
xpub: string,
|
||||
xpubFormatted: string
|
||||
}
|
||||
} | ResponseUnsuccessful;
|
||||
|
||||
|
||||
declare module.exports: {
|
||||
@ -174,13 +224,13 @@ declare module 'trezor-connect' {
|
||||
getVersion: () => any;
|
||||
renderWebUSBButton: (className?: string) => void;
|
||||
|
||||
getDeviceState: (options: Object) => Promise<Object>;
|
||||
getFeatures: (options: Object) => Promise<Object>;
|
||||
getPublicKey: (options: Object) => Promise<Object>;
|
||||
ethereumGetAddress: (options: Object) => Promise<Object>;
|
||||
getDeviceState: (options: Object) => Promise<ResponseGetDeviceState>;
|
||||
getFeatures: (options: Object) => Promise<ResponseGetFeatures>;
|
||||
getPublicKey: (options: Object) => Promise<ResponseGetPublicKey>;
|
||||
ethereumGetAddress: (options: Object) => Promise<ResponseEthereumGetAddress>;
|
||||
uiResponse: (options: Object) => Promise<Object>;
|
||||
|
||||
ethereumSignTransaction: (options: Object) => Promise<Object>;
|
||||
ethereumSignTransaction: (options: Object) => Promise<ResponseEthereumSignTransaction>;
|
||||
|
||||
|
||||
// export const RESPONSE_EVENT: string = 'RESPONSE_EVENT';
|
||||
|
@ -58,7 +58,7 @@ declare module 'web3' {
|
||||
// sign: (payload: string, signer: EthereumAddressT) => Promise<string>,
|
||||
contract: (abi: Array<Object>) => ContractFactory,
|
||||
estimateGas: (options: EstimateGasOptions, callback: (error: ?Error, gas: ?number) => void) => void,
|
||||
sendRawTransaction: (tx: any, callback: (error: Error, result: any) => void) => void,
|
||||
sendRawTransaction: (tx: any, callback: (error: Error, result: string) => void) => void,
|
||||
filter: (type: string) => Filter; // return intance with "watch"
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user