Skip to content

Commit

Permalink
Merge pull request #610 from arconnectio/development
Browse files Browse the repository at this point in the history
ArConnect BETA 1.23.1
  • Loading branch information
pawanpaudel93 authored Jan 9, 2025
2 parents 35f73de + af478a3 commit 6477fc4
Show file tree
Hide file tree
Showing 37 changed files with 311 additions and 2,879 deletions.
8 changes: 0 additions & 8 deletions assets/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,6 @@
"message": "Currency",
"description": "Select currency"
},
"setting_dre_node": {
"message": "Warp DRE node",
"description": "Warp DRE node setting title"
},
"setting_arverify": {
"message": "ArVerify treshold",
"description": "ArVerify settings title"
Expand Down Expand Up @@ -2006,10 +2002,6 @@
}
}
},
"setting_ao_support": {
"message": "ao support",
"description": "ao support settings title"
},
"setting_ao_support_description": {
"message": "Show ao tokens in your wallet (beta)",
"description": "ao support settings description"
Expand Down
8 changes: 0 additions & 8 deletions assets/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,6 @@
"message": "货币",
"description": "Select currency"
},
"setting_dre_node": {
"message": "Warp DRE 节点",
"description": "Warp DRE node setting title"
},
"setting_arverify": {
"message": "ArVerify 阈值",
"description": "ArVerify settings title"
Expand Down Expand Up @@ -1996,10 +1992,6 @@
}
}
},
"setting_ao_support": {
"message": "ao 支持",
"description": "ao support settings title"
},
"setting_ao_support_description": {
"message": "在您的钱包中显示 ao 代币(测试版)",
"description": "ao support settings description"
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"dependencies": {
"@arconnect/components": "^1.0.0",
"@arconnect/keystone-sdk": "^0.0.5",
"@arconnect/warp-dre": "^0.0.1",
"@arconnect/webext-bridge": "^5.0.6",
"@iconicicons/react": "^1.5.0",
"@keystonehq/arweave-keyring": "^0.1.1-alpha.0",
Expand Down Expand Up @@ -89,7 +88,6 @@
"styled-components": "^5.3.6",
"typed-assert": "^1.0.9",
"uuid": "^9.0.0",
"warp-contracts": "^1.2.13",
"webextension-polyfill": "^0.10.0",
"wouter": "^3.3.5"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const handleApiCallMessage: OnMessageCallback<
});

// update app value with the app belonging to the frame
if (frame.url) {
if (frame?.url) {
app = new Application(getAppURL(frame.url));
}
}
Expand Down
27 changes: 1 addition & 26 deletions src/api/modules/add_token/add_token.background.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,12 @@
import { isAddress, isTokenType, isValidURL } from "~utils/assertions";
import type { BackgroundModuleFunction } from "~api/background/background-modules";
import { requestUserAuthorization } from "../../../utils/auth/auth.utils";
import { getTokens } from "~tokens";

const background: BackgroundModuleFunction<void> = async (
appData,
id: unknown,
type?: unknown,
dre_node?: unknown
) => {
// validate input
isAddress(id);

if (type) isTokenType(type);
if (dre_node) isValidURL(dre_node);

// check if the token is added already
const tokens = await getTokens();

if (tokens.find((token) => token.id === id)) {
throw new Error("Token already added");
}

// request "add token" popup
await requestUserAuthorization(
{
type: "token",
tokenID: id,
tokenType: type,
dre: dre_node
},
appData
);
throw new Error("The addToken API is deprecated and removed.");
};

export default background;
3 changes: 1 addition & 2 deletions src/api/modules/dispatch/allowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import { freeDecryptedWallet } from "~wallets/encryption";
import type { AllowanceBigNumber } from "~applications/allowance";
import type { ModuleAppData } from "~api/background/background-modules";
import { defaultGateway } from "~gateways/gateway";
import type { JWKInterface } from "warp-contracts";
import { allowanceAuth } from "../sign/allowance";
import { signAuth } from "../sign/sign_auth";
import Arweave from "arweave";
import type { DataItem } from "arbundles";
import type Transaction from "arweave/web/lib/transaction";
import type BigNumber from "bignumber.js";
import type { JWKInterface } from "arweave/web/lib/wallet";

/**
* Ensure allowance for dispatch
Expand Down
11 changes: 1 addition & 10 deletions src/api/modules/is_token_added/is_token_added.background.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import type { BackgroundModuleFunction } from "~api/background/background-modules";
import { isAddressFormat } from "~utils/format";
import { getTokens } from "~tokens";
import { isAddress } from "~utils/assertions";

const background: BackgroundModuleFunction<boolean> = async (_, id: string) => {
// check id
isAddress(id);

// check if the token is added
const tokens = await getTokens();

return !!tokens.find((token) => token.id === id);
throw new Error("The isTokenAdded API is deprecated and removed.");
};

export default background;
94 changes: 18 additions & 76 deletions src/components/dashboard/Tokens.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { useStorage } from "@plasmohq/storage/hook";
import { ExtensionStorage } from "~utils/storage";
import { useRoute } from "wouter";
import { useEffect, useMemo, useState } from "react";
import type { Token, TokenType } from "~tokens/token";
import { useEffect, useMemo } from "react";
import type { TokenType } from "~tokens/token";
import { Reorder } from "framer-motion";
import TokenListItem from "./list/TokenListItem";
import styled from "styled-components";
import PermissionCheckbox from "~components/auth/PermissionCheckbox";
import browser from "webextension-polyfill";
import { ButtonV2, Label, Spacer, Text } from "@arconnect/components";
import { ButtonV2, Spacer } from "@arconnect/components";
import { type TokenInfoWithBalance } from "~tokens/aoTokens/ao";
import { useLocation } from "~wallets/router/router.utils";

Expand All @@ -18,13 +17,6 @@ export function TokensDashboardView() {
const [matches, params] = useRoute<{ id?: string }>("/tokens/:id?");

// tokens
const [tokens, setTokens] = useStorage<Token[]>(
{
key: "tokens",
instance: ExtensionStorage
},
[]
);
const [aoTokens] = useStorage<TokenInfoWithBalance[]>(
{
key: "ao_tokens",
Expand All @@ -44,23 +36,6 @@ export function TokensDashboardView() {
}));
}, [aoTokens]);

const [aoSettingsState, setaoSettingsState] = useState(true);

useEffect(() => {
(async () => {
const currentSetting = await ExtensionStorage.get<boolean>(
"setting_ao_support"
);
setaoSettingsState(currentSetting);
})();
}, []);

const toggleaoSettings = async () => {
const newSetting = !aoSettingsState;
setaoSettingsState(newSetting);
await ExtensionStorage.set("setting_ao_support", newSetting);
};

// active subsetting val
const activeTokenSetting = useMemo(
() => (params?.id ? params.id : undefined),
Expand All @@ -72,22 +47,18 @@ export function TokensDashboardView() {
return;
}

const firstToken = tokens?.[0];

const allTokens = [...tokens, ...enhancedAoTokens];

// return if there is a wallet present in params
if (
activeTokenSetting &&
allTokens.some((t) => t.id === activeTokenSetting)
enhancedAoTokens.some((t) => t.id === activeTokenSetting)
) {
return;
}

if (allTokens.length > 0) {
navigate(`/tokens/${allTokens[0].id}`);
if (enhancedAoTokens.length > 0) {
navigate(`/tokens/${enhancedAoTokens[0].id}`);
}
}, [tokens, enhancedAoTokens, activeTokenSetting, matches]);
}, [enhancedAoTokens, activeTokenSetting, matches]);

const addToken = () => {
navigate("/tokens/new");
Expand All @@ -106,51 +77,22 @@ export function TokensDashboardView() {

return (
<Wrapper>
<div>
<PermissionCheckbox
checked={aoSettingsState}
onChange={toggleaoSettings}
style={{ padding: "0 9.6px" }}
>
{browser.i18n.getMessage(!!aoSettingsState ? "enabled" : "disabled")}
<br />
<Text noMargin>
{browser.i18n.getMessage("setting_ao_support_description")}
</Text>
</PermissionCheckbox>
<Spacer y={1.7} />
<div style={{ overflowY: "auto" }}>
<Reorder.Group
as="div"
axis="y"
onReorder={setTokens}
values={tokens}
onReorder={() => {}}
values={aoTokens}
style={{ display: "flex", flexDirection: "column", gap: "0.4rem" }}
>
{enhancedAoTokens.length > 0 && aoSettingsState && (
<>
<Label style={{ paddingLeft: "4px", margin: "0" }}>
ao tokens
</Label>
{enhancedAoTokens.map((token) => (
<div onClick={() => handleTokenClick(token)} key={token.id}>
<TokenListItem
token={token}
ao={true}
active={activeTokenSetting === token.id}
key={token.id}
/>
</div>
))}
</>
)}
<Spacer y={1} />
<Label style={{ paddingLeft: "4px", margin: "0" }}>warp tokens</Label>
{tokens.map((token) => (
<TokenListItem
token={token}
active={activeTokenSetting === token.id}
key={token.id}
/>
{enhancedAoTokens.map((token) => (
<div onClick={() => handleTokenClick(token)} key={token.id}>
<TokenListItem
token={token}
active={activeTokenSetting === token.id}
key={token.id}
/>
</div>
))}
</Reorder.Group>
<Spacer y={1} />
Expand Down
56 changes: 14 additions & 42 deletions src/components/dashboard/list/TokenListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { DREContract, DRENode, NODES } from "@arconnect/warp-dre";
import { loadTokenLogo, type Token } from "~tokens/token";
import { type Token } from "~tokens/token";
import { Reorder, useDragControls } from "framer-motion";
import { useEffect, useMemo, useState } from "react";
import { ListItem } from "@arconnect/components";
import { formatAddress } from "~utils/format";
import { getDreForToken } from "~tokens";
import { useTheme } from "~utils/theme";
import * as viewblock from "~lib/viewblock";
import styled from "styled-components";
import { FULL_HISTORY, useGateway } from "~gateways/wayfinder";
import { concatGatewayURL } from "~gateways/utils";
Expand All @@ -15,7 +12,7 @@ import arLogoDark from "url:/assets/ar/logo_dark.png";
import { getUserAvatar } from "~lib/avatar";
import { useLocation } from "~wallets/router/router.utils";

export default function TokenListItem({ token, active, ao, onClick }: Props) {
export default function TokenListItem({ token, active, onClick }: Props) {
const { navigate } = useLocation();

// format address
Expand All @@ -31,7 +28,7 @@ export default function TokenListItem({ token, active, ao, onClick }: Props) {
const theme = useTheme();

// token logo
const [image, setImage] = useState(viewblock.getTokenLogo(token.id));
const [image, setImage] = useState(arLogoDark);

// gateway
const gateway = useGateway(FULL_HISTORY);
Expand All @@ -41,32 +38,20 @@ export default function TokenListItem({ token, active, ao, onClick }: Props) {
try {
// if it is a collectible, we don't need to determinate the logo
if (token.type === "collectible") {
return setImage(
`${concatGatewayURL(token.gateway || gateway)}/${token.id}`
);
return setImage(`${concatGatewayURL(gateway)}/${token.id}`);
}
if (ao) {
if (token.defaultLogo) {
const logo = await getUserAvatar(token.defaultLogo);
return setImage(logo);
} else {
return setImage(arLogoDark);
}
}

// query community logo using Warp DRE
const node = new DRENode(await getDreForToken(token.id));
const contract = new DREContract(token.id, node);
const result = await contract.query<[string]>(
"$.settings.[?(@[0] === 'communityLogo')][1]"
);

setImage(await loadTokenLogo(token.id, result[0], theme));
if (token.defaultLogo) {
const logo = await getUserAvatar(token.defaultLogo);
return setImage(logo);
} else {
return setImage(arLogoDark);
}
} catch {
setImage(viewblock.getTokenLogo(token.id));
setImage(arLogoDark);
}
})();
}, [token, theme, gateway, ao]);
}, [token, theme, gateway]);

const handleClick = () => {
if (onClick) {
Expand All @@ -90,12 +75,11 @@ export default function TokenListItem({ token, active, ao, onClick }: Props) {
description={
<DescriptionWrapper>
{formattedAddress}
{ao && <Image src={aoLogo} alt="ao logo" />}
{!ao && <TokenType>{token.type}</TokenType>}
<Image src={aoLogo} alt="ao logo" />
</DescriptionWrapper>
}
active={active}
dragControls={!ao ? dragControls : null}
dragControls={null}
>
<TokenLogo src={image} />
</ListItem>
Expand Down Expand Up @@ -128,18 +112,6 @@ const TokenLogo = styled.img.attrs({
transform: translate(-50%, -50%);
`;

const TokenType = styled.span`
padding: 0.08rem 0.2rem;
background-color: rgb(${(props) => props.theme.theme});
color: #fff;
font-weight: 500;
font-size: 0.62rem;
text-transform: uppercase;
margin-left: 0.45rem;
width: max-content;
border-radius: 5px;
`;

interface Props {
token: Token;
ao?: boolean;
Expand Down
Loading

0 comments on commit 6477fc4

Please sign in to comment.