Skip to content

Commit dece1c4

Browse files
Merge pull request #1004 from lfglabs-dev/feat/add-braavos-mobile
feat: add braavos mobile
2 parents 3f81544 + efe262d commit dece1c4

File tree

11 files changed

+235
-58
lines changed

11 files changed

+235
-58
lines changed

app/analytics/page.tsx

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ export default function Page() {
1717
const { address } = useAccount();
1818
const [loading, setLoading] = useState<boolean>(true);
1919

20-
const [quests, setQuests] = useState<QuestList> ({} as QuestList);
20+
const [quests, setQuests] = useState<QuestList>({} as QuestList);
2121

2222
const fetchQuests = useCallback(async () => {
2323
try {
2424
setLoading(true);
25-
const res = await getQuests() || {};
25+
const res = (await getQuests()) || {};
2626
setQuests(res);
2727
setLoading(false);
2828
} catch (error) {
@@ -39,34 +39,42 @@ export default function Page() {
3939
<div className={styles.backButton}>
4040
<BackButton onClick={() => router.back()} />
4141
</div>
42-
<Typography type={TEXT_TYPE.H1} color="transparent" className={styles.title}>Quest Analytics</Typography>
42+
<Typography
43+
type={TEXT_TYPE.H1}
44+
color="transparent"
45+
className={styles.title}
46+
>
47+
Quest Analytics
48+
</Typography>
4349
<div className={styles.card_container}>
4450
{loading ? (
4551
<FeaturedQuestSkeleton />
4652
) : (
47-
(Object.keys(quests) as (keyof typeof quests)[]).map((categoryName: keyof typeof quests) => {
48-
const categoryValue = quests[categoryName];
49-
if (Array.isArray(categoryValue)) {
50-
return categoryValue.map((quest: QuestDocument) => {
51-
return (
52-
<Quest
53-
key={quest.id}
54-
title={quest.title_card}
55-
onClick={() => router.push(`/analytics/${quest.id}`)}
56-
imgSrc={quest.img_card}
57-
issuer={{
58-
name: quest.issuer,
59-
logoFavicon: quest.logo,
60-
}}
61-
reward={quest.rewards_title}
62-
id={quest.id}
63-
expired={false}
64-
/>
65-
);
66-
});
53+
(Object.keys(quests) as (keyof typeof quests)[]).map(
54+
(categoryName: keyof typeof quests) => {
55+
const categoryValue = quests[categoryName];
56+
if (Array.isArray(categoryValue)) {
57+
return categoryValue.map((quest: QuestDocument) => {
58+
return (
59+
<Quest
60+
key={quest.id}
61+
title={quest.title_card}
62+
onClick={() => router.push(`/analytics/${quest.id}`)}
63+
imgSrc={quest.img_card}
64+
issuer={{
65+
name: quest.issuer,
66+
logoFavicon: quest.logo,
67+
}}
68+
reward={quest.rewards_title}
69+
id={quest.id}
70+
expired={false}
71+
/>
72+
);
73+
});
74+
}
75+
return null;
6776
}
68-
return null;
69-
})
77+
)
7078
)}
7179
</div>
7280
</div>

app/provider.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
"use client";
22

33
import React from "react";
4-
import { InjectedConnector } from "starknetkit/injected";
5-
import { WebWalletConnector } from "starknetkit/webwallet";
6-
import { ArgentMobileConnector } from "starknetkit/argentMobile";
74
import { Chain, mainnet, sepolia } from "@starknet-react/chains";
85
import {
96
Connector,
107
StarknetConfig,
118
jsonRpcProvider,
129
} from "@starknet-react/core";
1310
import { StarknetIdJsProvider } from "@context/StarknetIdJsProvider";
14-
import { ThemeProvider, createTheme } from "@mui/material";
11+
import { ThemeProvider } from "@mui/material";
1512
import { QuestsContextProvider } from "@context/QuestsProvider";
1613
import { getCurrentNetwork } from "@utils/network";
17-
import { constants } from "starknet";
1814
import { PostHogProvider } from "posthog-js/react";
1915
import posthog from "posthog-js";
2016
import { NotificationProvider } from "@context/NotificationProvider";

context/QuestsProvider.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ export const QuestsContextProvider = ({
138138
!quest.expired
139139
)
140140
: undefined;
141-
142141
setFeaturedQuest(
143142
lastBoostedQuest ||
144143
notExpired[Math.floor(Math.random() * notExpired.length)]

jest.config.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
module.exports = {
33
testEnvironment: "node",
44
transform: {
5-
"\\.[jt]sx?$": "ts-jest",
5+
"^.+\\.(js|jsx|ts|tsx)$": ["babel-jest", { presets: ["next/babel"] }],
66
},
77
setupFilesAfterEnv: ["./jest.setup.js"],
88
moduleNameMapper: {
@@ -16,9 +16,10 @@ module.exports = {
1616
coverageThreshold: {
1717
"./utils/": {
1818
branches: 75,
19-
functions: 90,
19+
functions: 80,
2020
lines: 90,
21-
statements: -10,
21+
statements: -23,
2222
},
2323
},
24-
};
24+
transformIgnorePatterns: ["node_modules/(?!(@starknet-react|@starknetkit)/)"],
25+
};

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"chart.js": "^4.3.0",
3131
"dayjs": "^1.11.11",
3232
"eslint-config-next": "^14.0.1",
33-
"get-starknet-core": "^3.2.0",
33+
"get-starknet": "^3.3.3",
34+
"get-starknet-core": "^3.3.3",
3435
"jotai": "^2.5.0",
3536
"jwt-decode": "^4.0.0",
3637
"lottie-react": "^2.4.0",
@@ -51,7 +52,7 @@
5152
"recharts": "^2.12.2",
5253
"starknet": "^6.11.0",
5354
"starknetid.js": "^4.0.1",
54-
"starknetkit": "^2.3.3",
55+
"starknetkit": "^2.6.1",
5556
"three": "^0.155.0",
5657
"twitter-api-sdk": "^1.2.1"
5758
},

public/visuals/braavosMobile.webp

9.8 KB
Loading

tests/utils/braavosMobile.test.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { mainnet, sepolia } from "@starknet-react/chains";
2+
import {
3+
ConnectorNotConnectedError,
4+
UserNotConnectedError,
5+
} from "@starknet-react/core";
6+
import { BraavosMobileConnector, getBraavosMobile } from "@utils/braavosMobile";
7+
8+
describe("BraavosMobileConnector class", () => {
9+
let connector;
10+
11+
beforeEach(() => {
12+
connector = new BraavosMobileConnector();
13+
});
14+
15+
describe("id getter", () => {
16+
it("should return 'braavosMobile'", () => {
17+
expect(connector.id).toBe("braavosMobile");
18+
});
19+
});
20+
21+
describe("icon getter", () => {
22+
it("should return the same icon for light and dark modes", () => {
23+
expect(connector.icon.light).toBeDefined();
24+
expect(connector.icon.dark).toBeDefined();
25+
expect(connector.icon.light).toBe(connector.icon.dark);
26+
});
27+
});
28+
29+
describe("name getter", () => {
30+
it("should return 'Braavos (mobile)'", () => {
31+
expect(connector.name).toBe("Braavos (mobile)");
32+
});
33+
});
34+
35+
describe("available method", () => {
36+
it("should return true", () => {
37+
expect(connector.available()).toBe(true);
38+
});
39+
});
40+
41+
describe("wallet getter", () => {
42+
it("should throw a ConnectorNotConnectedError", () => {
43+
expect(() => connector.wallet).toThrow(ConnectorNotConnectedError);
44+
});
45+
});
46+
47+
describe("disconnect method", () => {
48+
it("should throw a UserNotConnectedError", () => {
49+
expect(() => connector.disconnect()).toThrow(UserNotConnectedError);
50+
});
51+
});
52+
53+
describe("account method", () => {
54+
it("should throw a ConnectorNotConnectedError", () => {
55+
expect(() => connector.account()).toThrow(ConnectorNotConnectedError);
56+
});
57+
});
58+
59+
describe("chainId method", () => {
60+
it("should return sepolia.id when NEXT_PUBLIC_IS_TESTNET is 'true'", async () => {
61+
process.env.NEXT_PUBLIC_IS_TESTNET = "true";
62+
const result = await connector.chainId();
63+
expect(result).toBe(sepolia.id);
64+
});
65+
66+
it("should return mainnet.id when NEXT_PUBLIC_IS_TESTNET is not 'true'", async () => {
67+
process.env.NEXT_PUBLIC_IS_TESTNET = "false";
68+
const result = await connector.chainId();
69+
expect(result).toBe(mainnet.id);
70+
});
71+
});
72+
73+
describe("ready method", () => {
74+
it("should return true as a Promise", async () => {
75+
const result = await connector.ready();
76+
expect(result).toBe(true);
77+
});
78+
});
79+
});
80+
81+
describe("getBraavosMobile function", () => {
82+
it("should return an instance of BraavosMobileConnector", () => {
83+
const instance = getBraavosMobile();
84+
expect(instance).toBeInstanceOf(BraavosMobileConnector);
85+
});
86+
});

tests/utils/domainService.test.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
import { getDomainFromAddress } from '@utils/domainService';
1+
import { getDomainFromAddress } from "@utils/domainService";
22

33
const API_URL = process.env.NEXT_PUBLIC_STARKNET_ID_API_LINK;
44

55
describe("getDomainFromAddress function", () => {
6-
it("should return a valid domain for a valid address", async () => {
7-
const validAddress = "0x061b6c0a78f9edf13cea17b50719f3344533fadd470b8cb29c2b4318014f52d3";
6+
it("should return a valid domain for a valid address", async () => {
7+
const validAddress =
8+
"0x061b6c0a78f9edf13cea17b50719f3344533fadd470b8cb29c2b4318014f52d3";
89
const expectedDomain = "fricoben.stark";
910

1011
// Mocking the fetch function to return a predefined response
1112
const mockResponse = { domain: expectedDomain };
1213
const fetchMock = jest.fn().mockResolvedValue({
13-
json: jest.fn().mockResolvedValue(mockResponse),
14+
json: jest.fn().mockResolvedValue(mockResponse),
1415
});
15-
(fetch as jest.Mock) = fetchMock;
16+
fetch = fetchMock;
1617

1718
const domain = await getDomainFromAddress(validAddress);
1819

1920
expect(domain).toBe(expectedDomain);
20-
expect(fetchMock).toHaveBeenCalledWith(`${API_URL}/addr_to_domain?addr=${validAddress}`);
21+
expect(fetchMock).toHaveBeenCalledWith(
22+
`${API_URL}/addr_to_domain?addr=${validAddress}`
23+
);
2124
});
2225

2326
it("should return an empty string for an invalid address", async () => {
@@ -27,13 +30,15 @@ it("should return a valid domain for a valid address", async () => {
2730
// Mocking the fetch function to simulate an error
2831
const mockResponse = { domain: expectedDomain };
2932
const fetchMock = jest.fn().mockResolvedValue({
30-
json: jest.fn().mockResolvedValue(mockResponse),
31-
});
32-
(fetch as jest.Mock) = fetchMock;
33+
json: jest.fn().mockResolvedValue(mockResponse),
34+
});
35+
fetch = fetchMock;
3336

3437
const domain = await getDomainFromAddress(invalidAddress);
3538

3639
expect(domain).toBe("");
37-
expect(fetchMock).toHaveBeenCalledWith(`${API_URL}/addr_to_domain?addr=${invalidAddress}`);
40+
expect(fetchMock).toHaveBeenCalledWith(
41+
`${API_URL}/addr_to_domain?addr=${invalidAddress}`
42+
);
3843
});
39-
});
44+
});

0 commit comments

Comments
 (0)