Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
feat: use-wallet integration (#141)
Browse files Browse the repository at this point in the history
* feat: use-wallet integration

* refactor: trimming codebase

* refactor: trimming codebase

* refactor: eslint warnings
  • Loading branch information
aorumbayev authored Dec 21, 2022
1 parent 19a1dda commit 8179e4e
Show file tree
Hide file tree
Showing 57 changed files with 1,194 additions and 1,971 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: E2E Tests
on:
pull_request:
branches: [main]
# pull_request:
# branches: [main]
workflow_dispatch:

jobs:
e2e_test:
env:
Expand Down
20 changes: 13 additions & 7 deletions e2e/pages/public-swaps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
NAV_BAR_SETTINGS_MENU_ITEM_ID,
} from '@/components/Headers/constants';
import {
CONNECT_WALLET_DIALOG_ID,
CONNECT_PROVIDER_DIALOG_ID,
FROM_ASSET_PICKER_DIALOG_SEARCH_ID,
DIALOG_SELECT_BTN_ID,
FROM_ASSET_PICKER_DIALOG_ID,
Expand Down Expand Up @@ -66,7 +66,9 @@ test.afterAll(async () => {
test.describe(`Public Swaps`, () => {
test(`Bob should be able to load and connect wallet`, async () => {
await page.locator(`id=${NAV_BAR_CONNECT_BTN_ID}`).click();
await expect(page.locator(`id=${CONNECT_WALLET_DIALOG_ID}`)).toBeVisible();
await expect(
page.locator(`id=${CONNECT_PROVIDER_DIALOG_ID}`),
).toBeVisible();
await page.locator(`div[role="button"]:has-text("Mnemonic")`).click();
await expect(page.locator(`id=${MNEMONIC_DIALOG_ID}`)).toBeVisible();
await page
Expand All @@ -76,7 +78,7 @@ test.describe(`Public Swaps`, () => {
await page.locator(`id=${MNEMONIC_DIALOG_SELECT_BUTTON_ID}`).click();

await expect(page.locator(`id=${MNEMONIC_DIALOG_ID}`)).toBeHidden();
await expect(page.locator(`id=${CONNECT_WALLET_DIALOG_ID}`)).toBeHidden();
await expect(page.locator(`id=${CONNECT_PROVIDER_DIALOG_ID}`)).toBeHidden();
});

test(`Bob should be able to navigate to Asa to Asa page`, async () => {
Expand Down Expand Up @@ -172,7 +174,9 @@ test.describe(`Public Swaps`, () => {

test(`Alice should be able to load and connect wallet`, async () => {
await page.locator(`id=${NAV_BAR_CONNECT_BTN_ID}`).click();
await expect(page.locator(`id=${CONNECT_WALLET_DIALOG_ID}`)).toBeVisible();
await expect(
page.locator(`id=${CONNECT_PROVIDER_DIALOG_ID}`),
).toBeVisible();
await page.locator(`div[role="button"]:has-text("Mnemonic")`).click();
await expect(page.locator(`id=${MNEMONIC_DIALOG_ID}`)).toBeVisible();
await page.waitForTimeout(5000);
Expand All @@ -182,7 +186,7 @@ test.describe(`Public Swaps`, () => {

await page.locator(`id=${MNEMONIC_DIALOG_SELECT_BUTTON_ID}`).click();
await expect(page.locator(`id=${MNEMONIC_DIALOG_ID}`)).toBeHidden();
await expect(page.locator(`id=${CONNECT_WALLET_DIALOG_ID}`)).toBeHidden();
await expect(page.locator(`id=${CONNECT_PROVIDER_DIALOG_ID}`)).toBeHidden();
});

test(`Alice should perform swaps`, async () => {
Expand Down Expand Up @@ -216,15 +220,17 @@ test.describe(`Public Swaps`, () => {

test(`Bob should successfully remove created swap`, async () => {
await page.locator(`id=${NAV_BAR_CONNECT_BTN_ID}`).click();
await expect(page.locator(`id=${CONNECT_WALLET_DIALOG_ID}`)).toBeVisible();
await expect(
page.locator(`id=${CONNECT_PROVIDER_DIALOG_ID}`),
).toBeVisible();
await page.locator(`div[role="button"]:has-text("Mnemonic")`).click();
await expect(page.locator(`id=${MNEMONIC_DIALOG_ID}`)).toBeVisible();
await page
.locator(`id=${MNEMONIC_DIALOG_TEXT_INPUT_ID}`)
.fill(process.env.E2E_TESTS_BOB_MNEMONIC ?? ``);
await page.locator(`id=${MNEMONIC_DIALOG_SELECT_BUTTON_ID}`).click();
await expect(page.locator(`id=${MNEMONIC_DIALOG_ID}`)).toBeHidden();
await expect(page.locator(`id=${CONNECT_WALLET_DIALOG_ID}`)).toBeHidden();
await expect(page.locator(`id=${CONNECT_PROVIDER_DIALOG_ID}`)).toBeHidden();

await page.locator(`id=${NAV_BAR_SETTINGS_BTN_ID}`).click();
await Promise.all([
Expand Down
20 changes: 13 additions & 7 deletions e2e/pages/swappers/asa-to-asa.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
NAV_BAR_SETTINGS_MENU_ITEM_ID,
} from '@/components/Headers/constants';
import {
CONNECT_WALLET_DIALOG_ID,
CONNECT_PROVIDER_DIALOG_ID,
FROM_ASSET_PICKER_DIALOG_SEARCH_ID,
DIALOG_SELECT_BTN_ID,
FROM_ASSET_PICKER_DIALOG_ID,
Expand Down Expand Up @@ -59,7 +59,9 @@ test.afterAll(async () => {
test.describe(`Asa to Asa Swap`, () => {
test(`Bob should be able to load and connect wallet`, async () => {
await page.locator(`id=${NAV_BAR_CONNECT_BTN_ID}`).click();
await expect(page.locator(`id=${CONNECT_WALLET_DIALOG_ID}`)).toBeVisible();
await expect(
page.locator(`id=${CONNECT_PROVIDER_DIALOG_ID}`),
).toBeVisible();
await page.locator(`div[role="button"]:has-text("Mnemonic")`).click();
await expect(page.locator(`id=${MNEMONIC_DIALOG_ID}`)).toBeVisible();
await page
Expand All @@ -69,7 +71,7 @@ test.describe(`Asa to Asa Swap`, () => {
await page.locator(`id=${MNEMONIC_DIALOG_SELECT_BUTTON_ID}`).click();

await expect(page.locator(`id=${MNEMONIC_DIALOG_ID}`)).toBeHidden();
await expect(page.locator(`id=${CONNECT_WALLET_DIALOG_ID}`)).toBeHidden();
await expect(page.locator(`id=${CONNECT_PROVIDER_DIALOG_ID}`)).toBeHidden();
});

test(`Bob should be able to navigate to Asa to Asa page`, async () => {
Expand Down Expand Up @@ -156,7 +158,9 @@ test.describe(`Asa to Asa Swap`, () => {

test(`Alice should be able to load and connect wallet`, async () => {
await page.locator(`id=${NAV_BAR_CONNECT_BTN_ID}`).click();
await expect(page.locator(`id=${CONNECT_WALLET_DIALOG_ID}`)).toBeVisible();
await expect(
page.locator(`id=${CONNECT_PROVIDER_DIALOG_ID}`),
).toBeVisible();
await page.locator(`div[role="button"]:has-text("Mnemonic")`).click();
await expect(page.locator(`id=${MNEMONIC_DIALOG_ID}`)).toBeVisible();
await page
Expand All @@ -165,7 +169,7 @@ test.describe(`Asa to Asa Swap`, () => {

await page.locator(`id=${MNEMONIC_DIALOG_SELECT_BUTTON_ID}`).click();
await expect(page.locator(`id=${MNEMONIC_DIALOG_ID}`)).toBeHidden();
await expect(page.locator(`id=${CONNECT_WALLET_DIALOG_ID}`)).toBeHidden();
await expect(page.locator(`id=${CONNECT_PROVIDER_DIALOG_ID}`)).toBeHidden();
});

test(`Alice should successfully perform swap created by Bob`, async () => {
Expand Down Expand Up @@ -199,15 +203,17 @@ test.describe(`Asa to Asa Swap`, () => {

test(`Bob should successfully remove created swap`, async () => {
await page.locator(`id=${NAV_BAR_CONNECT_BTN_ID}`).click();
await expect(page.locator(`id=${CONNECT_WALLET_DIALOG_ID}`)).toBeVisible();
await expect(
page.locator(`id=${CONNECT_PROVIDER_DIALOG_ID}`),
).toBeVisible();
await page.locator(`div[role="button"]:has-text("Mnemonic")`).click();
await expect(page.locator(`id=${MNEMONIC_DIALOG_ID}`)).toBeVisible();
await page
.locator(`id=${MNEMONIC_DIALOG_TEXT_INPUT_ID}`)
.fill(process.env.E2E_TESTS_BOB_MNEMONIC ?? ``);
await page.locator(`id=${MNEMONIC_DIALOG_SELECT_BUTTON_ID}`).click();
await expect(page.locator(`id=${MNEMONIC_DIALOG_ID}`)).toBeHidden();
await expect(page.locator(`id=${CONNECT_WALLET_DIALOG_ID}`)).toBeHidden();
await expect(page.locator(`id=${CONNECT_PROVIDER_DIALOG_ID}`)).toBeHidden();

await page.locator(`id=${NAV_BAR_SETTINGS_BTN_ID}`).click();
await Promise.all([
Expand Down
20 changes: 13 additions & 7 deletions e2e/pages/swappers/asas-to-algo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
NAV_BAR_SETTINGS_MENU_ITEM_ID,
} from '@/components/Headers/constants';
import {
CONNECT_WALLET_DIALOG_ID,
CONNECT_PROVIDER_DIALOG_ID,
FROM_ASSET_PICKER_DIALOG_SEARCH_ID,
DIALOG_SELECT_BTN_ID,
FROM_ASSET_PICKER_DIALOG_ID,
Expand Down Expand Up @@ -56,7 +56,9 @@ test.afterAll(async () => {
test.describe(`Asas to Algo Swap`, () => {
test(`Bob should be able to load and connect wallet`, async () => {
await page.locator(`id=${NAV_BAR_CONNECT_BTN_ID}`).click();
await expect(page.locator(`id=${CONNECT_WALLET_DIALOG_ID}`)).toBeVisible();
await expect(
page.locator(`id=${CONNECT_PROVIDER_DIALOG_ID}`),
).toBeVisible();
await page.locator(`div[role="button"]:has-text("Mnemonic")`).click();
await expect(page.locator(`id=${MNEMONIC_DIALOG_ID}`)).toBeVisible();
await page
Expand All @@ -66,7 +68,7 @@ test.describe(`Asas to Algo Swap`, () => {
await page.locator(`id=${MNEMONIC_DIALOG_SELECT_BUTTON_ID}`).click();

await expect(page.locator(`id=${MNEMONIC_DIALOG_ID}`)).toBeHidden();
await expect(page.locator(`id=${CONNECT_WALLET_DIALOG_ID}`)).toBeHidden();
await expect(page.locator(`id=${CONNECT_PROVIDER_DIALOG_ID}`)).toBeHidden();
});

test(`Bob should be able to navigate to Asas to Algo page`, async () => {
Expand Down Expand Up @@ -149,7 +151,9 @@ test.describe(`Asas to Algo Swap`, () => {

test(`Alice should be able to load and connect wallet`, async () => {
await page.locator(`id=${NAV_BAR_CONNECT_BTN_ID}`).click();
await expect(page.locator(`id=${CONNECT_WALLET_DIALOG_ID}`)).toBeVisible();
await expect(
page.locator(`id=${CONNECT_PROVIDER_DIALOG_ID}`),
).toBeVisible();
await page.locator(`div[role="button"]:has-text("Mnemonic")`).click();
await expect(page.locator(`id=${MNEMONIC_DIALOG_ID}`)).toBeVisible();
await page
Expand All @@ -158,7 +162,7 @@ test.describe(`Asas to Algo Swap`, () => {

await page.locator(`id=${MNEMONIC_DIALOG_SELECT_BUTTON_ID}`).click();
await expect(page.locator(`id=${MNEMONIC_DIALOG_ID}`)).toBeHidden();
await expect(page.locator(`id=${CONNECT_WALLET_DIALOG_ID}`)).toBeHidden();
await expect(page.locator(`id=${CONNECT_PROVIDER_DIALOG_ID}`)).toBeHidden();
});

test(`Alice should successfully perform swap created by Bob`, async () => {
Expand Down Expand Up @@ -192,15 +196,17 @@ test.describe(`Asas to Algo Swap`, () => {

test(`Bob should successfully remove created swap`, async () => {
await page.locator(`id=${NAV_BAR_CONNECT_BTN_ID}`).click();
await expect(page.locator(`id=${CONNECT_WALLET_DIALOG_ID}`)).toBeVisible();
await expect(
page.locator(`id=${CONNECT_PROVIDER_DIALOG_ID}`),
).toBeVisible();
await page.locator(`div[role="button"]:has-text("Mnemonic")`).click();
await expect(page.locator(`id=${MNEMONIC_DIALOG_ID}`)).toBeVisible();
await page
.locator(`id=${MNEMONIC_DIALOG_TEXT_INPUT_ID}`)
.fill(process.env.E2E_TESTS_BOB_MNEMONIC ?? ``);
await page.locator(`id=${MNEMONIC_DIALOG_SELECT_BUTTON_ID}`).click();
await expect(page.locator(`id=${MNEMONIC_DIALOG_ID}`)).toBeHidden();
await expect(page.locator(`id=${CONNECT_WALLET_DIALOG_ID}`)).toBeHidden();
await expect(page.locator(`id=${CONNECT_PROVIDER_DIALOG_ID}`)).toBeHidden();

await page.locator(`id=${NAV_BAR_SETTINGS_BTN_ID}`).click();
await Promise.all([
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "algoworld-swapper",
"description": "Free and trustless ASA swapper, powered by Algorand ⚡️",
"version": "0.8.2",
"version": "0.9.0",
"private": true,
"author": "AlgoWorld <[email protected]>",
"license": "GPL-3.0",
Expand Down Expand Up @@ -32,31 +32,36 @@
]
},
"dependencies": {
"@blockshake/defly-connect": "1.0.0",
"@emotion/cache": "11.10.5",
"@emotion/react": "11.10.5",
"@emotion/server": "11.10.0",
"@emotion/styled": "11.10.5",
"@fontsource/roboto": "4.5.8",
"@hookform/resolvers": "2.9.10",
"@json-rpc-tools/utils": "1.7.6",
"@mui/icons-material": "5.11.0",
"@mui/lab": "5.0.0-alpha.112",
"@mui/material": "5.11.0",
"@mui/x-data-grid": "5.17.16",
"@perawallet/connect": "1.0.7",
"@randlabs/myalgo-connect": "1.4.2",
"@reduxjs/toolkit": "1.9.1",
"@txnlab/use-wallet": "1.0.4",
"@walletconnect/client": "1.8.0",
"algorand-walletconnect-qrcode-modal": "1.8.0",
"algosdk": "1.24.1",
"axios": "0.27.2",
"axios-retry": "3.3.1",
"next": "13.0.7",
"next-pwa": "5.6.0",
"nextjs-google-analytics": "2.2.2",
"notistack": "2.0.8",
"prop-types": "15.8.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-number-format": "4.9.4",
"react-redux": "8.0.5",
"react-toastify": "9.1.1",
"react-tsparticles": "2.6.0",
"react-use": "17.4.0",
"swr": "1.3.0",
Expand Down
3 changes: 3 additions & 0 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import { ChainType } from '@/models/Chain';
import { IpfsGateway } from '@/models/Gateway';
import { PROVIDER_ID } from '@txnlab/use-wallet';

export const CHAIN_TYPE: ChainType =
(process.env.NEXT_PUBLIC_CHAIN_TYPE ?? `TestNet`) === `TestNet`
Expand Down Expand Up @@ -95,3 +96,5 @@ export const PERFORM_SWAP_PERFORM_BUTTON_ID = `AWPerformSwapPerformButton`;

export const PUBLIC_SWAPS_SEARCH_FIELD_ID = `AWPublicSwapsSearchField`;
export const PUBLIC_SWAPS_SEARCH_BUTTON_ID = `AWPublicSwapsSearchButton`;

export const WALLET_PROVIDER_IDS = [PROVIDER_ID.MYALGO, PROVIDER_ID.PERA];
27 changes: 0 additions & 27 deletions src/components/Buttons/ViewOnAlgoExplorerButton.test.tsx

This file was deleted.

44 changes: 0 additions & 44 deletions src/components/Buttons/ViewOnAlgoExplorerButton.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/components/Buttons/constants.ts

This file was deleted.

13 changes: 8 additions & 5 deletions src/components/Cards/FromSwapCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import { Asset } from '@/models/Asset';
import { FromAssetPickerDialog } from '../Dialogs/FromAssetPickerDialog';
import AssetListView from '../Lists/AssetListView';
import { useAppSelector, useAppDispatch } from '@/redux/store/hooks';
import { setOfferingAssets } from '@/redux/slices/walletConnectSlice';
import { setOfferingAssets } from '@/redux/slices/applicationSlice';
import { FROM_SWAP_OFFERING_ASSET_BTN_ID } from './constants';
import { useWallet } from '@txnlab/use-wallet';

type Props = {
cardTitle: string;
Expand All @@ -33,12 +34,12 @@ type Props = {
};

const FromSwapCard = ({ cardTitle, maxAssets, disabled = false }: Props) => {
const assets = useAppSelector((state) => state.walletConnect.assets);
const address = useAppSelector((state) => state.walletConnect.address);
const assets = useAppSelector((state) => state.application.assets);
const { activeAddress } = useWallet();
const [pickerOpen, setPickerOpen] = useState<boolean>(false);

const offeringAssets = useAppSelector(
(state) => state.walletConnect.selectedOfferingAssets,
(state) => state.application.selectedOfferingAssets,
);
const dispatch = useAppDispatch();

Expand Down Expand Up @@ -76,7 +77,9 @@ const FromSwapCard = ({ cardTitle, maxAssets, disabled = false }: Props) => {
<Button
id={FROM_SWAP_OFFERING_ASSET_BTN_ID}
disabled={
offeringAssets.length >= maxAssets || !address || disabled
offeringAssets.length >= maxAssets ||
!activeAddress ||
disabled
}
variant="outlined"
onClick={() => {
Expand Down
Loading

1 comment on commit 8179e4e

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for algoworld-swapper ready!

✅ Preview
https://algoworld-swapper-plgmc8wpe-algoworldexplorer.vercel.app

Built with commit 8179e4e.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.