@domino-sdk/relay 0.26.0 → 0.28.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/authoring.d.ts +2 -2
- package/dist/browser.d.ts +297 -172
- package/dist/browser.js +9 -3
- package/dist/{chunk-7QICEKC2.js → chunk-AL5GXMKI.js} +39 -30
- package/dist/{chunk-MZFUQQDP.js → chunk-NHSA6ATH.js} +209 -9
- package/dist/{chunk-S44XSDW2.js → chunk-ZP43MHO3.js} +4 -4
- package/dist/index.d.ts +390 -390
- package/dist/index.js +8 -4
- package/dist/portal-proxy.js +1 -1
- package/dist/react/index.d.ts +60 -28
- package/dist/react/index.js +153 -77
- package/dist/{submission-input-Ckpb4sBv.d.ts → submission-input-D3t8WKOk.d.ts} +41 -41
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -72,7 +72,7 @@ import {
|
|
|
72
72
|
xPostSchema,
|
|
73
73
|
xProfileSchema,
|
|
74
74
|
xRequestSchema
|
|
75
|
-
} from "./chunk-
|
|
75
|
+
} from "./chunk-ZP43MHO3.js";
|
|
76
76
|
import {
|
|
77
77
|
defineEngagementReward,
|
|
78
78
|
defineLeaderboard,
|
|
@@ -127,8 +127,8 @@ import {
|
|
|
127
127
|
authScopeSchema,
|
|
128
128
|
caip10,
|
|
129
129
|
cosmosAddressSchema,
|
|
130
|
+
cosmosChain,
|
|
130
131
|
cosmosNetworkSchema,
|
|
131
|
-
cosmosNetworks,
|
|
132
132
|
evmAddressSchema,
|
|
133
133
|
exchangeResultSchema,
|
|
134
134
|
exchangeSchema,
|
|
@@ -150,11 +150,13 @@ import {
|
|
|
150
150
|
walletConnectionSchema,
|
|
151
151
|
walletMessageChallengeSchema,
|
|
152
152
|
walletProofSchema,
|
|
153
|
+
walletSignInFamilies,
|
|
153
154
|
walletSignInNetwork,
|
|
154
155
|
walletSignInNetworkSchema,
|
|
156
|
+
walletSignInNetworksSchema,
|
|
155
157
|
walletSignatureSchema,
|
|
156
158
|
walletUnlinkInputSchema
|
|
157
|
-
} from "./chunk-
|
|
159
|
+
} from "./chunk-AL5GXMKI.js";
|
|
158
160
|
import {
|
|
159
161
|
AVATAR_UPLOAD_LIMIT,
|
|
160
162
|
avatarProviderSchema,
|
|
@@ -389,8 +391,8 @@ export {
|
|
|
389
391
|
contentQualificationSchema,
|
|
390
392
|
contentReleaseInputSchema,
|
|
391
393
|
cosmosAddressSchema,
|
|
394
|
+
cosmosChain,
|
|
392
395
|
cosmosNetworkSchema,
|
|
393
|
-
cosmosNetworks,
|
|
394
396
|
createPointLedgerSchema,
|
|
395
397
|
createRelayClient,
|
|
396
398
|
createStockItemSchema,
|
|
@@ -644,8 +646,10 @@ export {
|
|
|
644
646
|
walletConnectionSchema,
|
|
645
647
|
walletMessageChallengeSchema,
|
|
646
648
|
walletProofSchema,
|
|
649
|
+
walletSignInFamilies,
|
|
647
650
|
walletSignInNetwork,
|
|
648
651
|
walletSignInNetworkSchema,
|
|
652
|
+
walletSignInNetworksSchema,
|
|
649
653
|
walletSignatureSchema,
|
|
650
654
|
walletUnlinkInputSchema,
|
|
651
655
|
x,
|
package/dist/portal-proxy.js
CHANGED
package/dist/react/index.d.ts
CHANGED
|
@@ -4,9 +4,10 @@ import * as zod from 'zod';
|
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { ProfileUpdate, QuestView, QuestController, ProgressObservation, questExperienceSchema, ProgressObserver, ExchangeInput, PhotoSubmission, QuizSubmission, ClaimSubmission, ValueSubmission, SubmissionDraft, PublicProfile, PointLedgerReference } from '../index.js';
|
|
6
6
|
export { avatarSrc, defaultAvatar, walletAvatarSeed } from '../index.js';
|
|
7
|
-
import { H as referralAcceptSchema, J as LeaderboardQuery, K as WalletAddressInput, M as walletSignatureSchema, L as LinkedWallet, N as WalletSigner, P as walletChallengeInputSchema, Q as walletProofSchema, R as AuthProvider, V as WalletSignature, Y as engagementPageQuerySchema, Z as contentQualificationQuerySchema, _ as contentAdmissionQuerySchema, $ as contentEnrollmentInputSchema, a0 as contentReleaseInputSchema, a1 as
|
|
7
|
+
import { H as referralAcceptSchema, J as LeaderboardQuery, K as WalletAddressInput, M as walletSignatureSchema, L as LinkedWallet, N as WalletSigner, P as walletChallengeInputSchema, Q as walletProofSchema, R as AuthProvider, V as WalletSignature, Y as engagementPageQuerySchema, Z as contentQualificationQuerySchema, _ as contentAdmissionQuerySchema, $ as contentEnrollmentInputSchema, a0 as contentReleaseInputSchema, a1 as AccountConnection, a2 as WalletSignInNetwork, a3 as referralSummarySchema, a4 as LeaderboardPage } from '../submission-input-D3t8WKOk.js';
|
|
8
8
|
import { SubmitInput, ReleaseInput, beginHandoverSchema, contentPerformanceQuerySchema, TieredRewardReference } from '../schema.js';
|
|
9
|
-
import { createBrowserRelayClient, DiscoveredWallet } from '../browser.js';
|
|
9
|
+
import { createBrowserRelayClient, SignInMethods, CosmosChains, SignInOption, SignInUnavailable, SignInWallet, DiscoveredWallet } from '../browser.js';
|
|
10
|
+
export { EmailSignInOption, OAuthSignInOption, SignInIcon, WalletSignInOption } from '../browser.js';
|
|
10
11
|
|
|
11
12
|
type RelayClient = ReturnType<typeof createBrowserRelayClient>;
|
|
12
13
|
/** The participant client, for calls no hook covers. */
|
|
@@ -1487,7 +1488,7 @@ declare function useRelay(): {
|
|
|
1487
1488
|
wallets: {
|
|
1488
1489
|
list: () => Promise<{
|
|
1489
1490
|
chain: "solana" | "eip155" | "cosmos";
|
|
1490
|
-
network:
|
|
1491
|
+
network: `cosmos:${string}` | null;
|
|
1491
1492
|
address: string;
|
|
1492
1493
|
verifiedAt: number;
|
|
1493
1494
|
revision: number;
|
|
@@ -1497,14 +1498,14 @@ declare function useRelay(): {
|
|
|
1497
1498
|
id: string;
|
|
1498
1499
|
purpose: "link" | "sign-in";
|
|
1499
1500
|
chain: "solana" | "eip155" | "cosmos";
|
|
1500
|
-
network:
|
|
1501
|
+
network: `cosmos:${string}` | null;
|
|
1501
1502
|
address: string;
|
|
1502
1503
|
message: string;
|
|
1503
1504
|
expiresAt: number;
|
|
1504
1505
|
}>;
|
|
1505
1506
|
verify: (input: zod.input<typeof walletSignatureSchema>, session: string) => Promise<{
|
|
1506
1507
|
chain: "solana" | "eip155" | "cosmos";
|
|
1507
|
-
network:
|
|
1508
|
+
network: `cosmos:${string}` | null;
|
|
1508
1509
|
address: string;
|
|
1509
1510
|
verifiedAt: number;
|
|
1510
1511
|
revision: number;
|
|
@@ -1515,7 +1516,7 @@ declare function useRelay(): {
|
|
|
1515
1516
|
}>;
|
|
1516
1517
|
link: (signer: WalletSigner) => Promise<{
|
|
1517
1518
|
chain: "solana" | "eip155" | "cosmos";
|
|
1518
|
-
network:
|
|
1519
|
+
network: `cosmos:${string}` | null;
|
|
1519
1520
|
address: string;
|
|
1520
1521
|
verifiedAt: number;
|
|
1521
1522
|
revision: number;
|
|
@@ -1550,7 +1551,7 @@ declare function useRelay(): {
|
|
|
1550
1551
|
configured: boolean;
|
|
1551
1552
|
}[];
|
|
1552
1553
|
email: boolean;
|
|
1553
|
-
wallets: ("solana" | "eip155" | "cosmos
|
|
1554
|
+
wallets: ("solana" | "eip155" | "cosmos")[];
|
|
1554
1555
|
demo: boolean;
|
|
1555
1556
|
}>;
|
|
1556
1557
|
start: (provider: AuthProvider, mode: "sign-in" | "connect") => Promise<{
|
|
@@ -1581,7 +1582,7 @@ declare function useRelay(): {
|
|
|
1581
1582
|
id: string;
|
|
1582
1583
|
purpose: "link" | "sign-in";
|
|
1583
1584
|
chain: "solana" | "eip155" | "cosmos";
|
|
1584
|
-
network:
|
|
1585
|
+
network: `cosmos:${string}` | null;
|
|
1585
1586
|
address: string;
|
|
1586
1587
|
message: string;
|
|
1587
1588
|
expiresAt: number;
|
|
@@ -4573,12 +4574,6 @@ declare function progressOf(quests: QuestView[]): {
|
|
|
4573
4574
|
};
|
|
4574
4575
|
|
|
4575
4576
|
type OAuthProvider = AuthProvider;
|
|
4576
|
-
type SignInMethods = {
|
|
4577
|
-
providers: OAuthProvider[];
|
|
4578
|
-
email: boolean;
|
|
4579
|
-
/** The wallet networks this project enabled for sign-in in Console. */
|
|
4580
|
-
wallets: WalletSignInNetwork[];
|
|
4581
|
-
};
|
|
4582
4577
|
/**
|
|
4583
4578
|
* The sign-in methods participants can use here: the OAuth providers and email Domino configured
|
|
4584
4579
|
* for the platform, and the wallet sign-in this project enabled in Console.
|
|
@@ -4593,7 +4588,10 @@ declare function useMe(): {
|
|
|
4593
4588
|
member: string;
|
|
4594
4589
|
avatarSeed: string;
|
|
4595
4590
|
} | null;
|
|
4596
|
-
/**
|
|
4591
|
+
/**
|
|
4592
|
+
* Email codes, OAuth consent and wallet signatures always happen in the participant's browser.
|
|
4593
|
+
* The actions keep their identity across renders, and never reject: a failure lands in `error`.
|
|
4594
|
+
*/
|
|
4597
4595
|
declare function useSignIn(): {
|
|
4598
4596
|
busy: boolean;
|
|
4599
4597
|
error: string | null;
|
|
@@ -4610,6 +4608,37 @@ declare function useSignOut(): {
|
|
|
4610
4608
|
busy: boolean;
|
|
4611
4609
|
signOut: () => Promise<void>;
|
|
4612
4610
|
};
|
|
4611
|
+
/**
|
|
4612
|
+
* Every way a participant can sign in here, as one flat list: the OAuth providers and email Domino
|
|
4613
|
+
* configured for the platform, and the installed wallets of the families this project enabled.
|
|
4614
|
+
* Each option has an `id`, a `label` ("Google", "Email", "Phantom"), a `kind` and an `icon` hint;
|
|
4615
|
+
* OAuth and wallet options sign in with `start()`, the email option with `sendCode(email)` then
|
|
4616
|
+
* `verifyCode(code)`. The options keep their identity across renders until the methods, the
|
|
4617
|
+
* installed wallets or the chains change, and their actions never reject: a failure lands in
|
|
4618
|
+
* `error`.
|
|
4619
|
+
*
|
|
4620
|
+
* Cosmos wallets sign in on the app's chains, so pass them in `cosmos`. Without them Cosmos wallets
|
|
4621
|
+
* are not offered, and `unavailable` holds `cosmos-chains-missing`; with an invalid one, such as
|
|
4622
|
+
* `"cosmoshub-4"` without `cosmos:`, it holds `cosmos-chains-invalid`. When the project takes
|
|
4623
|
+
* wallets but none is installed, `unavailable` holds `no-wallet-installed` with a message for the
|
|
4624
|
+
* participant. `options` is null until the methods are read. OAuth and email are offered at once;
|
|
4625
|
+
* installed wallets join them when discovery finishes, and a project that takes only wallets stays
|
|
4626
|
+
* null until then.
|
|
4627
|
+
*/
|
|
4628
|
+
declare function useSignInOptions(input?: {
|
|
4629
|
+
cosmos?: CosmosChains;
|
|
4630
|
+
}): {
|
|
4631
|
+
options: SignInOption[] | null;
|
|
4632
|
+
unavailable: SignInUnavailable[];
|
|
4633
|
+
/** Why the project's methods could not be read; the options are then email alone. */
|
|
4634
|
+
methodsError: string | null;
|
|
4635
|
+
busy: boolean;
|
|
4636
|
+
error: string | null;
|
|
4637
|
+
/** True once an email code was sent and the form should ask for it. */
|
|
4638
|
+
codeSent: boolean;
|
|
4639
|
+
/** Forgets the email code sent, to use another address. */
|
|
4640
|
+
startOver(): void;
|
|
4641
|
+
};
|
|
4613
4642
|
|
|
4614
4643
|
/** True when the account can be used to verify quests right now. */
|
|
4615
4644
|
declare function isConnected(accounts: AccountConnection[] | null, provider: AuthProvider): boolean;
|
|
@@ -4648,7 +4677,7 @@ declare function useWallets(): {
|
|
|
4648
4677
|
/** Null until read, and while nobody is signed in. */
|
|
4649
4678
|
wallets: {
|
|
4650
4679
|
chain: "solana" | "eip155" | "cosmos";
|
|
4651
|
-
network:
|
|
4680
|
+
network: `cosmos:${string}` | null;
|
|
4652
4681
|
address: string;
|
|
4653
4682
|
verifiedAt: number;
|
|
4654
4683
|
revision: number;
|
|
@@ -4662,26 +4691,29 @@ declare function useWallets(): {
|
|
|
4662
4691
|
};
|
|
4663
4692
|
/**
|
|
4664
4693
|
* The EVM, Solana and Cosmos wallets installed in this browser. Empty during
|
|
4665
|
-
* SSR and until discovery finishes
|
|
4694
|
+
* SSR and until discovery finishes. Cosmos wallets are listed once per chain
|
|
4695
|
+
* in `cosmos`, the app's chains; without it there are none.
|
|
4666
4696
|
*/
|
|
4667
4697
|
declare function useWalletDiscovery(options?: {
|
|
4668
|
-
cosmos?:
|
|
4698
|
+
cosmos?: CosmosChains;
|
|
4669
4699
|
}): {
|
|
4670
4700
|
evm: DiscoveredWallet[];
|
|
4671
4701
|
solana: DiscoveredWallet[];
|
|
4672
4702
|
cosmos: DiscoveredWallet[];
|
|
4673
4703
|
};
|
|
4674
|
-
/** An installed wallet that can sign in on one of the project's enabled networks. */
|
|
4675
|
-
type SignInWallet = DiscoveredWallet & {
|
|
4676
|
-
network: WalletSignInNetwork;
|
|
4677
|
-
};
|
|
4678
4704
|
/**
|
|
4679
|
-
* The wallets installed in this browser that can sign in
|
|
4680
|
-
* `useSignInMethods().wallets` returns: pass each one's
|
|
4681
|
-
* `useSignIn().withWallet`.
|
|
4682
|
-
*
|
|
4705
|
+
* The wallets installed in this browser that can sign in with the families in
|
|
4706
|
+
* `networks`, the list `useSignInMethods().wallets` returns: pass each one's
|
|
4707
|
+
* `signer` to `useSignIn().withWallet`. Cosmos wallets need the app's chains in
|
|
4708
|
+
* `options.cosmos`; each is listed once per chain, and none when a chain is
|
|
4709
|
+
* invalid (`useSignInOptions()` reports it as `cosmos-chains-invalid`). Null
|
|
4710
|
+
* during SSR and until discovery finishes, so a page can tell "still looking"
|
|
4711
|
+
* from "no wallet installed". `useSignInOptions()` combines this with the other
|
|
4712
|
+
* methods.
|
|
4683
4713
|
*/
|
|
4684
|
-
declare function useSignInWallets(networks: readonly WalletSignInNetwork[] | null | undefined
|
|
4714
|
+
declare function useSignInWallets(networks: readonly WalletSignInNetwork[] | null | undefined, options?: {
|
|
4715
|
+
cosmos?: CosmosChains;
|
|
4716
|
+
}): SignInWallet[] | null;
|
|
4685
4717
|
|
|
4686
4718
|
/** Dispatched on `window` after the member changes their profile in this tab. */
|
|
4687
4719
|
declare const PROFILE_CHANGED = "relay-profile-changed";
|
|
@@ -5028,4 +5060,4 @@ declare function useTieredRewards(): {
|
|
|
5028
5060
|
}[];
|
|
5029
5061
|
};
|
|
5030
5062
|
|
|
5031
|
-
export { type Collection, DiscoveredWallet, type Experience, type Invitation, type LeaderboardState, type OAuthProvider, PENDING_POLL_MS, PROFILE_CHANGED, type PointLedgersState, type ProfileState, type QuestInput, type QuestNotice, type QuestStatus, type QuestTone, RETRY_DELAYS_MS, type ReferencesState, type ReferralSummary, type RelayClient, RelayProvider, type RoleDelivery, type SavedSubmission,
|
|
5063
|
+
export { type Collection, CosmosChains, DiscoveredWallet, type Experience, type Invitation, type LeaderboardState, type OAuthProvider, PENDING_POLL_MS, PROFILE_CHANGED, type PointLedgersState, type ProfileState, type QuestInput, type QuestNotice, type QuestStatus, type QuestTone, RETRY_DELAYS_MS, type ReferencesState, type ReferralSummary, type RelayClient, RelayProvider, type RoleDelivery, type SavedSubmission, SignInMethods, SignInOption, SignInUnavailable, SignInWallet, type TieredRewardsState, canRepeat, canSubmit, captureReferralCode, completionCountLabel, completionMark, hasPending, isAutomatic, isConnected, isFinished, progressOf, questGroups, questStatus, roleDeliveryLabel, runsSilently, sanitizeDeliveries, useAccounts, useExperience, useInvitation, useLeaderboard, useMe, useMyProfile, usePointLedgers, useProfile, useQuest, useReferralSummary, useRelay, useSignIn, useSignInMethods, useSignInOptions, useSignInWallets, useSignOut, useTieredRewards, useWalletDiscovery, useWallets, visibleQuests, watchRoleDeliveries };
|
package/dist/react/index.js
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
|
+
cosmosChainList,
|
|
3
|
+
cosmosChainsError,
|
|
2
4
|
createBrowserRelayClient,
|
|
3
5
|
discoverCosmosWallets,
|
|
4
6
|
discoverEvmWallets,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
discoverSignInWallets,
|
|
8
|
+
discoverSolanaWallets,
|
|
9
|
+
readSignInMethods,
|
|
10
|
+
signInOptionsFrom
|
|
11
|
+
} from "../chunk-NHSA6ATH.js";
|
|
7
12
|
import {
|
|
8
13
|
RelayError,
|
|
9
14
|
avatarSrc,
|
|
10
15
|
defaultAvatar,
|
|
11
16
|
walletAvatarSeed
|
|
12
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-ZP43MHO3.js";
|
|
13
18
|
import "../chunk-AKB266O5.js";
|
|
14
|
-
import "../chunk-
|
|
19
|
+
import "../chunk-AL5GXMKI.js";
|
|
15
20
|
import "../chunk-D6BX627V.js";
|
|
16
21
|
import "../chunk-IXLY3A7B.js";
|
|
17
22
|
|
|
@@ -538,7 +543,7 @@ function useQuest(observed) {
|
|
|
538
543
|
}
|
|
539
544
|
|
|
540
545
|
// src/react/auth.ts
|
|
541
|
-
import { useEffect as useEffect5, useState as useState6 } from "react";
|
|
546
|
+
import { useCallback as useCallback3, useEffect as useEffect5, useMemo as useMemo2, useRef as useRef2, useState as useState6 } from "react";
|
|
542
547
|
|
|
543
548
|
// src/react/wallets.ts
|
|
544
549
|
import { useCallback as useCallback2, useEffect as useEffect4, useState as useState5 } from "react";
|
|
@@ -605,13 +610,18 @@ function useWallets() {
|
|
|
605
610
|
}, "Couldn't unlink this wallet. Try again.")
|
|
606
611
|
};
|
|
607
612
|
}
|
|
613
|
+
function discoverChains(key) {
|
|
614
|
+
return JSON.parse(key).flatMap(
|
|
615
|
+
(chain) => discoverCosmosWallets(chain)
|
|
616
|
+
);
|
|
617
|
+
}
|
|
608
618
|
function useWalletDiscovery(options = {}) {
|
|
609
|
-
const
|
|
619
|
+
const chains = JSON.stringify(cosmosChainList(options.cosmos));
|
|
610
620
|
const [found, setFound] = useState5({ evm: [], solana: [], cosmos: [] });
|
|
611
621
|
useEffect4(() => {
|
|
612
622
|
let active = true;
|
|
613
623
|
const solana = discoverSolanaWallets();
|
|
614
|
-
const cosmos =
|
|
624
|
+
const cosmos = discoverChains(chains);
|
|
615
625
|
setFound((current) => ({ ...current, solana, cosmos }));
|
|
616
626
|
void discoverEvmWallets().then((evm) => {
|
|
617
627
|
if (active) {
|
|
@@ -621,29 +631,28 @@ function useWalletDiscovery(options = {}) {
|
|
|
621
631
|
return () => {
|
|
622
632
|
active = false;
|
|
623
633
|
};
|
|
624
|
-
}, [
|
|
634
|
+
}, [chains]);
|
|
625
635
|
return found;
|
|
626
636
|
}
|
|
627
|
-
function useSignInWallets(networks) {
|
|
628
|
-
const
|
|
637
|
+
function useSignInWallets(networks, options = {}) {
|
|
638
|
+
const chains = JSON.stringify(
|
|
639
|
+
cosmosChainsError(options.cosmos) ? [] : cosmosChainList(options.cosmos)
|
|
640
|
+
);
|
|
641
|
+
const key = networks ? `${networks.join(" ")}
|
|
642
|
+
${chains}` : null;
|
|
629
643
|
const [found, setFound] = useState5(null);
|
|
630
644
|
useEffect4(() => {
|
|
631
645
|
if (key === null) {
|
|
632
646
|
return;
|
|
633
647
|
}
|
|
634
648
|
let active = true;
|
|
635
|
-
const
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
(network) => network.startsWith("cosmos:")
|
|
641
|
-
).flatMap((network) => tagged(network, discoverCosmosWallets(network)))
|
|
642
|
-
];
|
|
643
|
-
const evm = enabled.includes("eip155") ? discoverEvmWallets() : Promise.resolve([]);
|
|
644
|
-
void evm.then((wallets) => {
|
|
649
|
+
const [families = "", cosmos = "[]"] = key.split("\n");
|
|
650
|
+
void discoverSignInWallets(
|
|
651
|
+
families.split(" ").filter(Boolean),
|
|
652
|
+
JSON.parse(cosmos)
|
|
653
|
+
).catch(() => []).then((wallets) => {
|
|
645
654
|
if (active) {
|
|
646
|
-
setFound({ key, wallets
|
|
655
|
+
setFound({ key, wallets });
|
|
647
656
|
}
|
|
648
657
|
});
|
|
649
658
|
return () => {
|
|
@@ -659,18 +668,11 @@ function useSignInMethods() {
|
|
|
659
668
|
const [methods, setMethods] = useState6(null);
|
|
660
669
|
useEffect5(() => {
|
|
661
670
|
let active = true;
|
|
662
|
-
relay
|
|
663
|
-
if (
|
|
664
|
-
|
|
671
|
+
void readSignInMethods(relay).then((result) => {
|
|
672
|
+
if (active) {
|
|
673
|
+
setMethods(result);
|
|
665
674
|
}
|
|
666
|
-
|
|
667
|
-
providers: result.providers.filter((p) => p.configured).map((p) => p.provider),
|
|
668
|
-
email: result.email,
|
|
669
|
-
wallets: result.wallets
|
|
670
|
-
});
|
|
671
|
-
}).catch(
|
|
672
|
-
() => active && setMethods({ providers: [], email: true, wallets: [] })
|
|
673
|
-
);
|
|
675
|
+
});
|
|
674
676
|
return () => {
|
|
675
677
|
active = false;
|
|
676
678
|
};
|
|
@@ -699,50 +701,77 @@ function useMe() {
|
|
|
699
701
|
}
|
|
700
702
|
function useSignIn() {
|
|
701
703
|
const relay = useRelay();
|
|
702
|
-
const [challenge,
|
|
704
|
+
const [challenge, setChallengeState] = useState6(null);
|
|
705
|
+
const latest = useRef2(null);
|
|
703
706
|
const [busy, setBusy] = useState6(false);
|
|
704
707
|
const [error, setError] = useState6(null);
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
708
|
+
const setChallenge = useCallback3((value) => {
|
|
709
|
+
latest.current = value;
|
|
710
|
+
setChallengeState(value);
|
|
711
|
+
}, []);
|
|
712
|
+
const run = useCallback3(
|
|
713
|
+
async (task, fallback) => {
|
|
714
|
+
setBusy(true);
|
|
715
|
+
setError(null);
|
|
716
|
+
try {
|
|
717
|
+
await task();
|
|
718
|
+
} catch (cause) {
|
|
719
|
+
setError(
|
|
720
|
+
cause instanceof Error && cause.message ? cause.message : fallback
|
|
721
|
+
);
|
|
722
|
+
} finally {
|
|
723
|
+
setBusy(false);
|
|
724
|
+
}
|
|
725
|
+
},
|
|
726
|
+
[]
|
|
727
|
+
);
|
|
728
|
+
const sendCode = useCallback3(
|
|
729
|
+
(email) => run(async () => {
|
|
730
|
+
setChallenge(null);
|
|
724
731
|
setChallenge((await relay.auth.emailStart(email)).challenge);
|
|
725
732
|
}, "Couldn't send a code. Check the address and try again."),
|
|
726
|
-
|
|
727
|
-
|
|
733
|
+
[relay, run, setChallenge]
|
|
734
|
+
);
|
|
735
|
+
const verifyCode = useCallback3(
|
|
736
|
+
(code) => run(async () => {
|
|
737
|
+
const sent = latest.current;
|
|
738
|
+
if (!sent) {
|
|
728
739
|
throw new Error("Request a new code first.");
|
|
729
740
|
}
|
|
730
|
-
await relay.auth.emailVerify(
|
|
741
|
+
await relay.auth.emailVerify(sent, code.trim());
|
|
731
742
|
setChallenge(null);
|
|
732
743
|
}, "That code didn't work. Check it, or request a new one."),
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
744
|
+
[relay, run, setChallenge]
|
|
745
|
+
);
|
|
746
|
+
const startOver = useCallback3(() => {
|
|
747
|
+
setChallenge(null);
|
|
748
|
+
setError(null);
|
|
749
|
+
}, [setChallenge]);
|
|
750
|
+
const withProvider = useCallback3(
|
|
751
|
+
(provider) => run(async () => {
|
|
738
752
|
const { url } = await relay.auth.start(provider, "sign-in");
|
|
739
753
|
window.location.assign(url);
|
|
740
754
|
}, "Couldn't start sign-in. Try again."),
|
|
741
|
-
|
|
742
|
-
|
|
755
|
+
[relay, run]
|
|
756
|
+
);
|
|
757
|
+
const withWallet = useCallback3(
|
|
758
|
+
(signer) => run(async () => {
|
|
743
759
|
await relay.auth.wallet.signIn(signer);
|
|
744
760
|
setChallenge(null);
|
|
745
|
-
}, "Couldn't sign in with this wallet. Try again.")
|
|
761
|
+
}, "Couldn't sign in with this wallet. Try again."),
|
|
762
|
+
[relay, run, setChallenge]
|
|
763
|
+
);
|
|
764
|
+
return {
|
|
765
|
+
busy,
|
|
766
|
+
error,
|
|
767
|
+
/** True once a code was sent and the form should ask for it. */
|
|
768
|
+
codeSent: challenge !== null,
|
|
769
|
+
sendCode,
|
|
770
|
+
verifyCode,
|
|
771
|
+
startOver,
|
|
772
|
+
withProvider,
|
|
773
|
+
/** Signs in, or signs up, with a wallet; the wallet asks the participant to sign a message. */
|
|
774
|
+
withWallet
|
|
746
775
|
};
|
|
747
776
|
}
|
|
748
777
|
function useSignOut() {
|
|
@@ -760,9 +789,55 @@ function useSignOut() {
|
|
|
760
789
|
}
|
|
761
790
|
};
|
|
762
791
|
}
|
|
792
|
+
function useSignInOptions(input = {}) {
|
|
793
|
+
const chains = JSON.stringify(cosmosChainList(input.cosmos));
|
|
794
|
+
const cosmos = useMemo2(
|
|
795
|
+
() => JSON.parse(chains),
|
|
796
|
+
[chains]
|
|
797
|
+
);
|
|
798
|
+
const methods = useSignInMethods();
|
|
799
|
+
const wallets = useSignInWallets(methods?.wallets, { cosmos });
|
|
800
|
+
const {
|
|
801
|
+
busy,
|
|
802
|
+
error,
|
|
803
|
+
codeSent,
|
|
804
|
+
startOver,
|
|
805
|
+
sendCode,
|
|
806
|
+
verifyCode,
|
|
807
|
+
withProvider,
|
|
808
|
+
withWallet
|
|
809
|
+
} = useSignIn();
|
|
810
|
+
const built = useMemo2(() => {
|
|
811
|
+
if (!methods) {
|
|
812
|
+
return null;
|
|
813
|
+
}
|
|
814
|
+
if (!wallets && methods.providers.length === 0 && !methods.email) {
|
|
815
|
+
return null;
|
|
816
|
+
}
|
|
817
|
+
return signInOptionsFrom(methods, wallets ?? [], {
|
|
818
|
+
cosmos,
|
|
819
|
+
walletsPending: !wallets,
|
|
820
|
+
actions: {
|
|
821
|
+
oauth: withProvider,
|
|
822
|
+
sendCode,
|
|
823
|
+
verifyCode,
|
|
824
|
+
wallet: withWallet
|
|
825
|
+
}
|
|
826
|
+
});
|
|
827
|
+
}, [methods, wallets, cosmos, withProvider, sendCode, verifyCode, withWallet]);
|
|
828
|
+
return {
|
|
829
|
+
options: built?.options ?? null,
|
|
830
|
+
unavailable: built?.unavailable ?? [],
|
|
831
|
+
methodsError: methods?.error ?? null,
|
|
832
|
+
busy,
|
|
833
|
+
error,
|
|
834
|
+
codeSent,
|
|
835
|
+
startOver
|
|
836
|
+
};
|
|
837
|
+
}
|
|
763
838
|
|
|
764
839
|
// src/react/accounts.ts
|
|
765
|
-
import { useCallback as
|
|
840
|
+
import { useCallback as useCallback4, useEffect as useEffect6, useState as useState7 } from "react";
|
|
766
841
|
var CHANGED = "relay-accounts-changed";
|
|
767
842
|
function isConnected(accounts, provider) {
|
|
768
843
|
return Boolean(
|
|
@@ -777,7 +852,7 @@ function useAccounts() {
|
|
|
777
852
|
const [accounts, setAccounts] = useState7(null);
|
|
778
853
|
const [error, setError] = useState7(null);
|
|
779
854
|
const [busy, setBusy] = useState7(false);
|
|
780
|
-
const refresh =
|
|
855
|
+
const refresh = useCallback4(async () => {
|
|
781
856
|
try {
|
|
782
857
|
setAccounts(await relay.auth.accounts());
|
|
783
858
|
setError(null);
|
|
@@ -833,7 +908,7 @@ function useAccounts() {
|
|
|
833
908
|
}
|
|
834
909
|
|
|
835
910
|
// src/react/profiles.ts
|
|
836
|
-
import { useCallback as
|
|
911
|
+
import { useCallback as useCallback5, useEffect as useEffect7, useRef as useRef3, useState as useState8 } from "react";
|
|
837
912
|
var PROFILE_CHANGED = "relay-profile-changed";
|
|
838
913
|
function useMyProfile() {
|
|
839
914
|
const relay = useRelay();
|
|
@@ -841,8 +916,8 @@ function useMyProfile() {
|
|
|
841
916
|
const [profile, setProfile] = useState8(null);
|
|
842
917
|
const [error, setError] = useState8(null);
|
|
843
918
|
const [busy, setBusy] = useState8(false);
|
|
844
|
-
const session =
|
|
845
|
-
const refresh =
|
|
919
|
+
const session = useRef3(null);
|
|
920
|
+
const refresh = useCallback5(async () => {
|
|
846
921
|
try {
|
|
847
922
|
const [current, value] = await Promise.all([
|
|
848
923
|
relay.auth.session(),
|
|
@@ -915,7 +990,7 @@ function useProfile(id, options = {}) {
|
|
|
915
990
|
const { member } = useExperience();
|
|
916
991
|
const { intervalMs = 6e4 } = options;
|
|
917
992
|
const [state, setState] = useState8({ status: "loading" });
|
|
918
|
-
const refresh =
|
|
993
|
+
const refresh = useCallback5(async () => {
|
|
919
994
|
try {
|
|
920
995
|
const profile = await relay.profiles.get(id);
|
|
921
996
|
setState({ status: "ready", profile, stale: null });
|
|
@@ -949,7 +1024,7 @@ function useProfile(id, options = {}) {
|
|
|
949
1024
|
}
|
|
950
1025
|
|
|
951
1026
|
// src/react/referrals.ts
|
|
952
|
-
import { useCallback as
|
|
1027
|
+
import { useCallback as useCallback6, useEffect as useEffect8, useRef as useRef4, useState as useState9 } from "react";
|
|
953
1028
|
var PENDING = "domino:pending-referral";
|
|
954
1029
|
var CODE = /^[a-zA-Z0-9_-]{1,100}$/;
|
|
955
1030
|
function captureReferralCode(param = "ref") {
|
|
@@ -979,8 +1054,8 @@ function useInvitation(param = "ref") {
|
|
|
979
1054
|
const code = captureReferralCode(param);
|
|
980
1055
|
return code ? { status: "pending", code } : { status: "none" };
|
|
981
1056
|
});
|
|
982
|
-
const started =
|
|
983
|
-
const accept =
|
|
1057
|
+
const started = useRef4(null);
|
|
1058
|
+
const accept = useCallback6(
|
|
984
1059
|
async (code) => {
|
|
985
1060
|
setState({ status: "accepting", code });
|
|
986
1061
|
try {
|
|
@@ -1014,7 +1089,7 @@ function useReferralSummary(options = {}) {
|
|
|
1014
1089
|
const { member } = useExperience();
|
|
1015
1090
|
const [summary, setSummary] = useState9(null);
|
|
1016
1091
|
const [error, setError] = useState9(null);
|
|
1017
|
-
const refresh =
|
|
1092
|
+
const refresh = useCallback6(async () => {
|
|
1018
1093
|
try {
|
|
1019
1094
|
setSummary(await relay.referrals.summary());
|
|
1020
1095
|
setError(null);
|
|
@@ -1040,13 +1115,13 @@ function useReferralSummary(options = {}) {
|
|
|
1040
1115
|
}
|
|
1041
1116
|
|
|
1042
1117
|
// src/react/leaderboards.ts
|
|
1043
|
-
import { useCallback as
|
|
1118
|
+
import { useCallback as useCallback7, useEffect as useEffect9, useState as useState10 } from "react";
|
|
1044
1119
|
function useLeaderboard(board, options = {}) {
|
|
1045
1120
|
const relay = useRelay();
|
|
1046
1121
|
const { member } = useExperience();
|
|
1047
1122
|
const { limit = 25, intervalMs = 3e4 } = options;
|
|
1048
1123
|
const [state, setState] = useState10({ status: "loading" });
|
|
1049
|
-
const refresh =
|
|
1124
|
+
const refresh = useCallback7(async () => {
|
|
1050
1125
|
try {
|
|
1051
1126
|
const page = await relay.leaderboards.standings(board, { limit });
|
|
1052
1127
|
setState({ status: "ready", page, stale: null });
|
|
@@ -1070,11 +1145,11 @@ function useLeaderboard(board, options = {}) {
|
|
|
1070
1145
|
}
|
|
1071
1146
|
|
|
1072
1147
|
// src/react/references.ts
|
|
1073
|
-
import { useCallback as
|
|
1148
|
+
import { useCallback as useCallback8, useEffect as useEffect10, useState as useState11 } from "react";
|
|
1074
1149
|
function useReferences(read, failure) {
|
|
1075
1150
|
const relay = useRelay();
|
|
1076
1151
|
const [state, setState] = useState11({ status: "loading" });
|
|
1077
|
-
const refresh =
|
|
1152
|
+
const refresh = useCallback8(async () => {
|
|
1078
1153
|
try {
|
|
1079
1154
|
setState({ status: "ready", items: await read(relay) });
|
|
1080
1155
|
} catch (cause) {
|
|
@@ -1132,6 +1207,7 @@ export {
|
|
|
1132
1207
|
useRelay,
|
|
1133
1208
|
useSignIn,
|
|
1134
1209
|
useSignInMethods,
|
|
1210
|
+
useSignInOptions,
|
|
1135
1211
|
useSignInWallets,
|
|
1136
1212
|
useSignOut,
|
|
1137
1213
|
useTieredRewards,
|