Skip to content

Commit 3d5e207

Browse files
authored
Merge pull request #758 from magiclabs/chris/fix-farcaster-deps
fix: remove farcaster deps
2 parents ddb112b + c0b30c3 commit 3d5e207

5 files changed

Lines changed: 111 additions & 429 deletions

File tree

‎package.json‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
"@types/rimraf": "^3.0.2",
3030
"@types/tsc-watch": "^4.2.0",
3131
"@types/whatwg-url": "^6.4.0",
32-
"@typescript-eslint/eslint-plugin": "^7.13.1",
33-
"@typescript-eslint/parser": "^7.13.1",
32+
"@typescript-eslint/eslint-plugin": "~3.4.0",
3433
"auto": "^11.1.2",
3534
"babel-jest": "^27.0.6",
3635
"brotli-size": "^4.0.0",
@@ -70,7 +69,7 @@
7069
"ts-node": "^10.2.0",
7170
"tsc-watch": "^4.2.9",
7271
"tslib": "^2.3.1",
73-
"typescript": "^5.4.5",
72+
"typescript": "~4.5.2",
7473
"wsrun": "^5.2.1",
7574
"zombi": "^3.3.0"
7675
},

‎packages/@magic-ext/farcaster/package.json‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,10 @@
2424
},
2525
"externals": {
2626
"include": [
27-
"@magic-sdk/commons",
28-
"viem"
29-
],
30-
"exclude": [
31-
"ethers"
27+
"@magic-sdk/commons"
3228
]
3329
},
3430
"devDependencies": {
3531
"@magic-sdk/commons": "^24.0.5"
36-
},
37-
"dependencies": {
38-
"@farcaster/auth-client": "^0.1.1",
39-
"ethers": "^6.13.0",
40-
"viem": "^2.15.1"
4132
}
4233
}

‎packages/@magic-ext/farcaster/src/index.ts‎

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Extension } from '@magic-sdk/commons';
2-
import type { CreateChannelAPIResponse, AuthenticateAPIResponse, AuthClientError } from '@farcaster/auth-client';
32
import { FarcasterPayloadMethod } from './types';
43
import { isMobile } from './utils';
54

@@ -15,9 +14,58 @@ const FarcasterLoginEventOnReceived = {
1514
Failed: 'failed',
1615
} as const;
1716

17+
interface CreateChannelAPIResponse {
18+
channelToken: string;
19+
url: string;
20+
nonce: string;
21+
}
22+
23+
type Hex = `0x${string}`;
24+
25+
interface StatusAPIResponse {
26+
state: 'pending' | 'completed';
27+
nonce: string;
28+
url: string;
29+
message?: string;
30+
signature?: `0x${string}`;
31+
fid?: number;
32+
username?: string;
33+
bio?: string;
34+
displayName?: string;
35+
pfpUrl?: string;
36+
verifications?: Hex[];
37+
custody?: Hex;
38+
}
39+
40+
type AuthClientErrorCode =
41+
| 'unauthenticated'
42+
| 'unauthorized'
43+
| 'bad_request'
44+
| 'bad_request.validation_failure'
45+
| 'not_found'
46+
| 'not_implemented'
47+
| 'unavailable'
48+
| 'unknown';
49+
50+
interface AuthClientErrorOpts {
51+
message: string;
52+
cause: Error | AuthClientError;
53+
presentable: boolean;
54+
}
55+
56+
declare class AuthClientError extends Error {
57+
readonly errCode: AuthClientErrorCode;
58+
readonly presentable: boolean;
59+
/**
60+
* @param errCode - the AuthClientError code for this message
61+
* @param context - a message, another Error, or a AuthClientErrorOpts
62+
*/
63+
constructor(errCode: AuthClientErrorCode, context: Partial<AuthClientErrorOpts> | string | Error);
64+
}
65+
1866
type FarcasterLoginEventHandlers = {
1967
[FarcasterLoginEventOnReceived.OpenChannel]: (channel: CreateChannelAPIResponse) => void;
20-
[FarcasterLoginEventOnReceived.Success]: (data: AuthenticateAPIResponse) => void;
68+
[FarcasterLoginEventOnReceived.Success]: (data: StatusAPIResponse) => void;
2169
[FarcasterLoginEventOnReceived.Failed]: (error: AuthClientError) => void;
2270
};
2371

@@ -37,8 +85,8 @@ export class FarcasterExtension extends Extension.Internal<'farcaster'> {
3785
'Content-Type': 'application/json',
3886
},
3987
body: JSON.stringify({
40-
domain: location.host,
41-
siweUri: location.origin,
88+
domain: window.location.host,
89+
siweUri: window.location.origin,
4290
}),
4391
}).then<CreateChannelAPIResponse>((r) => r.json());
4492

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

54102
const showUI = params?.showUI ?? DEFAULT_SHOW_UI;
55103

56-
const domain = location.origin;
104+
const domain = window.location.origin;
57105

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

71119
if (isMobile()) {
72-
location.href = this.channel.url;
120+
window.location.href = this.channel.url;
73121
}
74122

75123
return handle;

‎scripts/bin/lint.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ async function main() {
99
const PKG = await promptForPackage();
1010

1111
printSeparator('Linting TypeScripts');
12-
await execa('yarn', ['wsrun', '--serial', 'eslint', '--fix'], {
12+
await execa('yarn', ['wsrun', '--serial', 'eslint', '--fix', './**/*.ts', '.'], {
1313
stdio: 'inherit',
1414
env: { PKG },
1515
});

0 commit comments

Comments
 (0)