mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-28 03:08:30 +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
|
// get xpub from TREZOR
|
||||||
const response: Object = await TrezorConnect.getPublicKey({
|
const response = await TrezorConnect.getPublicKey({
|
||||||
device: {
|
device: {
|
||||||
path: device.path,
|
path: device.path,
|
||||||
instance: device.instance,
|
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 => {
|
return (dispatch: Dispatch, getState: GetState): void => {
|
||||||
const accountState: ?AccountState = getState().abstractAccount;
|
const accountState: ?AccountState = getState().abstractAccount;
|
||||||
if (!accountState) return;
|
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 data: string = '0x' + (currentState.data.length % 2 === 0 ? currentState.data : '0' + currentState.data);
|
||||||
const gasLimit = await estimateGas(web3instance.web3, {
|
const gasLimit = await estimateGas(web3instance.web3, {
|
||||||
to: '0xdb6e09ddca62d0959dc4725697e66b8152222aee',
|
to: '0xdb6e09ddca62d0959dc4725697e66b8152222aee', // TODO: real adress
|
||||||
data,
|
data,
|
||||||
value: web3.toHex(web3.toWei(currentState.amount, 'ether')),
|
value: web3.toHex(web3.toWei(currentState.amount, 'ether')),
|
||||||
gasPrice: web3.toHex( EthereumjsUnits.convert(currentState.gasPrice, 'gwei', 'wei') ),
|
gasPrice: web3.toHex( EthereumjsUnits.convert(currentState.gasPrice, 'gwei', 'wei') ),
|
||||||
@ -861,20 +861,6 @@ export const onSend = (): AsyncAction => {
|
|||||||
v: ''
|
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);
|
const selected: ?TrezorDevice = findSelectedDevice(getState().connect);
|
||||||
if (!selected) return;
|
if (!selected) return;
|
||||||
|
|
||||||
@ -914,17 +900,13 @@ export const onSend = (): AsyncAction => {
|
|||||||
txData.s = '0x' + signedTransaction.payload.s;
|
txData.s = '0x' + signedTransaction.payload.s;
|
||||||
txData.v = web3.toHex(signedTransaction.payload.v);
|
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 {
|
try {
|
||||||
const tx = new EthereumjsTx(txData);
|
const tx = new EthereumjsTx(txData);
|
||||||
const serializedTx = '0x' + tx.serialize().toString('hex');
|
const serializedTx = '0x' + tx.serialize().toString('hex');
|
||||||
const txid: string = await pushTx(web3, serializedTx);
|
const txid: string = await pushTx(web3, serializedTx);
|
||||||
|
const coin: Coin = accountState.coin;
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: SEND.TX_COMPLETE,
|
type: SEND.TX_COMPLETE,
|
||||||
@ -940,13 +922,13 @@ export const onSend = (): AsyncAction => {
|
|||||||
payload: {
|
payload: {
|
||||||
type: 'success',
|
type: 'success',
|
||||||
title: 'Transaction 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,
|
cancelable: true,
|
||||||
actions: []
|
actions: []
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch(error) {
|
} catch (error) {
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: NOTIFICATION.ADD,
|
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 => {
|
return (dispatch: Dispatch, getState: GetState): void => {
|
||||||
|
|
||||||
const selected = findSelectedDevice(getState().connect);
|
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) => {
|
return new Promise((resolve, reject) => {
|
||||||
web3.eth.sendRawTransaction(tx, (error, result) => {
|
web3.eth.sendRawTransaction(tx, (error: Error, result: string) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -79,10 +79,10 @@ declare module 'trezor-connect' {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
declare type T_RESPONSE_EVENT = 'RESPONSE_EVENT';
|
||||||
declare export type ResponseMessage = {
|
declare export type ResponseMessage = {
|
||||||
event: string;
|
event: T_RESPONSE_EVENT;
|
||||||
type: string;
|
type: T_RESPONSE_EVENT;
|
||||||
id: number;
|
id: number;
|
||||||
success: boolean;
|
success: boolean;
|
||||||
payload: Object;
|
payload: Object;
|
||||||
@ -163,7 +163,57 @@ declare module 'trezor-connect' {
|
|||||||
declare type TransportEventListener = (type: T_TRANSPORT_EVENT, handler: (event: TransportMessage) => void) => void;
|
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: {
|
declare module.exports: {
|
||||||
@ -174,13 +224,13 @@ declare module 'trezor-connect' {
|
|||||||
getVersion: () => any;
|
getVersion: () => any;
|
||||||
renderWebUSBButton: (className?: string) => void;
|
renderWebUSBButton: (className?: string) => void;
|
||||||
|
|
||||||
getDeviceState: (options: Object) => Promise<Object>;
|
getDeviceState: (options: Object) => Promise<ResponseGetDeviceState>;
|
||||||
getFeatures: (options: Object) => Promise<Object>;
|
getFeatures: (options: Object) => Promise<ResponseGetFeatures>;
|
||||||
getPublicKey: (options: Object) => Promise<Object>;
|
getPublicKey: (options: Object) => Promise<ResponseGetPublicKey>;
|
||||||
ethereumGetAddress: (options: Object) => Promise<Object>;
|
ethereumGetAddress: (options: Object) => Promise<ResponseEthereumGetAddress>;
|
||||||
uiResponse: (options: Object) => Promise<Object>;
|
uiResponse: (options: Object) => Promise<Object>;
|
||||||
|
|
||||||
ethereumSignTransaction: (options: Object) => Promise<Object>;
|
ethereumSignTransaction: (options: Object) => Promise<ResponseEthereumSignTransaction>;
|
||||||
|
|
||||||
|
|
||||||
// export const RESPONSE_EVENT: string = 'RESPONSE_EVENT';
|
// export const RESPONSE_EVENT: string = 'RESPONSE_EVENT';
|
||||||
|
@ -58,7 +58,7 @@ declare module 'web3' {
|
|||||||
// sign: (payload: string, signer: EthereumAddressT) => Promise<string>,
|
// sign: (payload: string, signer: EthereumAddressT) => Promise<string>,
|
||||||
contract: (abi: Array<Object>) => ContractFactory,
|
contract: (abi: Array<Object>) => ContractFactory,
|
||||||
estimateGas: (options: EstimateGasOptions, callback: (error: ?Error, gas: ?number) => void) => void,
|
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"
|
filter: (type: string) => Filter; // return intance with "watch"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user