Skip to content

Commit

Permalink
refactor: type improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Aug 9, 2023
1 parent 8c11fe1 commit 1b49636
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 34 deletions.
3 changes: 2 additions & 1 deletion src/actions/test/sendUnsignedTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ test('sends unsigned transaction', async () => {
})

test('sends unsigned transaction (w/ formatter)', async () => {
const chain = defineChain(testClient.chain, {
const chain = defineChain({
...testClient.chain,
formatters: {
transactionRequest: celo.formatters!.transactionRequest,
},
Expand Down
29 changes: 12 additions & 17 deletions src/actions/wallet/sendTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,13 @@ test('sends transaction', async () => {
test('sends transaction (w/ formatter)', async () => {
await setup()

const chain = defineChain(
{
...localhost,
id: 1,
const chain = defineChain({
...localhost,
id: 1,
formatters: {
transactionRequest: celo.formatters!.transactionRequest,
},
{
formatters: {
transactionRequest: celo.formatters!.transactionRequest,
},
},
)
})

expect(
await getBalance(publicClient, { address: targetAccount.address }),
Expand Down Expand Up @@ -154,14 +150,13 @@ test('sends transaction (w/ serializer)', async () => {
},
)

const chain = defineChain(
{ ...localhost, id: 1 },
{
serializers: {
transaction: serializer,
},
const chain = defineChain({
...localhost,
id: 1,
serializers: {
transaction: serializer,
},
)
})

await expect(() =>
sendTransaction(walletClient, {
Expand Down
27 changes: 18 additions & 9 deletions src/chains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ export const aurora = /*#__PURE__*/ defineChain(chains.aurora)
export const auroraTestnet = /*#__PURE__*/ defineChain(chains.auroraTestnet)
export const avalanche = /*#__PURE__*/ defineChain(chains.avalanche)
export const avalancheFuji = /*#__PURE__*/ defineChain(chains.avalancheFuji)
export const base = /*#__PURE__*/ defineChain(chains.base, {
export const base = /*#__PURE__*/ defineChain({
...chains.base,
fees: feesOptimism,
formatters: formattersOptimism,
})
export const baseGoerli = /*#__PURE__*/ defineChain(chains.baseGoerli, {
export const baseGoerli = /*#__PURE__*/ defineChain({
...chains.baseGoerli,
fees: feesOptimism,
formatters: formattersOptimism,
})
Expand All @@ -26,15 +28,18 @@ export const bronosTestnet = /*#__PURE__*/ defineChain(chains.bronosTestnet)
export const bsc = /*#__PURE__*/ defineChain(chains.bsc)
export const bscTestnet = /*#__PURE__*/ defineChain(chains.bscTestnet)
export const canto = /*#__PURE__*/ defineChain(chains.canto)
export const celo = /*#__PURE__*/ defineChain(chains.celo, {
export const celo = /*#__PURE__*/ defineChain({
...chains.celo,
formatters: formattersCelo,
serializers: serializersCelo,
})
export const celoAlfajores = /*#__PURE__*/ defineChain(chains.celoAlfajores, {
export const celoAlfajores = /*#__PURE__*/ defineChain({
...chains.celoAlfajores,
formatters: formattersCelo,
serializers: serializersCelo,
})
export const celoCannoli = /*#__PURE__*/ defineChain(chains.celoCannoli, {
export const celoCannoli = /*#__PURE__*/ defineChain({
...chains.celoCannoli,
formatters: formattersCelo,
serializers: serializersCelo,
})
Expand Down Expand Up @@ -78,11 +83,13 @@ export const moonbeam = /*#__PURE__*/ defineChain(chains.moonbeam)
export const moonriver = /*#__PURE__*/ defineChain(chains.moonriver)
export const nexi = /*#__PURE__*/ defineChain(chains.nexi)
export const okc = /*#__PURE__*/ defineChain(chains.okc)
export const optimism = /*#__PURE__*/ defineChain(chains.optimism, {
export const optimism = /*#__PURE__*/ defineChain({
...chains.optimism,
fees: feesOptimism,
formatters: formattersOptimism,
})
export const optimismGoerli = /*#__PURE__*/ defineChain(chains.optimismGoerli, {
export const optimismGoerli = /*#__PURE__*/ defineChain({
...chains.optimismGoerli,
fees: feesOptimism,
formatters: formattersOptimism,
})
Expand Down Expand Up @@ -145,11 +152,13 @@ export const xdcTestnet = /*#__PURE__*/ defineChain(chains.xdcTestnet)
export const zhejiang = /*#__PURE__*/ defineChain(chains.zhejiang)
export const zkSync = /*#__PURE__*/ defineChain(chains.zkSync)
export const zkSyncTestnet = /*#__PURE__*/ defineChain(chains.zkSyncTestnet)
export const zora = /*#__PURE__*/ defineChain(chains.zora, {
export const zora = /*#__PURE__*/ defineChain({
...chains.zora,
fees: feesOptimism,
formatters: formattersOptimism,
})
export const zoraTestnet = /*#__PURE__*/ defineChain(chains.zoraTestnet, {
export const zoraTestnet = /*#__PURE__*/ defineChain({
...chains.zoraTestnet,
fees: feesOptimism,
formatters: formattersOptimism,
})
Expand Down
14 changes: 7 additions & 7 deletions src/utils/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ export function assertCurrentChain({
}

export function defineChain<
TChain extends Chain,
TFormatters extends ChainFormatters,
formatters extends ChainFormatters,
chain extends Chain<formatters>,
>(
chain: TChain,
config?: Pick<Chain<TFormatters>, 'fees' | 'formatters' | 'serializers'>,
) {
chain: chain | Chain<formatters>,
/** @deprecated extend from the `chain` param instead. */
config?: Pick<Chain<formatters>, 'formatters' | 'serializers'>,
): chain {
return {
...chain,
fees: config?.fees,
formatters: config?.formatters,
serializers: config?.serializers,
}
} as chain
}

export function getChainContractAddress({
Expand Down

0 comments on commit 1b49636

Please sign in to comment.