Last active
September 22, 2022 16:54
-
-
Save yornaath/ee821afabdaf188e1d39ba2879d78b18 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const App: React.FC = () => { | |
const [sdk, setSdk] = useState<Partial<Sdk<Context>>>() | |
const [markets, setMarkets] = useState<Array<RpcMarket | IndexedMarket>>([]) | |
const loadMarkets = async (sdk: Sdk<Context>) => { | |
const markets = await sdk.model.markets.list() | |
setMarkets(markets) | |
} | |
useEffect(() => { | |
web3Enable('sdkv2') | |
builder(batterystation()).subscribe(sdk => { | |
setSdk(sdk) | |
}) | |
}, []) | |
useEffect(() => { | |
if (isRpcSdk(sdk) || isIndexedSdk(sdk)) { | |
loadMarkets(sdk) | |
} | |
}, [sdk]) | |
return ( | |
<div style={{ display: 'grid', columnGap: '50px' }}> | |
{markets.map((market, index) => ( | |
<Market key={index} market={market} /> | |
))} | |
</div> | |
) | |
} | |
const Market = (props: { market: RpcMarket | IndexedMarket }) => { | |
return ( | |
<div> | |
{isRpcMarket(props.market) ? ( | |
<div>rpc: {props.market.marketId.toHuman()}</div> | |
) : ( | |
<div>indexer: {props.market.marketId}</div> | |
)} | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment