Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: build parachainConfig from node to expand snowEnv #20

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
8 changes: 8 additions & 0 deletions .env → .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@
# - `kusama_mainnet` for Kusama <=> Ethereum bridge. (TBD)
# - `polkadot_mainnet` for Polkadot <=> Ethereum bridge.
NEXT_PUBLIC_SNOWBRIDGE_ENV=local_e2e


# Indexers A.P.I. Keys:
NEXT_PUBLIC_ALCHEMY_KEY=
NEXT_PUBLIC_SUBSCAN_KEY=

# parachain endpoints to build their configuration from node info. ";" separated
PARACHAIN_ENDPOINTS=wss://rilt.kilt.io
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Perform token transfers using Snowbridge.

### Configure

On the `.env`-file, configure of your project by assigning the values that fit your needs.
Copy the `.env.example`-file into an `.env`-file on the same scope.
Then, on the `.env`-file, configure of your project by assigning the values that fit your needs.

**NEXT_PUBLIC_SNOWBRIDGE_ENV** accepts:

Expand All @@ -19,7 +20,7 @@ On the `.env`-file, configure of your project by assigning the values that fit y
NEXT_PUBLIC_SNOWBRIDGE_ENV=rococo_sepolia
```

If you are not using local chains, create an `.env.local` to set the required A.P.I. keys.
If you are not using local chains, set the required A.P.I. keys.

```env
NEXT_PUBLIC_ALCHEMY_KEY=...
Expand Down
8 changes: 6 additions & 2 deletions __tests__/countryBlock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ function countryBlockCase(

when(mockedRequest.nextUrl).thenReturn(nextUrl);
const headers = new Headers();
if (country) headers.set(COUNTRY_HEADER_NAME, country);
if (region) headers.set(REGION_HEADER_NAME, region);
if (country) {
headers.set(COUNTRY_HEADER_NAME, country);
}
if (region) {
headers.set(REGION_HEADER_NAME, region);
}
when(mockedRequest.headers).thenReturn(headers);

const result = middleware(instance(mockedRequest));
Expand Down
12 changes: 8 additions & 4 deletions app/history/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ const transferTitle = (
history.TransferStatus.Failed == transfer.status
? " bg-destructive"
: history.TransferStatus.Pending == transfer.status
? ""
: "bg-secondary";
? ""
: "bg-secondary";

const { tokenName, amount } = formatTokenData(
transfer,
Expand Down Expand Up @@ -464,7 +464,9 @@ export default function History() {
const hashItem = useWindowHash();

useEffect(() => {
if (transfers === null) return;
if (transfers === null) {
return;
}
setTransferHistoryCache(transfers);
}, [transfers, setTransferHistoryCache]);

Expand Down Expand Up @@ -505,7 +507,9 @@ export default function History() {
transfer.info.sourceAddress,
transfer.info.beneficiaryAddress,
);
if (!showGlobal && !transfer.isWalletTransaction) continue;
if (!showGlobal && !transfer.isWalletTransaction) {
continue;
}

allTransfers.push(transfer);
}
Expand Down
4 changes: 3 additions & 1 deletion app/status/api/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const CACHE_REVALIDATE_IN_SECONDS = 60; // 1 minutes

let context: Context | null = null;
async function getContext() {
if (context) return context;
if (context) {
return context;
}
const env = getEnvironment();

const alchemyKey = process.env.NEXT_PUBLIC_ALCHEMY_KEY;
Expand Down
8 changes: 6 additions & 2 deletions app/status/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ const StatusCard = () => {
const hash = useWindowHash();
const diagnostic = hash === "diagnostic";

if (status == null) return <Loading />;
if (status == null) {
return <Loading />;
}

const toPolkadotStyle =
status.summary.toPolkadotOperatingMode === "Normal"
Expand All @@ -105,7 +107,9 @@ const StatusCard = () => {
status.summary.overallStatus === "Normal"
? "text-green-700 font-semibold"
: "text-red-700 font-semibold";
if (status == null) return <Loading />;
if (status == null) {
return <Loading />;
}

return (
<>
Expand Down
4 changes: 3 additions & 1 deletion components/BridgeStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const StatusCard = () => {
const { data: bridgeStatus } = useBridgeStatus();
const pathname = usePathname();

if (bridgeStatus == null) return <Loading />;
if (bridgeStatus == null) {
return <Loading />;
}

const toPolkadotStyle =
bridgeStatus.summary.toPolkadotOperatingMode === "Normal"
Expand Down
4 changes: 3 additions & 1 deletion components/BusyDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export const BusyDialog: FC<BusyDialogProps> = ({
<Dialog
open={open}
onOpenChange={(a) => {
if (!a && dismiss) dismiss();
if (!a && dismiss) {
dismiss();
}
}}
>
<DialogContent>
Expand Down
4 changes: 3 additions & 1 deletion components/ErrorDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export const ErrorDialog: FC<ErrorProps> = ({
<Dialog
open={open}
onOpenChange={(a) => {
if (!a && dismiss) dismiss();
if (!a && dismiss) {
dismiss();
}
}}
>
<DialogContent>
Expand Down
17 changes: 12 additions & 5 deletions components/Transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const TransferComponent: FC = () => {
.toLowerCase()
.trim() === "true";

if (maintenance)
if (maintenance) {
return (
<div className="flex-col gap-2">
<div className="flex justify-center">
Expand All @@ -115,6 +115,7 @@ export const TransferComponent: FC = () => {
<p>Under Maintenance: Check back soon!</p>
</div>
);
}
return <TransferForm />;
};

Expand Down Expand Up @@ -167,7 +168,9 @@ export const TransferForm: FC = () => {
});

useEffect(() => {
if (context == null) return;
if (context == null) {
return;
}
switch (source.type) {
case "substrate": {
toEthereum
Expand Down Expand Up @@ -290,7 +293,9 @@ export const TransferForm: FC = () => {
]);

useEffect(() => {
if (context == null) return;
if (context == null) {
return;
}
if (assetErc20MetaData !== null && assetErc20MetaData[token]) {
setTokenMetadata(assetErc20MetaData[token]);
return;
Expand Down Expand Up @@ -328,8 +333,9 @@ export const TransferForm: FC = () => {
ethereumChainId == null ||
token === "" ||
tokenMetadata == null
)
) {
return;
}
updateBalance(
context,
ethereumChainId,
Expand Down Expand Up @@ -431,8 +437,9 @@ export const TransferForm: FC = () => {
context == null ||
ethereumChainId == null ||
sourceAccount == undefined
)
) {
return;
}
const toastTitle = "Approve Token Spend";
setBusyMessage("Approving spend...");
try {
Expand Down
4 changes: 3 additions & 1 deletion hooks/useBridgeStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ const fetchStatus = async ([env, context]: [
]): Promise<BridgeStatus | null> => {
if (process.env.NEXT_PUBLIC_USE_CLIENT_SIDE_HISTORY_FETCH === "true") {
try {
if (context === null) return null;
if (context === null) {
return null;
}
return await getBridgeStatus(context, env);
} catch (err) {
console.error(err);
Expand Down
4 changes: 3 additions & 1 deletion hooks/useConnectEthereumWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export const useConnectEthereumWallet = (): [
}
} catch (err) {
let message = "Unknown Error";
if (err instanceof Error) message = err.message;
if (err instanceof Error) {
message = err.message;
}
setError(message);
}
setLoading(false);
Expand Down
8 changes: 6 additions & 2 deletions hooks/useConnectPolkadotWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export const useConnectPolkadotWallet = (ss58Format?: number): void => {
const [walletName] = useAtom(walletNameAtom);

useEffect(() => {
if (wallet != null || walletName == null) return;
if (wallet != null || walletName == null) {
return;
}
let unmounted = false;
const connect = async (): Promise<void> => {
const { getWalletBySource } = await import("@talismn/connect-wallets");
Expand All @@ -43,7 +45,9 @@ export const useConnectPolkadotWallet = (ss58Format?: number): void => {
let unsub: () => void;
let unmounted = false;
const saveAccounts = (accounts?: WalletAccount[]): void => {
if (accounts == null || unmounted) return;
if (accounts == null || unmounted) {
return;
}
if (ss58Format === undefined) {
setAccounts(accounts);
} else {
Expand Down
8 changes: 6 additions & 2 deletions hooks/useEthereumProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ export const useEthereumProvider = () => {
const setEthereumChainId = useSetAtom(ethereumChainIdAtom);

useEffect(() => {
if (ethereumProvider != null) return;
if (ethereumProvider != null) {
return;
}
const init = async (): Promise<void> => {
const provider = await getEthereumProvider();
if (provider == null) return;
if (provider == null) {
return;
}
const updateAccounts = (accounts: string[]): void => {
setEthereumAccount(accounts[0] ?? null);
setEthereumAccounts(accounts);
Expand Down
4 changes: 3 additions & 1 deletion hooks/useSnowbridgeContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ export const useSnowbridgeContext = (): [
})
.catch((error) => {
let message = "Unknown Error";
if (error instanceof Error) message = error.message;
if (error instanceof Error) {
message = error.message;
}
setLoading(false);
setError(message);
});
Expand Down
4 changes: 3 additions & 1 deletion hooks/useSwitchEthereumNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export const useSwitchEthereumNetwork = (): {
const shouldSwitchNetwork = providerChainID !== envChainId;

const switchNetwork = useCallback(async () => {
if (!shouldSwitchNetwork || ethereum === null) return;
if (!shouldSwitchNetwork || ethereum === null) {
return;
}
const chainIdHex = `0x${envChainId.toString(16)}`;
try {
await ethereum.request({
Expand Down
Loading