This repository has been archived by the owner on Nov 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91a7f35
commit 25a3712
Showing
1 changed file
with
86 additions
and
0 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
webapp/src/containers/TokensPage/components/CreateToken/index.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,86 @@ | ||
import React, { useState } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { RouteComponentProps } from 'react-router-dom'; | ||
import { TabContent, TabPane } from 'reactstrap'; | ||
|
||
import DCTDistribution from './DCTDistribution'; | ||
import CreateDCT from './CreateDCT'; | ||
import { createToken } from '../../reducer'; | ||
import { CREATE_DCT, DCT_DISTRIBUTION } from '../../../../constants'; | ||
|
||
interface CreateTokenProps extends RouteComponentProps { | ||
createToken: (tokenData) => void; | ||
} | ||
|
||
const CreateToken: React.FunctionComponent<CreateTokenProps> = ( | ||
props: CreateTokenProps | ||
) => { | ||
const [activeTab, setActiveTab] = useState<string>(CREATE_DCT); | ||
const [formState, setFormState] = useState<any>({ | ||
nameLabel: '', | ||
tickerSymbol: '', | ||
divisibility: '8', | ||
initialSupply: '', | ||
mintingSupport: 'no', | ||
optionalFinalSupplyLimit: '', | ||
tradable: 'no', | ||
}); | ||
const [csvData, setCsvData] = React.useState<any>([]); | ||
|
||
const { createToken } = props; | ||
|
||
const handleSubmit = () => { | ||
const tokenData = { ...formState, collateralAddresses: csvData }; | ||
createToken(tokenData); | ||
}; | ||
|
||
const handleChange = (e) => { | ||
setFormState({ | ||
...formState, | ||
[e.target.name]: e.target.value, | ||
}); | ||
}; | ||
|
||
const handleActiveTab = (active: string) => { | ||
setActiveTab(active); | ||
}; | ||
|
||
return ( | ||
<TabContent activeTab={activeTab}> | ||
<TabPane tabId={CREATE_DCT}> | ||
<div className='main-wrapper position-relative'> | ||
<CreateDCT | ||
handleActiveTab={handleActiveTab} | ||
handleChange={handleChange} | ||
formState={formState} | ||
/> | ||
</div> | ||
</TabPane> | ||
<TabPane tabId={DCT_DISTRIBUTION}> | ||
<div className='main-wrapper position-relative'> | ||
<DCTDistribution | ||
handleActiveTab={handleActiveTab} | ||
csvData={csvData} | ||
setCsvData={setCsvData} | ||
handleSubmit={handleSubmit} | ||
/> | ||
</div> | ||
</TabPane> | ||
</TabContent> | ||
); | ||
}; | ||
|
||
const mapStateToProps = (state) => { | ||
const { tokens } = state; | ||
return { | ||
isTokenCreating: tokens.isTokenCreating, | ||
createdTokenData: tokens.createdTokenData, | ||
isErrorCreatingToken: tokens.isErrorCreatingToken, | ||
}; | ||
}; | ||
|
||
const mapDispatchToProps = { | ||
createToken: (tokenData) => createToken({ tokenData }), | ||
}; | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(CreateToken); |