Skip to content

Commit

Permalink
Merge pull request #5 from coinbase/alissa.crane/charge
Browse files Browse the repository at this point in the history
chore: set default charge amount
  • Loading branch information
abcrane123 authored Oct 15, 2024
2 parents 93dcced + 4bc66c8 commit e9b9529
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .env.local.default
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# ~~~
NEXT_PUBLIC_COINBASE_COMMERCE_API_KEY="COMMERCE_API_KEY_1234567890"

NEXT_PUBLIC_GOOGLE_ANALYTICS_ID=GA_TEST_1234567890

# See https://www.coinbase.com/developer-platform/products/base-node
NEXT_PUBLIC_CDP_API_KEY="CDP_API_KEY_1234567890"

# ~~~
NEXT_PUBLIC_ENVIRONMENT=localhost
4 changes: 2 additions & 2 deletions .env.test
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# ~~~
NEXT_PUBLIC_COINBASE_COMMERCE_API_KEY="COMMERCE_API_KEY_1234567890"

NEXT_PUBLIC_GOOGLE_ANALYTICS_ID=GA_TEST_1234567890

# See https://www.coinbase.com/developer-platform/products/base-node
NEXT_PUBLIC_CDP_API_KEY="CDP_API_KEY_1234567890"

# ~~~
NEXT_PUBLIC_ENVIRONMENT=localhost
9 changes: 6 additions & 3 deletions src/components/OnchainStoreCart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ export default function OnchainStoreCart() {
description,
pricing_type: 'fixed_price',
local_price: {
amount: totalSum.toString(),
// NOTE: set to 0 for simulation purposes,
// replace with totalSum.toString() in real app
amount: '0',
currency: 'USD',
},
};
return createCharge(chargeDetails);
}, [createCharge, quantities, totalSum]);
}, [createCharge, quantities]);

return (
<div className="-mx-[50vw] fixed right-1/2 bottom-0 left-1/2 w-screen border-gray-200 border-t bg-white">
Expand All @@ -56,7 +58,8 @@ export default function OnchainStoreCart() {
<PayButton
coinbaseBranded={true}
text="Pay with Crypto"
disabled={!totalSum}
// NOTE: comment back in to disable 0 amount in real app
// disabled={!totalSum}
/>
</Pay>
</div>
Expand Down
4 changes: 1 addition & 3 deletions src/hooks/useCreateCharge.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useCallback } from 'react';
import { COINBASE_COMMERCE_API_KEY } from 'src/config';

const COMMERCE_API_URL = 'https://api.commerce.coinbase.com';
import { COMMERCE_API_URL } from 'src/links';

type Price = {
amount: string;
Expand All @@ -16,7 +15,6 @@ export type ChargeDetails = {

const useCreateCharge = () => {
const createCharge = useCallback(async (chargeDetails: ChargeDetails) => {
console.log({ chargeDetails });
try {
const res = await fetch(`${COMMERCE_API_URL}/charges`, {
method: 'POST',
Expand Down
1 change: 1 addition & 0 deletions src/links.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const COMMERCE_API_URL = 'https://api.commerce.coinbase.com';
export const DISCORD_LINK = 'https://discord.gg/wTJ7besU';
export const FIGMA_LINK =
'https://www.figma.com/community/file/1370194397345450683/onchainkit';
Expand Down

0 comments on commit e9b9529

Please sign in to comment.