Skip to content

Commit

Permalink
Merge pull request #110 from onflow/nialexsan/fix-view-account-evm
Browse files Browse the repository at this point in the history
Nialexsan/fix view account evm
  • Loading branch information
nialexsan authored Dec 17, 2024
2 parents bbdb1c5 + 37432ce commit 838547f
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 48 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jobs:
NEXT_PUBLIC_SIGNER_ADDRESS: "0xf8d6e0586b0a20c7"
SIGNER_PRIVATE_KEY: "91a22fbd87392b019fbe332c32695c14cf2ba5b6521476a8540228bdf1987068"
NEXT_PUBLIC_TEST_NET_URL: "http://localhost:3000"
NEXT_PUBLIC_PREVIEWNET_URL: "http://localhost:3000"
NEXT_PUBLIC_TOKEN_AMOUNT_FLOW: "1000.0"
NEXT_PUBLIC_CONTRACT_FUNGIBLE_TOKEN: "0xee82856bf20e2aa6"
NEXT_PUBLIC_CONTRACT_FLOW_TOKEN: "0x0ae53cb6e3f42a79"
Expand Down
5 changes: 4 additions & 1 deletion components/CreateAccountSubmitted.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import publicConfig from "lib/publicConfig"
import {useRef, useState} from "react"
import {Box, Flex, Link, Themed, ThemeUICSSObject} from "theme-ui"
import {CustomInputComponent} from "./inputs"
import {getAccountExplorerUrl} from "lib/address"

const styles: Record<string, ThemeUICSSObject> = {
addressContainer: {
Expand Down Expand Up @@ -41,6 +42,8 @@ export default function CreateAccountSubmitted({address}: {address: string}) {
setTimeout(() => setCopied(false), 3000)
}

const accountExplorerUrl = getAccountExplorerUrl(address)

return (
<>
<Box mb={4} mt={4}>
Expand Down Expand Up @@ -82,7 +85,7 @@ export default function CreateAccountSubmitted({address}: {address: string}) {
).toLocaleString()} FLOW tokens`}
</div>
<Link
href={`https://testnet.flowdiver.io/account/${address}`}
href={accountExplorerUrl}
target="_blank"
variant="secondary"
sx={{fontSize: 1}}
Expand Down
44 changes: 15 additions & 29 deletions components/FundAccountSubmitted.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {sendScript} from "../lib/flow/send"
import * as fcl from "@onflow/fcl"
import * as t from "@onflow/types"
import {getAddressType} from "../lib/common"
import {getAccountExplorerUrl} from "lib/address"

const styles: Record<string, ThemeUICSSObject> = {
resultsContainer: {
Expand All @@ -34,9 +35,9 @@ export default function FundAccountSubmitted({
}: {
result?: ClientFundAccountResult
}) {
const [isFetchingBalance, setIsFetchingBalance] = useState(false)
const [balance, setBalance] = useState("")
const [balanceError, setBalanceError] = useState("")
const [_isFetchingBalance, setIsFetchingBalance] = useState(false)

Check warning on line 38 in components/FundAccountSubmitted.tsx

View workflow job for this annotation

GitHub Actions / Static checks (20.x)

'_isFetchingBalance' is assigned a value but never used
const [_balance, setBalance] = useState("")

Check warning on line 39 in components/FundAccountSubmitted.tsx

View workflow job for this annotation

GitHub Actions / Static checks (20.x)

'_balance' is assigned a value but never used
const [_balanceError, setBalanceError] = useState("")

Check warning on line 40 in components/FundAccountSubmitted.tsx

View workflow job for this annotation

GitHub Actions / Static checks (20.x)

'_balanceError' is assigned a value but never used

useEffect(() => {
if (typeof result === "undefined") return
Expand Down Expand Up @@ -65,7 +66,7 @@ export default function FundAccountSubmitted({
}

const balanceScript =
publicConfig.network === "previewnet" && addressType === "FLOWEVM"
addressType === "FLOWEVM"
? `import EVM from ${publicConfig.contractEVM}
/// Returns the Flow balance of a given EVM address in FlowEVM
Expand Down Expand Up @@ -102,6 +103,8 @@ access(all) fun main(account: Address): UFix64 {
fetchBalance(result.address)
}, [result])

const accountExplorerUrl = getAccountExplorerUrl(result?.address ?? "")

return (
<>
<Box mb={4} mt={4}>
Expand Down Expand Up @@ -133,32 +136,15 @@ access(all) fun main(account: Address): UFix64 {
result.token
} tokens`}
</div>
{publicConfig.network === "testnet" && (
<Link
href={`https://${publicConfig.network}.flowdiver.io/account/${result.address}`}
target="_blank"
variant="secondary"
sx={{fontSize: 1}}
>
View Account
</Link>
)}
<Link
href={accountExplorerUrl}
target="_blank"
variant="secondary"
sx={{fontSize: 1}}
>
View Account
</Link>
</Flex>
{publicConfig.network === "previewnet" && (
<>
<Label>Balance</Label>
{isFetchingBalance ? (
<div>Fetching...</div>
) : (
<>
<div>{balance}</div>
{balanceError && balanceError.length > 0 && (
<div>{balanceError}</div>
)}
</>
)}
</>
)}
</Box>
</>
)}
Expand Down
6 changes: 1 addition & 5 deletions components/PageTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import {TEST_NET} from "lib/constants"
import publicConfig from "lib/publicConfig"
import Head from "next/head"

export const BASE_HTML_TITLE = `Flow ${
publicConfig.network === TEST_NET ? "Testnet" : "Previewnet"
} Faucet`
export const BASE_HTML_TITLE = "Flow Testnet Faucet"

export default function PageTitle({children}: {children?: string}) {
const title = [children, BASE_HTML_TITLE].filter(Boolean).join(" - ")
Expand Down
1 change: 0 additions & 1 deletion env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
NEXT_PUBLIC_NETWORK=testnet
NEXT_PUBLIC_TEST_NET_URL=http://localhost:3000
NEXT_PUBLIC_PREVIEWNET_URL=http://localhost:3000
NEXT_PUBLIC_MIXPANEL_TOKEN="dev"
NEXT_PUBLIC_TOKEN_AMOUNT_FLOW=1000.0
NEXT_PUBLIC_SIGNER_ADDRESS=0xf8d6e0586b0a20c7
Expand Down
9 changes: 0 additions & 9 deletions flow.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,19 @@
"source": "./cadence/contracts/Burner.cdc",
"aliases": {
"emulator": "ee82856bf20e2aa6",
"previewnet": "b6763b4399a888c8"
}
},
"EVM": {
"source": "./cadence/contracts/EVM.cdc",
"aliases": {
"emulator": "f8d6e0586b0a20c7",
"previewnet": "b6763b4399a888c8"
}
},
"FlowToken": {
"source": "./cadence/contracts/FlowToken.cdc",
"aliases": {
"crescendo": "7e60df042a9c0868",
"emulator": "0ae53cb6e3f42a79",
"previewnet": "4445e7ad11568276",
"testnet": "7e60df042a9c0868"
}
},
Expand All @@ -28,7 +25,6 @@
"aliases": {
"crescendo": "9a0766d93b6608b7",
"emulator": "ee82856bf20e2aa6",
"previewnet": "a0225e7000ac82a9",
"testnet": "9a0766d93b6608b7"
}
},
Expand All @@ -37,7 +33,6 @@
"aliases": {
"crescendo": "f233dcee88fe0abe",
"emulator": "f8d6e0586b0a20c7",
"previewnet": "a0225e7000ac82a9",
"testnet": "f233dcee88fe0abe"
}
},
Expand All @@ -46,7 +41,6 @@
"aliases": {
"crescendo": "631e88ae7f1d7c20",
"emulator": "f8d6e0586b0a20c7",
"previewnet": "b6763b4399a888c8",
"testnet": "631e88ae7f1d7c20"
}
},
Expand All @@ -55,7 +49,6 @@
"aliases": {
"crescendo": "631e88ae7f1d7c20",
"emulator": "f8d6e0586b0a20c7",
"previewnet": "b6763b4399a888c8",
"testnet": "631e88ae7f1d7c20"
}
},
Expand All @@ -64,14 +57,12 @@
"aliases": {
"crescendo": "631e88ae7f1d7c20",
"emulator": "f8d6e0586b0a20c7",
"previewnet": "b6763b4399a888c8",
"testnet": "631e88ae7f1d7c20"
}
}
},
"networks": {
"crescendo": "access.crescendo.nodes.onflow.org:9000",
"previewnet": "access.previewnet.nodes.onflow.org:9000",
"emulator": "127.0.0.1:3569",
"testnet": "access.devnet.nodes.onflow.org:9000"
},
Expand Down
14 changes: 14 additions & 0 deletions lib/address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const with0x = (address: string) =>
!address?.startsWith("0x") ? "0x" + address : address

export const isEvmAddress = (address: string) => {
if (!address) return false
// add 0x if not supplied
const formattedAddress = with0x(address)
return /^0x[a-fA-F0-9]{40}$/.test(formattedAddress)
}

export const getAccountExplorerUrl = (address: string) =>
isEvmAddress(address)
? `https://evm-testnet.flowscan.io/address/${address}`
: `https://testnet.flowdiver.io/account/${address}`
3 changes: 1 addition & 2 deletions lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type Networks = "testnet" | "previewnet"
export type Networks = "testnet"
export type TokenTypes = typeof FLOW_TYPE

export const TEST_NET = "testnet"
Expand Down Expand Up @@ -33,5 +33,4 @@ export const ADDRESS_REGEXP = /^(0x)?([0-9a-fA-F]{16}|[0-9a-fA-F]{40})$/

export const NETWORK_CODEWORDS = {
testnet: "0x6834ba37b3980209",
previewnet: "0x5211829E88528817",
}

0 comments on commit 838547f

Please sign in to comment.