Skip to content

Commit

Permalink
chore: polish (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zizzamia authored Jun 13, 2024
1 parent 8b85738 commit c0a9d2b
Show file tree
Hide file tree
Showing 99 changed files with 985 additions and 350 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
run: npm install

- name: Kit Format Check
run: npm run format:check
run: npm run ci:format
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"javascript": {
"formatter": {
"enabled": true,
"lineWidth": 100,
"lineWidth": 80,
"arrowParentheses": "always",
"bracketSameLine": false,
"quoteStyle": "single",
Expand Down
21 changes: 6 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
"license": "MIT",
"scripts": {
"build": "packemon build --addEngines --addFiles --declaration && npx packemon validate --no-license --no-people --no-repo && tailwindcss -i ./src/styles/index.css -o ./src/tailwind.css --minify && tailwindcss -i ./src/styles/index-with-tailwind.css -o ./src/styles.css --minify",
"watch": "tailwind -i ./src/styles/index-with-tailwind.css -o ./src/styles.css --watch",
"check": "yarn format",
"format": "prettier --log-level warn --write .",
"format:check": "prettier --check .",
"format:biome": "biome format --write .",
"ci:format": "biome ci --linter-enabled=false --organize-imports-enabled=false",
"format": "biome format --write .",
"lint": "biome lint --write .",
"lint:unsafe": "biome lint --write --unsafe .",
"test": "jest --testPathIgnorePatterns=\\.integ\\.",
Expand All @@ -19,7 +16,8 @@
"test:coverage": "jest . --coverage ",
"release:check": "changeset status --verbose --since=origin/main",
"release:publish": "yarn install && yarn build && changeset publish",
"release:version": "changeset version && yarn install --immutable"
"release:version": "changeset version && yarn install --immutable",
"watch": "tailwind -i ./src/styles/index-with-tailwind.css -o ./src/styles.css --watch"
},
"peerDependencies": {
"@tanstack/react-query": "^5",
Expand Down Expand Up @@ -72,20 +70,13 @@
"packemon": [
{
"bundle": false,
"platform": [
"browser"
]
"platform": ["browser"]
}
],
"publishConfig": {
"access": "public"
},
"files": [
"esm/**/*",
"lib/**/*",
"src/",
"src/**/*"
],
"files": ["esm/**/*", "lib/**/*", "src/", "src/**/*"],
"main": "./esm/index.js",
"types": "./esm/index.d.ts",
"module": "./esm/index.js",
Expand Down
8 changes: 5 additions & 3 deletions src/OnchainKitConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { baseSepolia } from 'viem/chains';
import { getOnchainKitConfig, setOnchainKitConfig } from './OnchainKitConfig';
import { getRPCUrl } from './getRPCUrl';
import { getRPCUrl } from './network/getRPCUrl';

describe('OnchainKitConfig', () => {
it('should have a get function to access the config', () => {
Expand All @@ -23,7 +23,8 @@ describe('OnchainKitConfig', () => {
const chain = baseSepolia;
const schemaId = '0x123';
const apiKey = 'test-api-key';
const rpcUrl = 'https://api.developer.coinbase.com/rpc/v1/base-sepolia/test-api-key';
const rpcUrl =
'https://api.developer.coinbase.com/rpc/v1/base-sepolia/test-api-key';
setOnchainKitConfig({ chain, schemaId, apiKey });
expect(getOnchainKitConfig('chain')).toEqual(chain);
expect(getOnchainKitConfig('schemaId')).toEqual(schemaId);
Expand All @@ -35,7 +36,8 @@ describe('OnchainKitConfig', () => {
const chain = baseSepolia;
const schemaId = '0x123';
const apiKey = 'updated-api-key';
const rpcUrl = 'https://api.developer.coinbase.com/rpc/v1/base-sepolia/updated-api-key';
const rpcUrl =
'https://api.developer.coinbase.com/rpc/v1/base-sepolia/updated-api-key';
setOnchainKitConfig({ chain, schemaId, apiKey, rpcUrl });
expect(getOnchainKitConfig('chain')).toEqual(chain);
expect(getOnchainKitConfig('schemaId')).toEqual(schemaId);
Expand Down
9 changes: 7 additions & 2 deletions src/OnchainKitProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { checkHashLength } from './utils/checkHashLength';
import { ONCHAIN_KIT_CONFIG, setOnchainKitConfig } from './OnchainKitConfig';
import type { OnchainKitContextType, OnchainKitProviderReact } from './types';

export const OnchainKitContext = createContext<OnchainKitContextType>(ONCHAIN_KIT_CONFIG);
export const OnchainKitContext =
createContext<OnchainKitContextType>(ONCHAIN_KIT_CONFIG);

/**
* Provides the OnchainKit React Context to the app.
Expand All @@ -30,5 +31,9 @@ export function OnchainKitProvider({
setOnchainKitConfig(onchainKitConfig);
return onchainKitConfig;
}, [address, chain, schemaId, apiKey, rpcUrl]);
return <OnchainKitContext.Provider value={value}>{children}</OnchainKitContext.Provider>;
return (
<OnchainKitContext.Provider value={value}>
{children}
</OnchainKitContext.Provider>
);
}
39 changes: 30 additions & 9 deletions src/farcaster/getFarcasterUserAddress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ describe('getFarcasterUserAddress function', () => {

it('should return both custody and verified addresses by default', async () => {
const expectedCustodyAddress = 'mock-custody-address';
(getCustodyAddressForFidNeynar as jest.Mock).mockResolvedValue(expectedCustodyAddress);
(getVerifiedAddressesForFidNeynar as jest.Mock).mockResolvedValue([expectedCustodyAddress]);
(getCustodyAddressForFidNeynar as jest.Mock).mockResolvedValue(
expectedCustodyAddress,
);
(getVerifiedAddressesForFidNeynar as jest.Mock).mockResolvedValue([
expectedCustodyAddress,
]);

const result = await getFarcasterUserAddress(123);
expect(result).toEqual({
Expand All @@ -40,9 +44,16 @@ describe('getFarcasterUserAddress function', () => {

it('should return both custodyAddress and verifiedAddresses when both options are true', async () => {
const expectedCustodyAddress = 'mock-custody-address';
const expectedVerifiedAddresses = ['mock-verified-address-1', 'mock-verified-address-2'];
(getCustodyAddressForFidNeynar as jest.Mock).mockResolvedValue(expectedCustodyAddress);
(getVerifiedAddressesForFidNeynar as jest.Mock).mockResolvedValue(expectedVerifiedAddresses);
const expectedVerifiedAddresses = [
'mock-verified-address-1',
'mock-verified-address-2',
];
(getCustodyAddressForFidNeynar as jest.Mock).mockResolvedValue(
expectedCustodyAddress,
);
(getVerifiedAddressesForFidNeynar as jest.Mock).mockResolvedValue(
expectedVerifiedAddresses,
);
const result = await getFarcasterUserAddress(123, {
hasCustodyAddress: true,
hasVerifiedAddresses: true,
Expand All @@ -55,16 +66,23 @@ describe('getFarcasterUserAddress function', () => {

it('should only return custodyAddress when hasVerifiedAddresses is false', async () => {
const expectedCustodyAddress = 'mock-custody-address';
(getCustodyAddressForFidNeynar as jest.Mock).mockResolvedValue(expectedCustodyAddress);
(getCustodyAddressForFidNeynar as jest.Mock).mockResolvedValue(
expectedCustodyAddress,
);
const result = await getFarcasterUserAddress(123, {
hasVerifiedAddresses: false,
});
expect(result).toEqual({ custodyAddress: expectedCustodyAddress });
});

it('should only return verifiedAddresses when hasCustodyAddress is false', async () => {
const expectedVerifiedAddresses = ['mock-verified-address-1', 'mock-verified-address-2'];
(getVerifiedAddressesForFidNeynar as jest.Mock).mockResolvedValue(expectedVerifiedAddresses);
const expectedVerifiedAddresses = [
'mock-verified-address-1',
'mock-verified-address-2',
];
(getVerifiedAddressesForFidNeynar as jest.Mock).mockResolvedValue(
expectedVerifiedAddresses,
);
const result = await getFarcasterUserAddress(123, {
hasCustodyAddress: false,
});
Expand All @@ -74,6 +92,9 @@ describe('getFarcasterUserAddress function', () => {
it('should call getCustodyAddressForFidNeynar and getVerifiedAddressesForFidNeynar with the default neynarApiKey if not provided', async () => {
await getFarcasterUserAddress(123);
expect(getCustodyAddressForFidNeynar).toHaveBeenCalledWith(123, undefined);
expect(getVerifiedAddressesForFidNeynar).toHaveBeenCalledWith(123, undefined);
expect(getVerifiedAddressesForFidNeynar).toHaveBeenCalledWith(
123,
undefined,
);
});
});
10 changes: 8 additions & 2 deletions src/farcaster/getFarcasterUserAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,20 @@ async function getFarcasterUserAddress(
const response: GetFarcasterUserAddressResponse = {};

if (hasCustodyAddress) {
const custodyAddress = await getCustodyAddressForFidNeynar(fid, options?.neynarApiKey);
const custodyAddress = await getCustodyAddressForFidNeynar(
fid,
options?.neynarApiKey,
);
if (custodyAddress) {
response.custodyAddress = custodyAddress;
}
}

if (hasVerifiedAddresses) {
const verifiedAddresses = await getVerifiedAddressesForFidNeynar(fid, options?.neynarApiKey);
const verifiedAddresses = await getVerifiedAddressesForFidNeynar(
fid,
options?.neynarApiKey,
);
if (verifiedAddresses) {
response.verifiedAddresses = verifiedAddresses;
}
Expand Down
Loading

0 comments on commit c0a9d2b

Please sign in to comment.