-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solution: common class for new tx ui
- Loading branch information
Showing
8 changed files
with
89 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/react-app/src/transaction/SetupTransaction/flow/common/common.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { EthereumEntry, WalletEntry } from '@emeraldpay/emerald-vault-core'; | ||
import { workflow } from '@emeraldwallet/core'; | ||
import { AnyCreateTx } from '@emeraldwallet/core/src/transaction/workflow'; | ||
import { CreateTxStage } from '@emeraldwallet/store'; | ||
import * as React from 'react'; | ||
import { Actions, EthereumFee } from '../components'; | ||
import { BaseFlow, Data, DataProvider, Handler } from '../types'; | ||
|
||
export abstract class CommonFlow implements BaseFlow { | ||
readonly data: Data<AnyCreateTx, WalletEntry>; | ||
readonly dataProvider: DataProvider; | ||
readonly handler: Handler; | ||
|
||
constructor(data: Data<AnyCreateTx, WalletEntry>, dataProvider: DataProvider, handler: Handler) { | ||
this.data = data; | ||
this.dataProvider = dataProvider; | ||
this.handler = handler; | ||
} | ||
|
||
abstract render(): React.ReactElement; | ||
|
||
renderActions(): React.ReactElement { | ||
const { createTx, entry, fee } = this.data; | ||
const { onCancel, setEntry, setStage, setTransaction } = this.handler; | ||
|
||
const handleCreateTx = (): void => { | ||
setEntry(entry); | ||
setTransaction(createTx.dump()); | ||
|
||
setStage(CreateTxStage.SIGN); | ||
}; | ||
|
||
return <Actions createTx={createTx} initializing={fee.loading} onCancel={onCancel} onCreate={handleCreateTx} />; | ||
} | ||
} | ||
|
||
type EthereumData = Data<workflow.AnyEthereumCreateTx, EthereumEntry>; | ||
|
||
export abstract class EthereumCommonFlow extends CommonFlow { | ||
readonly data: EthereumData; | ||
|
||
constructor(data: EthereumData, dataProvider: DataProvider, handler: Handler) { | ||
super(data, dataProvider, handler); | ||
|
||
this.data = data; | ||
} | ||
|
||
renderFee(): React.ReactElement { | ||
const { | ||
createTx, | ||
fee: { loading, range }, | ||
} = this.data; | ||
|
||
if (!workflow.isEthereumFeeRange(range)) { | ||
throw new Error('Bitcoin transaction or fee provided for Ethereum transaction'); | ||
} | ||
|
||
const { setTransaction } = this.handler; | ||
|
||
return <EthereumFee createTx={createTx} feeRange={range} initializing={loading} setTransaction={setTransaction} />; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/react-app/src/transaction/SetupTransaction/flow/common/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/* eslint sort-exports/sort-exports: error */ | ||
|
||
export { CommonFlow, EthereumCommonFlow } from './common'; | ||
export { ModifyFlow } from './modify'; | ||
export { TransferFlow } from './transfer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters