@mezo-org/passport 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/api/portal.d.ts +0 -6
- package/dist/src/api/portal.d.ts.map +1 -1
- package/dist/src/api/portal.js +0 -6
- package/dist/src/api/portal.js.map +1 -1
- package/dist/src/api/rewards.d.ts +1 -1
- package/dist/src/api/rewards.d.ts.map +1 -1
- package/dist/src/api/rewards.js.map +1 -1
- package/dist/src/hooks/useGetCurrentAccount.d.ts +2 -4
- package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -1
- package/dist/src/hooks/useGetCurrentAccount.js +25 -31
- package/dist/src/hooks/useGetCurrentAccount.js.map +1 -1
- package/dist/src/provider.d.ts +1 -5
- package/dist/src/provider.d.ts.map +1 -1
- package/dist/src/provider.js +1 -2
- package/dist/src/provider.js.map +1 -1
- package/package.json +1 -1
- package/src/api/portal.ts +0 -17
- package/src/api/rewards.ts +4 -1
- package/src/hooks/useGetCurrentAccount.ts +31 -54
- package/src/provider.ts +0 -6
package/dist/src/api/portal.d.ts
CHANGED
|
@@ -5,11 +5,6 @@ type PortalStatistics = {
|
|
|
5
5
|
tTokenPrice: number;
|
|
6
6
|
usersCount: number;
|
|
7
7
|
};
|
|
8
|
-
export type PortalMats = {
|
|
9
|
-
totalMats: number;
|
|
10
|
-
inactiveMats: number;
|
|
11
|
-
matsActivated: boolean;
|
|
12
|
-
};
|
|
13
8
|
export declare const PORTAL_API_ENDPOINTS_BY_ENV: {
|
|
14
9
|
mainnet: string;
|
|
15
10
|
testnet: string;
|
|
@@ -17,7 +12,6 @@ export declare const PORTAL_API_ENDPOINTS_BY_ENV: {
|
|
|
17
12
|
export declare class PortalApiClient extends ApiClient {
|
|
18
13
|
constructor(environment?: keyof typeof PORTAL_API_ENDPOINTS_BY_ENV, apiUrl?: string);
|
|
19
14
|
getPortalStatistics(): Promise<PortalStatistics>;
|
|
20
|
-
getPortalMats(address: string): Promise<PortalMats>;
|
|
21
15
|
}
|
|
22
16
|
export {};
|
|
23
17
|
//# sourceMappingURL=portal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portal.d.ts","sourceRoot":"","sources":["../../../src/api/portal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEpC,KAAK,gBAAgB,GAAG;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,
|
|
1
|
+
{"version":3,"file":"portal.d.ts","sourceRoot":"","sources":["../../../src/api/portal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEpC,KAAK,gBAAgB,GAAG;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,2BAA2B;;;CAGvC,CAAA;AAED,qBAAa,eAAgB,SAAQ,SAAS;gBAE1C,WAAW,GAAE,MAAM,OAAO,2BAAuC,EACjE,MAAM,CAAC,EAAE,MAAM;IAQX,mBAAmB;CAO1B"}
|
package/dist/src/api/portal.js
CHANGED
|
@@ -16,11 +16,5 @@ export class PortalApiClient extends ApiClient {
|
|
|
16
16
|
});
|
|
17
17
|
return data;
|
|
18
18
|
}
|
|
19
|
-
async getPortalMats(address) {
|
|
20
|
-
const data = await this.handleRequest(`/v2/account/${address}/mats`, {
|
|
21
|
-
method: "GET",
|
|
22
|
-
});
|
|
23
|
-
return data;
|
|
24
|
-
}
|
|
25
19
|
}
|
|
26
20
|
//# sourceMappingURL=portal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portal.js","sourceRoot":"","sources":["../../../src/api/portal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"portal.js","sourceRoot":"","sources":["../../../src/api/portal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AASpC,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,OAAO,EAAE,2BAA2B;IACpC,OAAO,EAAE,gCAAgC;CAC1C,CAAA;AAED,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,YACE,cAAwD,SAAS,EACjE,MAAe;QAEf,KAAK,CAAC;YACJ,MAAM,EAAE,MAAM,IAAI,2BAA2B,CAAC,WAAW,CAAC;YAC1D,gBAAgB,EAAE,IAAI;SACvB,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,mBAAmB;QACvB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,aAAa,CAAmB,gBAAgB,EAAE;YACxE,MAAM,EAAE,KAAK;SACd,CAAC,CAAA;QAEF,OAAO,IAAI,CAAA;IACb,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rewards.d.ts","sourceRoot":"","sources":["../../../src/api/rewards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEpC,KAAK,QAAQ,GAAG;
|
|
1
|
+
{"version":3,"file":"rewards.d.ts","sourceRoot":"","sources":["../../../src/api/rewards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEpC,KAAK,QAAQ,GAAG;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CACpB,CAAA;AAED,KAAK,mBAAmB,GAAG;IACzB,IAAI,EAAE;QAAE,IAAI,EAAE;YAAE,SAAS,EAAE,QAAQ,CAAC;YAAC,SAAS,EAAE,QAAQ,CAAA;SAAE,CAAA;KAAE,CAAA;CAC7D,CAAA;AAED,MAAM,MAAM,WAAW,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAA;AAE7D,eAAO,MAAM,4BAA4B;;;CAGxC,CAAA;AAED,qBAAa,gBAAiB,SAAQ,SAAS;gBAE3C,WAAW,GAAE,MAAM,OAAO,4BAAwC,EAClE,MAAM,CAAC,EAAE,MAAM;IAQX,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CAY5D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rewards.js","sourceRoot":"","sources":["../../../src/api/rewards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"rewards.js","sourceRoot":"","sources":["../../../src/api/rewards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAapC,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC1C,OAAO,EAAE,+BAA+B;IACxC,OAAO,EAAE,oCAAoC;CAC9C,CAAA;AAED,MAAM,OAAO,gBAAiB,SAAQ,SAAS;IAC7C,YACE,cAAyD,SAAS,EAClE,MAAe;QAEf,KAAK,CAAC;YACJ,MAAM,EAAE,MAAM,IAAI,4BAA4B,CAAC,WAAW,CAAC;YAC3D,gBAAgB,EAAE,IAAI;SACvB,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAAe;QAClC,MAAM,EACJ,IAAI,EAAE,EAAE,IAAI,EAAE,GACf,GAAG,MAAM,IAAI,CAAC,aAAa,CAC1B,aAAa,OAAO,CAAC,WAAW,EAAE,EAAE,EACpC;YACE,MAAM,EAAE,KAAK;SACd,CACF,CAAA;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { QueryKey, UseQueryOptions, UseQueryResult } from "@tanstack/react-query";
|
|
2
|
-
import type { GetCurrentAccountResponse,
|
|
2
|
+
import type { GetCurrentAccountResponse, RewardsMats } from "../api";
|
|
3
3
|
type GetCurrentAccountResponseWithMats = GetCurrentAccountResponse & {
|
|
4
|
-
mats:
|
|
4
|
+
mats: RewardsMats[];
|
|
5
5
|
totalMats: number;
|
|
6
6
|
};
|
|
7
|
-
export declare const isRewardsMats: (value: unknown) => value is RewardsMats;
|
|
8
|
-
export declare const isPortalMats: (value: unknown) => value is PortalMats;
|
|
9
7
|
type UseGetCurrentAccountOptions<TSelected> = Omit<UseQueryOptions<GetCurrentAccountResponseWithMats, Error, TSelected>, "queryKey" | "queryFn">;
|
|
10
8
|
/**
|
|
11
9
|
* Hook to fetch current account with mats
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetCurrentAccount.d.ts","sourceRoot":"","sources":["../../../src/hooks/useGetCurrentAccount.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useGetCurrentAccount.d.ts","sourceRoot":"","sources":["../../../src/hooks/useGetCurrentAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAER,eAAe,EACf,cAAc,EACf,MAAM,uBAAuB,CAAA;AAI9B,OAAO,KAAK,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAGpE,KAAK,iCAAiC,GAAG,yBAAyB,GAAG;IACnE,IAAI,EAAE,WAAW,EAAE,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,KAAK,2BAA2B,CAAC,SAAS,IAAI,IAAI,CAChD,eAAe,CAAC,iCAAiC,EAAE,KAAK,EAAE,SAAS,CAAC,EACpE,UAAU,GAAG,SAAS,CACvB,CAAA;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,GAAG,iCAAiC,EAE7C,OAAO,GAAE,2BAA2B,CAAC,SAAS,CAAM,GACnD,cAAc,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAgE3D"}
|
|
@@ -1,28 +1,13 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
2
1
|
import { useQuery, } from "@tanstack/react-query";
|
|
3
2
|
import { ONE_MINUTE_MS } from "../utils/time";
|
|
4
3
|
import { QUERY_KEYS } from "./constants";
|
|
5
4
|
import { useAuthApiClient } from "./useAuthApiClient";
|
|
6
|
-
import { usePortalApiClient } from "./usePortalApiClient";
|
|
7
5
|
import { useRewardsApiClient } from "./useRewardsApiClient";
|
|
8
|
-
import { PassportContext } from "../provider";
|
|
9
|
-
export const isRewardsMats = (value) => !!value &&
|
|
10
|
-
typeof value === "object" &&
|
|
11
|
-
["seasonOne", "seasonTwo"].every((seasonKey) => !!value[seasonKey] &&
|
|
12
|
-
typeof value[seasonKey] === "object" &&
|
|
13
|
-
["mats", "rank"].every((fieldKey) => typeof value[seasonKey][fieldKey] === "number"));
|
|
14
|
-
export const isPortalMats = (value) => !!value &&
|
|
15
|
-
typeof value === "object" &&
|
|
16
|
-
["totalMats", "inactiveMats", "matsActivated"].every((fieldKey) => fieldKey === "matsActivated"
|
|
17
|
-
? typeof value[fieldKey] === "boolean"
|
|
18
|
-
: typeof value[fieldKey] === "number");
|
|
19
6
|
/**
|
|
20
7
|
* Hook to fetch current account with mats
|
|
21
8
|
*/
|
|
22
9
|
export function useGetCurrentAccount(options = {}) {
|
|
23
|
-
const passportContext = useContext(PassportContext);
|
|
24
10
|
const authApiClient = useAuthApiClient();
|
|
25
|
-
const portalApiClient = usePortalApiClient();
|
|
26
11
|
const rewardsApiClient = useRewardsApiClient();
|
|
27
12
|
const queryKey = [QUERY_KEYS.ACCOUNT, QUERY_KEYS.CURRENT];
|
|
28
13
|
const query = useQuery({
|
|
@@ -36,22 +21,31 @@ export function useGetCurrentAccount(options = {}) {
|
|
|
36
21
|
if (!linkedWallets || linkedWallets.length === 0) {
|
|
37
22
|
throw new Error("No linked wallets found for the current account");
|
|
38
23
|
}
|
|
39
|
-
const addresses = linkedWallets.map((account) =>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
24
|
+
const addresses = linkedWallets.map((account) => account.evmAddress);
|
|
25
|
+
try {
|
|
26
|
+
/** Mats balances aggregated from all linked wallets */
|
|
27
|
+
const mats = await Promise.all(addresses.map((address) => rewardsApiClient.getRewardsMats(address)));
|
|
28
|
+
const totalMats = mats.reduce((sumMats, currentMats) => sumMats + currentMats.seasonTwo.mats, 0);
|
|
29
|
+
return {
|
|
30
|
+
...currentAccount,
|
|
31
|
+
mats,
|
|
32
|
+
totalMats,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// If account is not recognized by Rewards API, it will return 404.
|
|
37
|
+
// To prevent errors we return default values
|
|
38
|
+
return {
|
|
39
|
+
...currentAccount,
|
|
40
|
+
mats: [
|
|
41
|
+
{
|
|
42
|
+
seasonOne: { mats: 0, rank: null },
|
|
43
|
+
seasonTwo: { mats: 0, rank: null },
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
totalMats: 0,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
55
49
|
},
|
|
56
50
|
staleTime: options.staleTime ?? ONE_MINUTE_MS,
|
|
57
51
|
retry: options.retry ?? 1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetCurrentAccount.js","sourceRoot":"","sources":["../../../src/hooks/useGetCurrentAccount.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"useGetCurrentAccount.js","sourceRoot":"","sources":["../../../src/hooks/useGetCurrentAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,GAGT,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAY3D;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAGlC,UAAkD,EAAE;IAEpD,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IACxC,MAAM,gBAAgB,GAAG,mBAAmB,EAAE,CAAA;IAE9C,MAAM,QAAQ,GAAG,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,CAAA;IAEzD,MAAM,KAAK,GAAG,QAAQ,CAAsD;QAC1E,QAAQ;QACR,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,MAAM,cAAc,GAAG,MAAM,aAAa,CAAC,iBAAiB,EAAE,CAAA;YAE9D,IAAI,CAAC,cAAc,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;YAC7C,CAAC;YAED,MAAM,aAAa,GAAG,cAAc,EAAE,cAAc,EAAE,MAAM,CAC1D,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,QAAQ,CACvC,CAAA;YACD,IAAI,CAAC,aAAa,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACjD,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAA;YACpE,CAAC;YAED,MAAM,SAAS,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;YAEpE,IAAI,CAAC;gBACH,uDAAuD;gBACvD,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,GAAG,CAC5B,SAAS,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,gBAAgB,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CACrE,CAAA;gBAED,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAC3B,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE,CAAC,OAAO,GAAG,WAAW,CAAC,SAAS,CAAC,IAAI,EAC9D,CAAC,CACF,CAAA;gBAED,OAAO;oBACL,GAAG,cAAc;oBACjB,IAAI;oBACJ,SAAS;iBACV,CAAA;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,mEAAmE;gBACnE,6CAA6C;gBAC7C,OAAO;oBACL,GAAG,cAAc;oBACjB,IAAI,EAAE;wBACJ;4BACE,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE;4BAClC,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE;yBACnC;qBACF;oBACD,SAAS,EAAE,CAAC;iBACb,CAAA;YACH,CAAC;QACH,CAAC;QACD,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,aAAa;QAC7C,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;QACzB,GAAG,OAAO;KACX,CAAC,CAAA;IAEF,OAAO;QACL,GAAG,KAAK;QACR,QAAQ;KACT,CAAA;AACH,CAAC"}
|
package/dist/src/provider.d.ts
CHANGED
|
@@ -8,7 +8,6 @@ export interface PassportContextValue {
|
|
|
8
8
|
nativeBalanceRefetchInterval: number;
|
|
9
9
|
nativePriceRefetchInterval: number;
|
|
10
10
|
borrowDataRefetchInterval: number;
|
|
11
|
-
useRewardsApi: boolean;
|
|
12
11
|
}
|
|
13
12
|
export declare const PassportContext: import("react").Context<PassportContextValue | undefined>;
|
|
14
13
|
type Environment = "mainnet" | "testnet";
|
|
@@ -31,10 +30,7 @@ type PassportProviderProps = {
|
|
|
31
30
|
* re-fetched. Default is 60000 (60 secs)
|
|
32
31
|
* price. */
|
|
33
32
|
borrowDataRefetchInterval?: number;
|
|
34
|
-
/** Determines whether passport should use Rewards API
|
|
35
|
-
* to consume data */
|
|
36
|
-
useRewardsApi?: boolean;
|
|
37
33
|
};
|
|
38
|
-
export declare function PassportProvider({ environment, authApiUrl, portalApiUrl, rewardsApiUrl, children,
|
|
34
|
+
export declare function PassportProvider({ environment, authApiUrl, portalApiUrl, rewardsApiUrl, children, accountDataRefetchInterval, nativeBalanceRefetchInterval, nativePriceRefetchInterval, borrowDataRefetchInterval, }: PassportProviderProps): import("react").FunctionComponentElement<import("react").ProviderProps<PassportContextValue | undefined>>;
|
|
39
35
|
export {};
|
|
40
36
|
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAA;AAGxE,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,aAAa,CAAA;IAC5B,eAAe,EAAE,eAAe,CAAA;IAChC,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,0BAA0B,EAAE,MAAM,CAAA;IAClC,4BAA4B,EAAE,MAAM,CAAA;IACpC,0BAA0B,EAAE,MAAM,CAAA;IAClC,yBAAyB,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAA;AAGxE,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,aAAa,CAAA;IAC5B,eAAe,EAAE,eAAe,CAAA;IAChC,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,0BAA0B,EAAE,MAAM,CAAA;IAClC,4BAA4B,EAAE,MAAM,CAAA;IACpC,0BAA0B,EAAE,MAAM,CAAA;IAClC,yBAAyB,EAAE,MAAM,CAAA;CAClC;AAED,eAAO,MAAM,eAAe,2DAE3B,CAAA;AAED,KAAK,WAAW,GAAG,SAAS,GAAG,SAAS,CAAA;AAExC,KAAK,qBAAqB,GAAG;IAC3B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB;mEAC+D;IAC/D,0BAA0B,CAAC,EAAE,MAAM,CAAA;IACnC;oDACgD;IAChD,4BAA4B,CAAC,EAAE,MAAM,CAAA;IACrC;iDAC6C;IAC7C,0BAA0B,CAAC,EAAE,MAAM,CAAA;IACnC;;gBAEY;IACZ,yBAAyB,CAAC,EAAE,MAAM,CAAA;CACnC,CAAA;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,WAAW,EACX,UAAU,EACV,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,0BAA+C,EAC/C,4BAAiD,EACjD,0BAA+C,EAC/C,yBAA8C,GAC/C,EAAE,qBAAqB,6GA2BvB"}
|
package/dist/src/provider.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createContext, createElement } from "react";
|
|
|
2
2
|
import { AuthApiClient, PortalApiClient, RewardsApiClient } from "./api";
|
|
3
3
|
import { ONE_SECOND_MS } from "./utils/time";
|
|
4
4
|
export const PassportContext = createContext(undefined);
|
|
5
|
-
export function PassportProvider({ environment, authApiUrl, portalApiUrl, rewardsApiUrl, children,
|
|
5
|
+
export function PassportProvider({ environment, authApiUrl, portalApiUrl, rewardsApiUrl, children, accountDataRefetchInterval = 60 * ONE_SECOND_MS, nativeBalanceRefetchInterval = 60 * ONE_SECOND_MS, nativePriceRefetchInterval = 60 * ONE_SECOND_MS, borrowDataRefetchInterval = 60 * ONE_SECOND_MS, }) {
|
|
6
6
|
if (environment && !["mainnet", "testnet"].includes(environment)) {
|
|
7
7
|
throw new Error("Wrong environment passed to PassportProvider.");
|
|
8
8
|
}
|
|
@@ -16,7 +16,6 @@ export function PassportProvider({ environment, authApiUrl, portalApiUrl, reward
|
|
|
16
16
|
nativeBalanceRefetchInterval,
|
|
17
17
|
nativePriceRefetchInterval,
|
|
18
18
|
borrowDataRefetchInterval,
|
|
19
|
-
useRewardsApi: useRewardsApi ?? false,
|
|
20
19
|
},
|
|
21
20
|
}, children);
|
|
22
21
|
}
|
package/dist/src/provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAA;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAA;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAa5C,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAC1C,SAAS,CACV,CAAA;AAyBD,MAAM,UAAU,gBAAgB,CAAC,EAC/B,WAAW,EACX,UAAU,EACV,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,0BAA0B,GAAG,EAAE,GAAG,aAAa,EAC/C,4BAA4B,GAAG,EAAE,GAAG,aAAa,EACjD,0BAA0B,GAAG,EAAE,GAAG,aAAa,EAC/C,yBAAyB,GAAG,EAAE,GAAG,aAAa,GACxB;IACtB,IAAI,WAAW,IAAI,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QACjE,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;IAClE,CAAC;IAED,OAAO,aAAa,CAClB,eAAe,CAAC,QAAQ,EACxB;QACE,KAAK,EAAE;YACL,aAAa,EAAE,IAAI,aAAa,CAAC,WAAW,IAAI,SAAS,EAAE,UAAU,CAAC;YACtE,eAAe,EAAE,IAAI,eAAe,CAClC,WAAW,IAAI,SAAS,EACxB,YAAY,CACb;YACD,gBAAgB,EAAE,IAAI,gBAAgB,CACpC,WAAW,IAAI,SAAS,EACxB,aAAa,CACd;YACD,WAAW;YACX,0BAA0B;YAC1B,4BAA4B;YAC5B,0BAA0B;YAC1B,yBAAyB;SAC1B;KACF,EACD,QAAQ,CACT,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
package/src/api/portal.ts
CHANGED
|
@@ -7,12 +7,6 @@ type PortalStatistics = {
|
|
|
7
7
|
usersCount: number
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export type PortalMats = {
|
|
11
|
-
totalMats: number
|
|
12
|
-
inactiveMats: number
|
|
13
|
-
matsActivated: boolean
|
|
14
|
-
}
|
|
15
|
-
|
|
16
10
|
export const PORTAL_API_ENDPOINTS_BY_ENV = {
|
|
17
11
|
mainnet: "https://api.mezo.org/api/",
|
|
18
12
|
testnet: "https://api.test.mezo.org/api/",
|
|
@@ -36,15 +30,4 @@ export class PortalApiClient extends ApiClient {
|
|
|
36
30
|
|
|
37
31
|
return data
|
|
38
32
|
}
|
|
39
|
-
|
|
40
|
-
async getPortalMats(address: string) {
|
|
41
|
-
const data = await this.handleRequest<PortalMats>(
|
|
42
|
-
`/v2/account/${address}/mats`,
|
|
43
|
-
{
|
|
44
|
-
method: "GET",
|
|
45
|
-
},
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
return data
|
|
49
|
-
}
|
|
50
33
|
}
|
package/src/api/rewards.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { useContext } from "react"
|
|
2
1
|
import {
|
|
3
2
|
QueryKey,
|
|
4
3
|
useQuery,
|
|
@@ -8,37 +7,14 @@ import {
|
|
|
8
7
|
import { ONE_MINUTE_MS } from "../utils/time"
|
|
9
8
|
import { QUERY_KEYS } from "./constants"
|
|
10
9
|
import { useAuthApiClient } from "./useAuthApiClient"
|
|
11
|
-
import {
|
|
12
|
-
import type { GetCurrentAccountResponse, PortalMats, RewardsMats } from "../api"
|
|
10
|
+
import type { GetCurrentAccountResponse, RewardsMats } from "../api"
|
|
13
11
|
import { useRewardsApiClient } from "./useRewardsApiClient"
|
|
14
|
-
import { PassportContext } from "../provider"
|
|
15
12
|
|
|
16
13
|
type GetCurrentAccountResponseWithMats = GetCurrentAccountResponse & {
|
|
17
|
-
mats:
|
|
14
|
+
mats: RewardsMats[]
|
|
18
15
|
totalMats: number
|
|
19
16
|
}
|
|
20
17
|
|
|
21
|
-
export const isRewardsMats = (value: unknown): value is RewardsMats =>
|
|
22
|
-
!!value &&
|
|
23
|
-
typeof value === "object" &&
|
|
24
|
-
["seasonOne", "seasonTwo"].every(
|
|
25
|
-
(seasonKey) =>
|
|
26
|
-
!!(value as never)[seasonKey] &&
|
|
27
|
-
typeof (value as never)[seasonKey] === "object" &&
|
|
28
|
-
["mats", "rank"].every(
|
|
29
|
-
(fieldKey) => typeof (value as never)[seasonKey][fieldKey] === "number",
|
|
30
|
-
),
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
export const isPortalMats = (value: unknown): value is PortalMats =>
|
|
34
|
-
!!value &&
|
|
35
|
-
typeof value === "object" &&
|
|
36
|
-
["totalMats", "inactiveMats", "matsActivated"].every((fieldKey) =>
|
|
37
|
-
fieldKey === "matsActivated"
|
|
38
|
-
? typeof (value as never)[fieldKey] === "boolean"
|
|
39
|
-
: typeof (value as never)[fieldKey] === "number",
|
|
40
|
-
)
|
|
41
|
-
|
|
42
18
|
type UseGetCurrentAccountOptions<TSelected> = Omit<
|
|
43
19
|
UseQueryOptions<GetCurrentAccountResponseWithMats, Error, TSelected>,
|
|
44
20
|
"queryKey" | "queryFn"
|
|
@@ -52,10 +28,7 @@ export function useGetCurrentAccount<
|
|
|
52
28
|
>(
|
|
53
29
|
options: UseGetCurrentAccountOptions<TSelected> = {},
|
|
54
30
|
): UseQueryResult<TSelected, Error> & { queryKey: QueryKey } {
|
|
55
|
-
const passportContext = useContext(PassportContext)
|
|
56
|
-
|
|
57
31
|
const authApiClient = useAuthApiClient()
|
|
58
|
-
const portalApiClient = usePortalApiClient()
|
|
59
32
|
const rewardsApiClient = useRewardsApiClient()
|
|
60
33
|
|
|
61
34
|
const queryKey = [QUERY_KEYS.ACCOUNT, QUERY_KEYS.CURRENT]
|
|
@@ -64,6 +37,7 @@ export function useGetCurrentAccount<
|
|
|
64
37
|
queryKey,
|
|
65
38
|
queryFn: async () => {
|
|
66
39
|
const currentAccount = await authApiClient.getCurrentAccount()
|
|
40
|
+
|
|
67
41
|
if (!currentAccount) {
|
|
68
42
|
throw new Error("No current account found")
|
|
69
43
|
}
|
|
@@ -75,34 +49,37 @@ export function useGetCurrentAccount<
|
|
|
75
49
|
throw new Error("No linked wallets found for the current account")
|
|
76
50
|
}
|
|
77
51
|
|
|
78
|
-
const addresses = linkedWallets.map((account) =>
|
|
79
|
-
passportContext?.useRewardsApi
|
|
80
|
-
? account.evmAddress
|
|
81
|
-
: account.btcAddress || account.evmAddress,
|
|
82
|
-
)
|
|
52
|
+
const addresses = linkedWallets.map((account) => account.evmAddress)
|
|
83
53
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
: portalApiClient.getPortalMats(address),
|
|
90
|
-
),
|
|
91
|
-
)
|
|
54
|
+
try {
|
|
55
|
+
/** Mats balances aggregated from all linked wallets */
|
|
56
|
+
const mats = await Promise.all(
|
|
57
|
+
addresses.map((address) => rewardsApiClient.getRewardsMats(address)),
|
|
58
|
+
)
|
|
92
59
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
? (currentMats as RewardsMats).seasonTwo.mats
|
|
98
|
-
: (currentMats as PortalMats).totalMats),
|
|
99
|
-
0,
|
|
100
|
-
)
|
|
60
|
+
const totalMats = mats.reduce(
|
|
61
|
+
(sumMats, currentMats) => sumMats + currentMats.seasonTwo.mats,
|
|
62
|
+
0,
|
|
63
|
+
)
|
|
101
64
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
65
|
+
return {
|
|
66
|
+
...currentAccount,
|
|
67
|
+
mats,
|
|
68
|
+
totalMats,
|
|
69
|
+
}
|
|
70
|
+
} catch {
|
|
71
|
+
// If account is not recognized by Rewards API, it will return 404.
|
|
72
|
+
// To prevent errors we return default values
|
|
73
|
+
return {
|
|
74
|
+
...currentAccount,
|
|
75
|
+
mats: [
|
|
76
|
+
{
|
|
77
|
+
seasonOne: { mats: 0, rank: null },
|
|
78
|
+
seasonTwo: { mats: 0, rank: null },
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
totalMats: 0,
|
|
82
|
+
}
|
|
106
83
|
}
|
|
107
84
|
},
|
|
108
85
|
staleTime: options.staleTime ?? ONE_MINUTE_MS,
|
package/src/provider.ts
CHANGED
|
@@ -11,7 +11,6 @@ export interface PassportContextValue {
|
|
|
11
11
|
nativeBalanceRefetchInterval: number
|
|
12
12
|
nativePriceRefetchInterval: number
|
|
13
13
|
borrowDataRefetchInterval: number
|
|
14
|
-
useRewardsApi: boolean
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
export const PassportContext = createContext<PassportContextValue | undefined>(
|
|
@@ -39,9 +38,6 @@ type PassportProviderProps = {
|
|
|
39
38
|
* re-fetched. Default is 60000 (60 secs)
|
|
40
39
|
* price. */
|
|
41
40
|
borrowDataRefetchInterval?: number
|
|
42
|
-
/** Determines whether passport should use Rewards API
|
|
43
|
-
* to consume data */
|
|
44
|
-
useRewardsApi?: boolean
|
|
45
41
|
}
|
|
46
42
|
|
|
47
43
|
export function PassportProvider({
|
|
@@ -50,7 +46,6 @@ export function PassportProvider({
|
|
|
50
46
|
portalApiUrl,
|
|
51
47
|
rewardsApiUrl,
|
|
52
48
|
children,
|
|
53
|
-
useRewardsApi,
|
|
54
49
|
accountDataRefetchInterval = 60 * ONE_SECOND_MS,
|
|
55
50
|
nativeBalanceRefetchInterval = 60 * ONE_SECOND_MS,
|
|
56
51
|
nativePriceRefetchInterval = 60 * ONE_SECOND_MS,
|
|
@@ -78,7 +73,6 @@ export function PassportProvider({
|
|
|
78
73
|
nativeBalanceRefetchInterval,
|
|
79
74
|
nativePriceRefetchInterval,
|
|
80
75
|
borrowDataRefetchInterval,
|
|
81
|
-
useRewardsApi: useRewardsApi ?? false,
|
|
82
76
|
},
|
|
83
77
|
},
|
|
84
78
|
children,
|