Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove farcaster deps #758

Merged
merged 4 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"@types/rimraf": "^3.0.2",
"@types/tsc-watch": "^4.2.0",
"@types/whatwg-url": "^6.4.0",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1",
"@typescript-eslint/eslint-plugin": "~3.4.0",
"auto": "^11.1.2",
"babel-jest": "^27.0.6",
"brotli-size": "^4.0.0",
Expand Down Expand Up @@ -70,7 +69,7 @@
"ts-node": "^10.2.0",
"tsc-watch": "^4.2.9",
"tslib": "^2.3.1",
"typescript": "^5.4.5",
"typescript": "~4.5.2",
"wsrun": "^5.2.1",
"zombi": "^3.3.0"
},
Expand Down
11 changes: 1 addition & 10 deletions packages/@magic-ext/farcaster/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,10 @@
},
"externals": {
"include": [
"@magic-sdk/commons",
"viem"
],
"exclude": [
"ethers"
"@magic-sdk/commons"
]
},
"devDependencies": {
"@magic-sdk/commons": "^24.0.5"
},
"dependencies": {
"@farcaster/auth-client": "^0.1.1",
"ethers": "^6.13.0",
"viem": "^2.15.1"
}
}
60 changes: 54 additions & 6 deletions packages/@magic-ext/farcaster/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Extension } from '@magic-sdk/commons';
import type { CreateChannelAPIResponse, AuthenticateAPIResponse, AuthClientError } from '@farcaster/auth-client';
import { FarcasterPayloadMethod } from './types';
import { isMobile } from './utils';

Expand All @@ -15,9 +14,58 @@ const FarcasterLoginEventOnReceived = {
Failed: 'failed',
} as const;

interface CreateChannelAPIResponse {
channelToken: string;
url: string;
nonce: string;
}

type Hex = `0x${string}`;

interface StatusAPIResponse {
state: 'pending' | 'completed';
nonce: string;
url: string;
message?: string;
signature?: `0x${string}`;
fid?: number;
username?: string;
bio?: string;
displayName?: string;
pfpUrl?: string;
verifications?: Hex[];
custody?: Hex;
}

type AuthClientErrorCode =
| 'unauthenticated'
| 'unauthorized'
| 'bad_request'
| 'bad_request.validation_failure'
| 'not_found'
| 'not_implemented'
| 'unavailable'
| 'unknown';

interface AuthClientErrorOpts {
message: string;
cause: Error | AuthClientError;
presentable: boolean;
}

declare class AuthClientError extends Error {
readonly errCode: AuthClientErrorCode;
readonly presentable: boolean;
/**
* @param errCode - the AuthClientError code for this message
* @param context - a message, another Error, or a AuthClientErrorOpts
*/
constructor(errCode: AuthClientErrorCode, context: Partial<AuthClientErrorOpts> | string | Error);
}

type FarcasterLoginEventHandlers = {
[FarcasterLoginEventOnReceived.OpenChannel]: (channel: CreateChannelAPIResponse) => void;
[FarcasterLoginEventOnReceived.Success]: (data: AuthenticateAPIResponse) => void;
[FarcasterLoginEventOnReceived.Success]: (data: StatusAPIResponse) => void;
[FarcasterLoginEventOnReceived.Failed]: (error: AuthClientError) => void;
};

Expand All @@ -37,8 +85,8 @@ export class FarcasterExtension extends Extension.Internal<'farcaster'> {
'Content-Type': 'application/json',
},
body: JSON.stringify({
domain: location.host,
siweUri: location.origin,
domain: window.location.host,
siweUri: window.location.origin,
}),
}).then<CreateChannelAPIResponse>((r) => r.json());

Expand All @@ -53,7 +101,7 @@ export class FarcasterExtension extends Extension.Internal<'farcaster'> {

const showUI = params?.showUI ?? DEFAULT_SHOW_UI;

const domain = location.origin;
const domain = window.location.origin;

const payload = this.utils.createJsonRpcRequestPayload(FarcasterPayloadMethod.FarcasterShowQR, [
{
Expand All @@ -69,7 +117,7 @@ export class FarcasterExtension extends Extension.Internal<'farcaster'> {
const handle = this.request<string, FarcasterLoginEventHandlers>(payload);

if (isMobile()) {
location.href = this.channel.url;
window.location.href = this.channel.url;
}

return handle;
Expand Down
2 changes: 1 addition & 1 deletion scripts/bin/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async function main() {
const PKG = await promptForPackage();

printSeparator('Linting TypeScripts');
await execa('yarn', ['wsrun', '--serial', 'eslint', '--fix'], {
await execa('yarn', ['wsrun', '--serial', 'eslint', '--fix', './**/*.ts', '.'], {
stdio: 'inherit',
env: { PKG },
});
Expand Down
Loading
Loading