Skip to content

Commit

Permalink
fix: resolve issue with token setting & remove ao support check
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanpaudel93 committed Jan 7, 2025
1 parent c79ea1c commit 2d82f89
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 55 deletions.
4 changes: 0 additions & 4 deletions assets/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2002,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
4 changes: 0 additions & 4 deletions assets/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1992,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
4 changes: 2 additions & 2 deletions src/components/dashboard/Tokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function TokensDashboardView() {
const [matches, params] = useRoute<{ id?: string }>("/tokens/:id?");

// tokens
const [aoTokens, setAoTokens] = useStorage<TokenInfoWithBalance[]>(
const [aoTokens] = useStorage<TokenInfoWithBalance[]>(
{
key: "ao_tokens",
instance: ExtensionStorage
Expand Down Expand Up @@ -81,7 +81,7 @@ export function TokensDashboardView() {
<Reorder.Group
as="div"
axis="y"
onReorder={setAoTokens}
onReorder={() => {}}
values={aoTokens}
style={{ display: "flex", flexDirection: "column", gap: "0.4rem" }}
>
Expand Down
5 changes: 4 additions & 1 deletion src/components/dashboard/subsettings/TokenSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ export function TokenSettingsDashboardView({

const [loading, setLoading] = useState(false);

console.log({ aoTokens });

const token = useMemo(() => {
const aoToken = aoTokens.find((ao) => ao.processId === id);
if (!aoToken) return;

return {
...aoToken,
Expand All @@ -61,7 +64,7 @@ export function TokenSettingsDashboardView({
// update token type
function updateType(type: TokenType) {
setAoTokens((allTokens) => {
const tokenIndex = allTokens.findIndex((t) => t.id === id);
const tokenIndex = allTokens.findIndex((t) => t.processId === id);
if (tokenIndex !== -1) {
allTokens[tokenIndex].type = type;
}
Expand Down
1 change: 1 addition & 0 deletions src/routes/popup/settings/tokens/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function TokenSettingsView({ params: { id } }: TokenSettingsProps) {

const token = useMemo(() => {
const aoToken = aoTokens.find((ao) => ao.processId === id);
if (!aoToken) return;

return {
...aoToken,
Expand Down
18 changes: 3 additions & 15 deletions src/routes/popup/tokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
} from "~tokens/aoTokens/ao";
import { ExtensionStorage } from "~utils/storage";
import { syncAoTokens } from "~tokens/aoTokens/sync";
import { useStorage } from "@plasmohq/storage/hook";

export function TokensView() {
const { navigate } = useLocation();
Expand All @@ -32,14 +31,6 @@ export function TokensView() {

const { setToast } = useToasts();

const [aoSupport] = useStorage<boolean>(
{
key: "setting_ao_support",
instance: ExtensionStorage
},
false
);

function handleTokenClick(tokenId: string) {
navigate(`/send/transfer/${tokenId}`);
}
Expand Down Expand Up @@ -112,7 +103,6 @@ export function TokensView() {
};

async function searchAoTokens() {
if (!aoSupport) return;
try {
setIsLoading(true);
const { hasNextPage } = await syncAoTokens();
Expand All @@ -123,10 +113,8 @@ export function TokensView() {
}

useEffect(() => {
if (aoSupport) {
searchAoTokens();
}
}, [aoSupport]);
searchAoTokens();
}, []);

return (
<>
Expand Down Expand Up @@ -171,7 +159,7 @@ export function TokensView() {
/>
))}

{aoSupport && hasNextPage && (
{hasNextPage && (
<ButtonV2
disabled={isLoading}
style={{ alignSelf: "center", marginTop: "5px" }}
Expand Down
27 changes: 6 additions & 21 deletions src/tokens/aoTokens/ao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ export function useAoTokens({
instance: ExtensionStorage
});

const [aoSetting] = useStorage<boolean>({
key: "setting_ao_support",
instance: ExtensionStorage
});

const [aoTokens] = useStorage<TokenInfo[]>(
{
key: "ao_tokens",
Expand All @@ -129,11 +124,6 @@ export function useAoTokens({
useEffect(() => {
(async () => {
try {
if (!aoSetting) {
setTokens([]);
return;
}

setTokens(
aoTokens
.filter((t) => {
Expand All @@ -154,11 +144,11 @@ export function useAoTokens({
);
} catch {}
})();
}, [aoTokens, aoSetting]);
}, [aoTokens]);

useEffect(() => {
(async () => {
if (!activeAddress || !aoSetting) {
if (!activeAddress) {
setBalances([]);
return;
}
Expand Down Expand Up @@ -230,7 +220,7 @@ export function useAoTokens({
setLoading(false);
}
})();
}, [tokens, activeAddress, aoSetting]);
}, [tokens, activeAddress]);
return [tokensWithBalances, loading];
}

Expand Down Expand Up @@ -324,11 +314,6 @@ export function useAoTokensCache(): [TokenInfoWithBalance[], boolean] {
instance: ExtensionStorage
});

const [aoSetting] = useStorage<boolean>({
key: "setting_ao_support",
instance: ExtensionStorage
});

const [aoTokens] = useStorage<TokenInfoWithProcessId[]>(
{
key: "ao_tokens",
Expand All @@ -348,7 +333,7 @@ export function useAoTokensCache(): [TokenInfoWithBalance[], boolean] {
);

const aoTokensToAdd = useMemo(() => {
if (!activeAddress || aoTokensCache.length === 0 || !aoSetting) {
if (!activeAddress || aoTokensCache.length === 0) {
return [];
}

Expand Down Expand Up @@ -381,7 +366,7 @@ export function useAoTokensCache(): [TokenInfoWithBalance[], boolean] {

useEffect(() => {
(async () => {
if (!activeAddress || !aoSetting) {
if (!activeAddress) {
return setBalances([]);
}

Expand Down Expand Up @@ -413,7 +398,7 @@ export function useAoTokensCache(): [TokenInfoWithBalance[], boolean] {
setLoading(false);
}
})();
}, [aoTokensToAdd, activeAddress, aoSetting]);
}, [aoTokensToAdd, activeAddress]);

return [tokensWithBalances, loading];
}
Expand Down
10 changes: 2 additions & 8 deletions src/tokens/aoTokens/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,9 @@ export async function syncAoTokens() {
isSyncInProgress = true;

try {
const [activeAddress, aoSupport] = await Promise.all([
getActiveAddress(),
ExtensionStorage.get<boolean>("setting_ao_support")
]);
const activeAddress = await getActiveAddress();

if (!activeAddress || !aoSupport) {
if (!activeAddress) {
lastHasNextPage = false;
return { hasNextPage: false, syncCount: 0 };
}
Expand Down Expand Up @@ -354,9 +351,6 @@ export async function scheduleImportAoTokens() {
const activeAddress = await getActiveAddress();
if (!activeAddress) return;

const aoSupport = await ExtensionStorage.get<boolean>("setting_ao_support");
if (!aoSupport) return;

await ExtensionStorage.set(AO_TOKENS_IMPORT_TIMESTAMP, Date.now());

browser.alarms.create("import_ao_tokens", { when: Date.now() + 2000 });
Expand Down

0 comments on commit 2d82f89

Please sign in to comment.