Created
June 2, 2021 14:16
-
-
Save tomusdrw/6be7adb067ba44920931d8146f7467f7 to your computer and use it in GitHub Desktop.
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
type PayloadType = { | |
}; | |
type EstimateFeeType = {}; | |
class ApiCalls { | |
async estimateFee(chain: Chain, laneId: LaneId, payload: PayloadType): EstimateFeeType { | |
const payloadType = createType(chain, "OutboundPayload", payload); | |
return await stateCall(estimateFeeMethod, ...); | |
} | |
} | |
function Component() { | |
const apiCalls: ApiCalls = useApiCalls(); | |
const { isFeeCalculating, setFeeCalculating} = useState(false); | |
const { fee, setFee } = useState(null); | |
const { feeError, setFeeError } = useState(null); | |
useEffect(() => { | |
setFeeCalculating(true); | |
setFee(null); | |
try { | |
const fee = await apiCalls.estimateFee(chain, laneId, payload) | |
setFee(fee); | |
setFeeCalculating(false); | |
} catch (e) { | |
setFeeCalculating(false); | |
setFeeError("error"); | |
} | |
}); | |
} | |
import {useEstimateFee} from './hooks/api/useEstimateFee'; | |
function Component() { | |
const { fee: number | null, feeError: string|null, isFeeCalculating: bool, recalculateFee: () => void } = useEstimateFee(laneId, ...); | |
fee==null | |
isFeeCalculating == true | |
// | |
useEffect(() => { | |
recalculateFee(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following can really make all the above TLDR and show what I mean in idea.ts and project I built.
I am approaching it more like this:
Layers 2 -4 is the "library" we need to build. Layer 5 should be the actual Bridges UI. Layer 2-4 should ALWAYS work with specific version of Layer 1