generated from veeso-dev/rust-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: set fly canister address after creation
- Loading branch information
Showing
7 changed files
with
180 additions
and
20 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
86 changes: 86 additions & 0 deletions
86
ethereum/fly/app/src/js/components/Form/SetFlyCanisterAddress/SetFlyCanisterAddressForm.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 * as React from 'react'; | ||
import { useConnectedMetaMask } from 'metamask-react'; | ||
|
||
import Container from '../../reusable/Container'; | ||
import Heading from '../../reusable/Heading'; | ||
import Input from '../../reusable/Input'; | ||
import Button from '../../reusable/Button'; | ||
import Web3Client from '../../../web3/Web3Client'; | ||
import Alerts from '../../reusable/Alerts'; | ||
import { ChainId } from '../../MetamaskConnect'; | ||
|
||
const setFlyCanisterAddressForm = () => { | ||
const { account, ethereum, chainId } = useConnectedMetaMask(); | ||
const [address, setAddress] = React.useState(''); | ||
const [addressSet, setAddressSet] = React.useState<string | null>(null); | ||
const [pendingTx, setPendingTx] = React.useState<boolean>(false); | ||
const [error, setError] = React.useState<string>(); | ||
|
||
const onAddressChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setAddress(event.target.value); | ||
}; | ||
|
||
const onChangeAddress = () => { | ||
setPendingTx(true); | ||
const client = new Web3Client(account, ethereum, chainId as ChainId); | ||
client | ||
.setFlyCanisterAddress(address) | ||
.then(() => { | ||
setPendingTx(false); | ||
setError(undefined); | ||
}) | ||
.catch((e) => { | ||
setError(e.message); | ||
setPendingTx(false); | ||
}); | ||
}; | ||
|
||
React.useEffect(() => { | ||
if (account && ethereum && chainId) { | ||
const client = new Web3Client(account, ethereum, chainId as ChainId); | ||
client | ||
.getFlyCanisterAddress() | ||
.then((address) => { | ||
setAddressSet(address); | ||
}) | ||
.catch((e) => { | ||
console.log(e); | ||
setAddressSet(null); | ||
}); | ||
} | ||
}, [account, ethereum, chainId]); | ||
|
||
const btnDisabled = address.length != 42 || pendingTx; | ||
|
||
return ( | ||
<Container.FlexCols className="items-center"> | ||
{addressSet ? ( | ||
<Heading.H2>Fly canister address: {addressSet}</Heading.H2> | ||
) : ( | ||
<> | ||
<Heading.H2>Set Fly canister address</Heading.H2> | ||
<Input.Input | ||
id="change-fly-canister-form-address" | ||
label="Fly canister ETH address" | ||
onChange={onAddressChange} | ||
value={address} | ||
/> | ||
<Button.Danger | ||
disabled={btnDisabled} | ||
onClick={onChangeAddress} | ||
className="!mt-4" | ||
> | ||
Set fly canister address | ||
</Button.Danger> | ||
{error && ( | ||
<Alerts.Danger> | ||
<p>{error}</p> | ||
</Alerts.Danger> | ||
)} | ||
</> | ||
)} | ||
</Container.FlexCols> | ||
); | ||
}; | ||
|
||
export default setFlyCanisterAddressForm; |
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
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