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

fix: removed token mirror #656

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/api/modules/token_balance/token_balance.background.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import type { BackgroundModuleFunction } from "~api/background/background-modules";
import { ExtensionStorage } from "~utils/storage";
import { getAoTokenBalance, getNativeTokenBalance } from "~tokens/aoTokens/ao";
import { AO_NATIVE_TOKEN } from "~utils/ao_import";
import { getAoTokenBalance } from "~tokens/aoTokens/ao";
import { isAddress } from "~utils/assertions";

const background: BackgroundModuleFunction<string> = async (_, id?: string) => {
// validate input
isAddress(id);
const address = await ExtensionStorage.get("active_address");

const balance =
id === AO_NATIVE_TOKEN
? await getNativeTokenBalance(address)
: (await getAoTokenBalance(address, id)).toString();
const balance = (await getAoTokenBalance(address, id)).toString();

return balance;
};
Expand Down
13 changes: 2 additions & 11 deletions src/api/modules/user_tokens/user_tokens.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import type { BackgroundModuleFunction } from "~api/background/background-module
import { ExtensionStorage } from "~utils/storage";
import {
getAoTokenBalance,
getNativeTokenBalance,
type TokenInfo,
type TokenInfoWithBalance
} from "~tokens/aoTokens/ao";
import { AO_NATIVE_TOKEN } from "~utils/ao_import";

const background: BackgroundModuleFunction<
TokenInfoWithBalance[] | TokenInfo[]
Expand All @@ -25,15 +23,8 @@ const background: BackgroundModuleFunction<
let balance: string | null = null;

try {
if (token.processId === AO_NATIVE_TOKEN) {
balance = await getNativeTokenBalance(address);
} else {
const balanceResult = await getAoTokenBalance(
address,
token.processId
);
balance = balanceResult.toString();
}
const balanceResult = await getAoTokenBalance(address, token.processId);
balance = balanceResult.toString();
} catch (error) {
console.error(
`Error fetching balance for token ${token.Name} (${token.processId}):`,
Expand Down
4 changes: 1 addition & 3 deletions src/tokens/aoTokens/ao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,7 @@ export async function fetchTokenBalance(
refresh?: boolean
): Promise<string> {
try {
if (token.processId === AO_NATIVE_TOKEN) {
return (await getNativeTokenBalance(address)).toString();
} else if (token.processId === "AR") {
if (token.processId === "AR") {
return await getArTokenBalance(address);
} else {
if (refresh) token = await getTokenInfo(token.processId);
Expand Down