Skip to content

Commit

Permalink
Prettier format (#14)
Browse files Browse the repository at this point in the history
* Prettier format

* Updating format command to work on tsx files as well
  • Loading branch information
corbanbrook authored Apr 10, 2024
1 parent f33e369 commit 9256d91
Show file tree
Hide file tree
Showing 75 changed files with 739 additions and 822 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lint:fix": "eslint -c .eslintrc.js --fix 'packages/**/src/**/*.{ts,tsx}'",
"lint:tests": "eslint -c .eslintrc.js 'packages/**/tests/**/*.{ts,tsx}'",
"lint:tests:fix": "eslint -c .eslintrc.js 'packages/**/tests/**/*.{ts,tsx}'",
"format": "prettier --write packages/**/src/**/*.ts packages/**/tests/**/*.ts",
"format": "prettier --write packages/**/src/**/*.{ts,tsx}",
"audit:fix": "pnpm audit --fix",
"typecheck": "tsc --noEmit",
"coverage": "rimraf ./coverage && rimraf ./.nyc_output && nyc pnpm test",
Expand Down
105 changes: 50 additions & 55 deletions packages/checkout/src/api/data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import { ethers } from 'ethers'
import { getPaperNetworkName } from '../utils'

export interface GetTokenBalancesArgs {
accountAddress: string,
accountAddress: string
chainId: number
}

export const getNativeToken = async ({ accountAddress, chainId }: GetTokenBalancesArgs) => {
try {
const { indexerClient } = await getNetworkConfigAndClients(chainId)
const { indexerClient } = await getNetworkConfigAndClients(chainId)

const res = await indexerClient.getEtherBalance({ accountAddress })

const tokenBalance: TokenBalance = {
chainId,
contractAddress: ethers.constants.AddressZero,
Expand All @@ -25,18 +25,18 @@ export const getNativeToken = async ({ accountAddress, chainId }: GetTokenBalanc
contractType: ContractType.UNKNOWN,
blockHash: '',
blockNumber: 0,
tokenID: '',
tokenID: ''
}
return [tokenBalance]
} catch(e) {
} catch (e) {
console.error(e)
return []
}
}

export const getTokenBalances = async ({ accountAddress, chainId }: GetTokenBalancesArgs) => {
try {
const { indexerClient } = await getNetworkConfigAndClients(chainId)
const { indexerClient } = await getNetworkConfigAndClients(chainId)

const res = await indexerClient.getTokenBalances({
accountAddress,
Expand All @@ -45,9 +45,9 @@ export const getTokenBalances = async ({ accountAddress, chainId }: GetTokenBala
verifiedOnly: true
}
})

return res?.balances || []
} catch(e) {
} catch (e) {
console.error(e)
return []
}
Expand All @@ -63,26 +63,26 @@ export const fetchBalances = async ({ accountAddress, chainId }: GetTokenBalance
}),
getTokenBalances({
accountAddress,
chainId,
chainId
})
])
).flat()
return tokenBalances
} catch(e) {
} catch (e) {
console.error(e)
return []
}
}

export interface GetCollectionBalanceArgs {
accountAddress: string,
chainId: number,
accountAddress: string
chainId: number
collectionAddress: string
}

export const fetchCollectionBalance = async ({ accountAddress, chainId, collectionAddress }: GetCollectionBalanceArgs) => {
try {
const { indexerClient } = await getNetworkConfigAndClients(chainId)
const { indexerClient } = await getNetworkConfigAndClients(chainId)

const res = await indexerClient.getTokenBalances({
accountAddress,
Expand All @@ -92,9 +92,9 @@ export const fetchCollectionBalance = async ({ accountAddress, chainId, collecti
verifiedOnly: true
}
})

return res?.balances || []
} catch(e) {
} catch (e) {
console.error(e)
return []
}
Expand All @@ -108,15 +108,15 @@ export const getCoinPrices = async ({ tokens }: GetCoinPricesArgs): Promise<Toke
try {
if (tokens.length === 0) return []
const chainId = tokens[0].chainId

const { apiClient } = await getNetworkConfigAndClients(chainId)

const res = await apiClient.getCoinPrices({
tokens
})

return res?.tokenPrices || []
} catch(e) {
} catch (e) {
console.error(e)
return
}
Expand All @@ -128,48 +128,41 @@ export interface GetTokenMetadataArgs {
contractAddress: string
}

export const fetchTokenMetadata = async ({
chainId,
tokenId,
contractAddress,
}: GetTokenMetadataArgs): Promise<TokenMetadata> => {
export const fetchTokenMetadata = async ({ chainId, tokenId, contractAddress }: GetTokenMetadataArgs): Promise<TokenMetadata> => {
const { metadataClient } = await getNetworkConfigAndClients(chainId)

const response = await metadataClient.getTokenMetadata({
chainID: String(chainId),
contractAddress,
tokenIDs: [tokenId],
tokenIDs: [tokenId]
})

return response.tokenMetadata[0]
}

export const fetchContractInfo = async ({
chainID,
contractAddress,
}: GetContractInfoArgs): Promise<ContractInfo> => {
export const fetchContractInfo = async ({ chainID, contractAddress }: GetContractInfoArgs): Promise<ContractInfo> => {
const { metadataClient } = await getNetworkConfigAndClients(chainID)

const response = await metadataClient.getContractInfo({
chainID,
contractAddress,
contractAddress
})

return response.contractInfo
}

export interface FetchPaperSecretArgs {
chainId: number,
email: string,
abi: string,
contractAddress: string,
recipientAddress: string,
receiptTitle: string,
collectionContractAddress?: string,
methodArguments: MethodArguments,
currency: string,
currencyAmount: string,
methodName: string,
chainId: number
email: string
abi: string
contractAddress: string
recipientAddress: string
receiptTitle: string
collectionContractAddress?: string
methodArguments: MethodArguments
currency: string
currencyAmount: string
methodName: string
}

export interface MethodArguments {
Expand All @@ -187,9 +180,9 @@ export const fetchPaperSecret = async ({
currency,
currencyAmount,
methodName,
recipientAddress,
recipientAddress
}: FetchPaperSecretArgs) => {
const { network, apiClient } = await getNetworkConfigAndClients(chainId)
const { network, apiClient } = await getNetworkConfigAndClients(chainId)

// @ts-ignore-next-line
const chainName = getPaperNetworkName(network)
Expand All @@ -203,24 +196,26 @@ export const fetchPaperSecret = async ({
args: methodArguments,
payment: {
currency,
value: `${currencyAmount} * $QUANTITY`,
value: `${currencyAmount} * $QUANTITY`
},
name: methodName,
name: methodName
},
walletAddress: recipientAddress,
...(collectionContractAddress ? {
contractArgs: {
collectionContractAddress
}
} : {}),
...(collectionContractAddress
? {
contractArgs: {
collectionContractAddress
}
}
: {})
})

const { secret } = await apiClient.paperSessionSecret2({
chainName,
contractAddress,
abi,
paramsJson,
chainName,
contractAddress,
abi,
paramsJson
})

return secret
}
}
2 changes: 1 addition & 1 deletion packages/checkout/src/api/index.tsx
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './data'
export * from './data'
20 changes: 10 additions & 10 deletions packages/checkout/src/contexts/CheckoutModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { MethodArguments } from '../api'
import { createGenericContext, Theme } from '@0xsequence/kit'

interface CoinQuantity {
contractAddress: string,
amountRequiredRaw: string,
contractAddress: string
amountRequiredRaw: string
}

interface OrderSummaryItem {
contractAddress: string,
quantityRaw: string,
contractAddress: string
quantityRaw: string
tokenId: string
}

Expand All @@ -28,12 +28,12 @@ export interface CheckoutSettings {
email?: string
onSuccess?: (transactionHash: string) => void
onError?: (error: Error) => void
},
}
cryptoCheckout?: {
chainId: number,
triggerTransaction: () => void,
coinQuantity: CoinQuantity,
},
chainId: number
triggerTransaction: () => void
coinQuantity: CoinQuantity
}
orderSummaryItems: OrderSummaryItem[]
}

Expand All @@ -44,4 +44,4 @@ type CheckoutModalContext = {
theme: Theme
}

export const [useCheckoutModalContext, CheckoutModalContextProvider] = createGenericContext<CheckoutModalContext>()
export const [useCheckoutModalContext, CheckoutModalContextProvider] = createGenericContext<CheckoutModalContext>()
21 changes: 13 additions & 8 deletions packages/checkout/src/contexts/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import React from 'react'
import { createGenericContext } from '@0xsequence/kit'

export interface SelectCheckoutNavigation {
location: 'select-method-checkout',
location: 'select-method-checkout'
}

export interface TransactionFormNavigation {
location: 'transaction-form',
location: 'transaction-form'
}

export interface TransactionSuccessParams {
transactionHash: string
}

export interface TransactionSuccessNavigation {
location: 'transaction-success',
location: 'transaction-success'
params: TransactionSuccessParams
}

Expand All @@ -23,7 +23,7 @@ export interface TransactionErrorParams {
}

export interface TransactionErrorNavigation {
location: 'transaction-error',
location: 'transaction-error'
params: TransactionErrorParams
}

Expand All @@ -32,17 +32,22 @@ export interface TransactionPendingParams {
}

export interface TransactionPendingNavigation {
location: 'transaction-pending',
location: 'transaction-pending'
params: TransactionPendingParams
}

export type Navigation = TransactionFormNavigation | TransactionSuccessNavigation | TransactionErrorNavigation | TransactionPendingNavigation | SelectCheckoutNavigation
export type Navigation =
| TransactionFormNavigation
| TransactionSuccessNavigation
| TransactionErrorNavigation
| TransactionPendingNavigation
| SelectCheckoutNavigation

export type History = Navigation[]

type NavigationContext = {
setHistory: (history: History) => void
history: History,
history: History
}

export const [useNavigationContext,NavigationContextProvider] = createGenericContext<NavigationContext>()
export const [useNavigationContext, NavigationContextProvider] = createGenericContext<NavigationContext>()
2 changes: 1 addition & 1 deletion packages/checkout/src/contexts/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './CheckoutModal'
export * from './Navigation'
export * from './Navigation'
6 changes: 3 additions & 3 deletions packages/checkout/src/hooks/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
GetCoinPricesArgs,
fetchTokenMetadata,
GetTokenMetadataArgs,
fetchContractInfo,
fetchContractInfo
} from '../api/data'

export const time = {
Expand Down Expand Up @@ -46,7 +46,7 @@ export const useCoinPrices = (args: GetCoinPricesArgs): UseQueryResult<TokenPric
staleTime: 1 * time.oneMinute,
enabled: args.tokens.length > 0
})

export const useTokenMetadata = (args: GetTokenMetadataArgs): UseQueryResult<TokenMetadata> =>
useQuery({
queryKey: ['useTokenMetadata', args],
Expand All @@ -63,4 +63,4 @@ export const useContractInfo = (args: GetContractInfoArgs): UseQueryResult<Contr
retry: true,
staleTime: 60 * time.oneMinute,
enabled: !!args.chainID && !!args.contractAddress
})
})
2 changes: 1 addition & 1 deletion packages/checkout/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './useCheckoutModal'
export * from './data'
export * from './useNavigation'
export * from './useModalTheme'
export * from './useModalTheme'
2 changes: 1 addition & 1 deletion packages/checkout/src/hooks/useCheckoutModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export const useCheckoutModal = () => {
const { triggerCheckout, closeCheckout, settings } = useCheckoutModalContext()

return { triggerCheckout, closeCheckout, settings }
}
}
Loading

0 comments on commit 9256d91

Please sign in to comment.