Skip to content

Commit 5911725

Browse files
Merge pull request #1113 from wanderwallet/refactor/update-ario-logo
refactor: update ario logo
2 parents 6c18d8e + 2bef407 commit 5911725

File tree

4 files changed

+20
-58
lines changed

4 files changed

+20
-58
lines changed

src/api/background/handlers/alarms/ao-tokens-cache/ao-tokens-cache-alarm.handler.ts

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { dryrun } from "@permaweb/aoconnect";
21
import { PersistentStorage } from "~utils/storage";
32
import type { Alarms } from "webextension-polyfill";
4-
import { type TokenInfo, getTokenInfoFromData } from "~tokens/aoTokens/ao";
3+
import { type TokenInfo, getTokenInfo } from "~tokens/aoTokens/ao";
54
import { timeoutPromise } from "~utils/promises/timeout";
6-
import { AR_PROCESS_ID, Id, Owner } from "~tokens/aoTokens/ao.constants";
5+
import { AR_PROCESS_ID } from "~tokens/aoTokens/ao.constants";
76

87
/**
98
* Alarm handler for syncing ao tokens
@@ -18,29 +17,18 @@ export const handleAoTokenCacheAlarm = async (alarmInfo?: Alarms.Alarm) => {
1817
for (const token of aoTokens) {
1918
if (token.processId === AR_PROCESS_ID) continue;
2019
try {
21-
const res = await timeoutPromise(
22-
dryrun({
23-
Id,
24-
Owner,
25-
process: token.processId,
26-
tags: [{ name: "Action", value: "Info" }],
27-
}),
28-
6000,
29-
);
20+
const tokenInfo = await timeoutPromise(getTokenInfo(token.processId), 6000);
3021

31-
if (res.Messages && Array.isArray(res.Messages)) {
32-
const tokenInfo = getTokenInfoFromData(res, token.processId);
33-
const updatedToken = {
34-
...tokenInfo,
35-
lastUpdated: new Date().toISOString(),
36-
};
22+
const updatedToken = {
23+
...tokenInfo,
24+
lastUpdated: new Date().toISOString(),
25+
};
3726

38-
if (updatedToken) {
39-
const index = updatedTokens.findIndex((t) => t.processId === token.processId);
27+
if (updatedToken) {
28+
const index = updatedTokens.findIndex((t) => t.processId === token.processId);
4029

41-
if (index !== -1) {
42-
updatedTokens[index] = { ...updatedTokens[index], ...updatedToken };
43-
}
30+
if (index !== -1) {
31+
updatedTokens[index] = { ...updatedTokens[index], ...updatedToken };
4432
}
4533
}
4634
} catch (err) {

src/api/background/handlers/browser/install/install.handler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export async function handleInstall(details: Runtime.OnInstalledDetailsType) {
4949

5050
// initialize alarm to update tokens once a week
5151
browser.alarms.create("update_ao_tokens", {
52+
delayInMinutes: 1,
5253
periodInMinutes: 10080,
5354
});
5455

src/tokens/aoTokens/ao.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,23 @@ type DataItemResult = {
5454
const ao = connect(defaultConfig);
5555

5656
export const ARDRIVE_CU_URL = "https://cu.ardrive.io";
57-
export const AO_DEV_CU_URL = "https://aodev.fun/ao/cu";
5857
export const DEFAULT_CU_URL = "https://cu.ao-testnet.xyz";
5958

6059
const { dryrun: arDriveDryrun } = connect({ CU_URL: ARDRIVE_CU_URL });
61-
const { dryrun: aoDevDryrun } = connect({ CU_URL: AO_DEV_CU_URL });
6260

6361
const ARDRIVE_PROCESSES = [ARIO_MAINNET_PROCESS_ID, ARIO_TESTNET_PROCESS_ID];
6462

6563
export const getDryrunForProcess = (processId: string) => {
66-
if (processId === UTD_PROCESS_ID) return { dryrunFn: aoDevDryrun, isCustomDryrun: true };
6764
if (ARDRIVE_PROCESSES.includes(processId)) return { dryrunFn: arDriveDryrun, isCustomDryrun: true };
6865

6966
return { dryrunFn: dryrun, isCustomDryrun: false };
7067
};
7168

69+
export const getCuUrlForProcess = (processId: string) => {
70+
if (ARDRIVE_PROCESSES.includes(processId)) return ARDRIVE_CU_URL;
71+
return DEFAULT_CU_URL;
72+
};
73+
7274
export function getTokenInfoFromData(res: any, id: string): TokenInfo {
7375
// find message with token info
7476
for (const msg of res.Messages as Message[]) {
@@ -102,7 +104,7 @@ export function getTokenInfoFromData(res: any, id: string): TokenInfo {
102104
const Logo = getTagValue("Logo", msg.Tags);
103105
const Transferable = getTagValue("Transferable", msg.Tags);
104106

105-
if (!Ticker && !Name) continue;
107+
if (!Ticker || !Name) continue;
106108

107109
return {
108110
processId: id,
@@ -135,7 +137,7 @@ export async function getTokenInfo(id: string): Promise<TokenInfo> {
135137
return { ...data.tokenInfo, processId: id };
136138
} catch {
137139
// query ao
138-
const dryrunFn = id === UTD_PROCESS_ID ? aoDevDryrun : dryrun;
140+
const { dryrunFn } = getDryrunForProcess(id);
139141
const res = await dryrunFn({
140142
Id,
141143
Owner,

src/tokens/aoTokens/sync.ts

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import { getAoTokensCache } from "~tokens";
44
import type { GQLTransactionsResultInterface } from "ar-gql/dist/faces";
55
import { PersistentStorage } from "~utils/storage";
66
import { getActiveAddress } from "~wallets";
7-
import { type TokenInfo, getTokenInfoFromData, DEFAULT_CU_URL, AO_DEV_CU_URL } from "./ao";
7+
import { getTokenInfo, type TokenInfo } from "./ao";
88
import { withRetry } from "~utils/promises/retry";
99
import { timeoutPromise } from "~utils/promises/timeout";
1010
import { Mutex } from "~utils/mutex";
11-
import { Id, Owner, UTD_PROCESS_ID } from "~tokens/aoTokens/ao.constants";
1211

1312
/** Tokens storage name */
1413
export const AO_TOKENS = "ao_tokens";
@@ -35,34 +34,6 @@ export const gateway = {
3534
protocol: "https",
3635
};
3736

38-
async function getTokenInfo(id: string): Promise<TokenInfo> {
39-
const body = {
40-
Id,
41-
Target: id,
42-
Owner,
43-
Anchor: "0",
44-
Data: "1234",
45-
Tags: [
46-
{ name: "Action", value: "Info" },
47-
{ name: "Data-Protocol", value: "ao" },
48-
{ name: "Type", value: "Message" },
49-
{ name: "Variant", value: "ao.TN.1" },
50-
],
51-
};
52-
const cuUrl = id === UTD_PROCESS_ID ? AO_DEV_CU_URL : DEFAULT_CU_URL;
53-
const res = await (
54-
await fetch(`${cuUrl}/dry-run?process-id=${id}`, {
55-
headers: {
56-
"content-type": "application/json",
57-
},
58-
body: JSON.stringify(body),
59-
method: "POST",
60-
})
61-
).json();
62-
63-
return getTokenInfoFromData(res, id);
64-
}
65-
6637
// Get transactions for AO token discovery
6738
function getNoticeTransactionsQuery(address: string, filterProcesses: string[], minBlockHeight?: number) {
6839
const effectiveMinHeight = minBlockHeight || 1;

0 commit comments

Comments
 (0)