import { BigNumber } from '@ethersproject/bignumber' ; import { createSlice , PayloadAction } from '@reduxjs/toolkit' ; import { constants } from 'ethers' ; import { CurrencyOption } from 'models/currency-option' ; import { PayoutMod , TicketMod } from 'models/mods' ; import { ProjectMetadataV3 } from 'models/project-metadata' ; import { fromPerbicent , fromPermille , parsePerbicent , parsePermille , } from 'utils/formatNumber' ; import { SerializedFundingCycle , serializeFundingCycle , } from 'utils/serializers' ; interface EditingProjectInfo { metadata : ProjectMetadataV3 ; handle : string ; } export interface EditingProjectState { version : number ; info : EditingProjectInfo ; fundingCycle : SerializedFundingCycle ; payoutMods : PayoutMod [ ] ; ticketMods : TicketMod [ ] ; } const defaultDiscountRate = parsePermille ( 0 ) ; const defaultBondingCurveRate = parsePerbicent ( 100 ) ; export const defaultProjectState = { version : 1 , info : { metadata : { name : '' , infoUri : '' , logoUri : '' , description : '' , twitter : '' , discord : '' , tokens : [ ] , version : 3 , } , handle : '' , } , fundingCycle : serializeFundingCycle ( { id : BigNumber . from ( 1 ) , projectId : BigNumber . from ( 0 ) , number : BigNumber . from ( 1 ) , basedOn : BigNumber . from ( 0 ) , target : constants . MaxUint256 , currency : BigNumber . from ( 1 ) , start : BigNumber . from ( Math . floor ( new Date ( ) . valueOf ( ) / 1000 ) ) , duration : BigNumber . from ( 0 ) , tapped : BigNumber . from ( 0 ) , weight : BigNumber . from ( '1000000000000000000000000' ) , fee : BigNumber . from ( 0 ) , reserved : parsePerbicent ( 0 ) , bondingCurveRate : defaultBondingCurveRate , discountRate : defaultDiscountRate , cycleLimit : BigNumber . from ( 0 ) , configured : BigNumber . from ( 0 ) , ballot : constants . AddressZero , payIsPaused : false , ticketPrintingIsAllowed : true , treasuryExtension : constants . AddressZero , } ) , payoutMods : [ ] , ticketMods : [ ] , } ; export const editingProjectSlice = createSlice ( { name : 'editingProject' , initialState : defaultProjectState , reducers : { setState : ( state , action ) => action . payload , resetState : ( ) => defaultProjectState , setProjectInfo : ( state , action ) => { state . info = action . payload ; } , setName : ( state , action ) => { state . info . metadata . name = action . payload ; } , setInfoUri : ( state , action ) => { state . info . metadata . infoUri = action . payload ; } , setLogoUri : ( state , action ) => { state . info . metadata . logoUri = action . payload ; } , setTwitter : ( state , action ) => { state . info . metadata . twitter = action . payload ; } , setDiscord : ( state , action ) => { state . info . metadata . discord = action . payload ; } , setPayButton : ( state , action ) => { state . info . metadata . payButton = action . payload ; } , setPayDisclosure : ( state , action ) => { state . info . metadata . payDisclosure = action . payload ; } , setHandle : ( state , action ) => { state . info . handle = action . payload ; } , setDescription : ( state , action ) => { state . info . metadata . description = action . payload ; } , setFundingCycle : ( state , action ) => { state . fundingCycle = action . payload ; } , setId : ( state , action ) => { state . fundingCycle . id = action . payload ; } , setProjectId : ( state , action ) => { state . fundingCycle . projectId = action . payload ; } , setNumber : ( state , action ) => { state . fundingCycle . number = action . payload ; } , setTarget : ( state , action ) => { state . fundingCycle . target = action . payload ; } , setFee : ( state , action ) => { state . fundingCycle . fee = action . payload ; } , setDuration : ( state , action ) => { state . fundingCycle . duration = action . payload ; } , setReserved : ( state , action ) => { state . fundingCycle . reserved = action . payload ; } , setDiscountRate : ( state , action ) => { state . fundingCycle . discountRate = action . payload ; } , setBondingCurveRate : ( state , action ) => { state . fundingCycle . bondingCurveRate = action . payload ; } , setCurrency : ( state , action ) => { state . fundingCycle . currency = action . payload . toString ( ) ; } , setBallot : ( state , action ) => { state . fundingCycle . ballot = action . payload ; } , setIsRecurring : ( state , action ) => { state . fundingCycle . discountRate = fromPermille ( action . payload ? defaultDiscountRate : '201' ) ; state . fundingCycle . bondingCurveRate = fromPerbicent ( action . payload ? defaultBondingCurveRate : 0 ) ; } , setPayIsPaused : ( state , action ) => { state . fundingCycle . payIsPaused = action . payload ; } , setticketPrintingIsAllowed : ( state , action ) => { state . fundingCycle . ticketPrintingIsAllowed = action . payload ; } , setPayoutMods : ( state , action ) => { state . payoutMods = action . payload ; } , setTicketMods : ( state , action ) => { state . ticketMods = action . payload ; } , } , } ) ; export const editingProjectActions = editingProjectSlice . actions ; export default editingProjectSlice . reducer ;