Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat: add onAuthSuccess callback for paper wallet
  • Loading branch information
ElasticBottle committed Oct 20, 2023
commit df2f553a08c139ea14b8a9c360c17f3d47a675d9
2 changes: 1 addition & 1 deletion packages/react/src/wallet/wallets/paper/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type PaperConfig = Omit<
"chain" | "clientId"
> & {
/**
* If true, the wallet will be tagged as "reccomended" in ConnectWallet Modal
* If true, the wallet will be tagged as "recomended" in ConnectWallet Modal
*/
recommended?: boolean;
};
Expand Down
2 changes: 2 additions & 0 deletions packages/wallets/src/evm/connectors/paper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class PaperWalletConnector extends Connector<Record<string, never>> {
clientId: this.options.clientId,
chain: "Ethereum",
styles: this.options.styles,
onAuthSuccess: this.options.onAuthSuccess,
}),
);
} catch (err) {
Expand Down Expand Up @@ -136,6 +137,7 @@ export class PaperWalletConnector extends Connector<Record<string, never>> {
if (!this.user) {
throw new Error("Error connecting User");
}
this.options.onAuth(this.user);

if (options?.chainId) {
this.switchChain(options.chainId);
Expand Down
3 changes: 3 additions & 0 deletions packages/wallets/src/evm/connectors/paper/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
AuthAndWalletRpcReturnType,
PaperConstructorType,
RecoveryShareManagement,
} from "@paperxyz/embedded-wallet-service-sdk";
Expand All @@ -14,6 +15,7 @@ export type PaperWalletAdditionalOptions = {
styles?: PaperConstructorType<RecoveryShareManagement>["styles"];
paperClientId?: string;
clientId?: string;
onAuthSuccess?: (authResult: AuthAndWalletRpcReturnType) => void;
};

export interface PaperWalletConnectorOptions {
Expand All @@ -22,6 +24,7 @@ export interface PaperWalletConnectorOptions {
chains: Chain[];
advancedOptions?: PaperAdvanceOptions;
styles?: PaperConstructorType<RecoveryShareManagement>["styles"];
onAuthSuccess?: (authResult: AuthAndWalletRpcReturnType) => void;
}

export interface PaperWalletConnectionArgs {
Expand Down
3 changes: 3 additions & 0 deletions packages/wallets/src/evm/wallets/paper-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class PaperWallet extends AbstractClientWallet<

paperClientId: string;
chain: PaperWalletAdditionalOptions_["chain"];
onAuthSuccess: PaperWalletAdditionalOptions_["onAuth"];

constructor(options: PaperWalletOptions) {
super(PaperWallet.id, {
Expand Down Expand Up @@ -84,6 +85,7 @@ export class PaperWallet extends AbstractClientWallet<

// cast is okay because we assert that either clientId or paperClientId is defined above
this.paperClientId = (options.paperClientId ?? options.clientId) as string;
this.onAuthSuccess = options.onAuthSuccess;
}
private isClientIdLegacyPaper(clientId: string): boolean {
return clientId.indexOf("-") > 0 && clientId.length === 36;
Expand All @@ -96,6 +98,7 @@ export class PaperWallet extends AbstractClientWallet<
clientId: this.paperClientId,
chain: this.chain,
chains: this.chains,
onAuthSuccess: this.onAuthSuccess,
advancedOptions: {
recoveryShareManagement:
this.options?.advancedOptions?.recoveryShareManagement,
Expand Down