Skip to content

Commit

Permalink
docs: fixed running min tc withour .env (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aman035 authored Sep 1, 2023
1 parent 0ba2034 commit 5831caf
Show file tree
Hide file tree
Showing 5 changed files with 595 additions and 544 deletions.
37 changes: 35 additions & 2 deletions packages/examples/sdk-backend-node/src/chat/nftChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ const nftChainId1 = process.env.NFT_CHAIN_ID_1;
const nftContractAddress1 = process.env.NFT_CONTRACT_ADDRESS_1;
const nftTokenId1 = process.env.NFT_TOKEN_ID_1;
const nftHolderWalletPrivatekey1 = process.env.NFT_HOLDER_WALLET_PRIVATE_KEY_1;
const nftSigner1 = new ethers.Wallet(`0x${nftHolderWalletPrivatekey1}`);
const nftSigner1 = nftHolderWalletPrivatekey1
? new ethers.Wallet(`0x${nftHolderWalletPrivatekey1}`)
: undefined;
const nftAccount1 = `nft:eip155:${nftChainId1}:${nftContractAddress1}:${nftTokenId1}`;
const nftProfilePassword1 = process.env.NFT_PROFILE_PASSWORD_1;
const nftChainId2 = process.env.NFT_CHAIN_ID_2;
const nftContractAddress2 = process.env.NFT_CONTRACT_ADDRESS_2;
const nftTokenId2 = process.env.NFT_TOKEN_ID_2;
const nftHolderWalletPrivatekey2 = process.env.NFT_HOLDER_WALLET_PRIVATE_KEY_2;
const nftSigner2 = new ethers.Wallet(`0x${nftHolderWalletPrivatekey2}`);
const nftSigner2 = nftHolderWalletPrivatekey2
? new ethers.Wallet(`0x${nftHolderWalletPrivatekey2}`)
: undefined;
const nftAccount2 = `nft:eip155:${nftChainId2}:${nftContractAddress2}:${nftTokenId2}`;
const nftProfilePassword2 = process.env.NFT_PROFILE_PASSWORD_2;
const nftAccount3 = `nft:eip155:${nftChainId2}:${nftContractAddress2}:10`;
Expand All @@ -46,6 +50,29 @@ const groupDescription = uniqueNamesGenerator({
const groupImage =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAvklEQVR4AcXBsW2FMBiF0Y8r3GQb6jeBxRauYRpo4yGQkMd4A7kg7Z/GUfSKe8703fKDkTATZsJsrr0RlZSJ9r4RLayMvLmJjnQS1d6IhJkwE2bT13U/DBzp5BN73xgRZsJMmM1HOolqb/yWiWpvjJSUiRZWopIykTATZsJs5g+1N6KSMiO1N/5DmAkzYTa9Lh6MhJkwE2ZzSZlo7xvRwson3txERzqJhJkwE2bT6+JhoKTMJ2pvjAgzYSbMfgDlXixqjH6gRgAAAABJRU5ErkJggg==';

const skipExample = () => {
const requiredEnvVars = [
'NFT_CHAIN_ID_1',
'NFT_CONTRACT_ADDRESS_1',
'NFT_TOKEN_ID_1',
'NFT_HOLDER_WALLET_PRIVATE_KEY_1',
'NFT_PROFILE_PASSWORD_1',
'NFT_CHAIN_ID_2',
'NFT_CONTRACT_ADDRESS_2',
'NFT_TOKEN_ID_2',
'NFT_HOLDER_WALLET_PRIVATE_KEY_2',
'NFT_PROFILE_PASSWORD_2',
];

for (const envVar of requiredEnvVars) {
if (!process.env[envVar]) {
return true; // Skip the example if any of the required env vars is missing
}
}

return false; // All required env vars are present, don't skip the example
};

// Push Chat - Run Chat Use cases
export const runNFTChatUseCases = async (): Promise<void> => {
console.log(`
Expand All @@ -55,6 +82,12 @@ export const runNFTChatUseCases = async (): Promise<void> => {
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ████ ██ ██ ██████ ██ ██ ██ ██ ██
`);

if (skipExample()) {
console.log('Skipping examples as required env vars are missing');
return;
}

console.log('PushAPI.user.create');
await PushAPI_nft_user_create();

Expand Down
4 changes: 3 additions & 1 deletion packages/examples/sdk-backend-node/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { ENV } from './types';
dotenv.config();

export const config = {
env: process.env.PUSH_NODE_NETWORK as ENV, // choose ENV.STAGING or ENV.PROD
env: process.env.PUSH_NODE_NETWORK
? (process.env.PUSH_NODE_NETWORK as ENV)
: ('staging' as ENV), // choose ENV.STAGING or ENV.PROD
showAPIResponse: process.env.SHOW_API_RESPONSE === 'true' ? true : false, // choose to show or hide API responses
};
84 changes: 51 additions & 33 deletions packages/examples/sdk-backend-node/src/notification/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@ enum ENV {
const { env, showAPIResponse } = config;

// If you own a channel, you can use your channel address as well
const channelPrivateKey: string = process.env.WALLET_PRIVATE_KEY!;
const channelPrivateKey: string = process.env.WALLET_PRIVATE_KEY;

/***************** SAMPLE SIGNER GENERATION *********************/
/**
* USING VIEM
*/
const signerChannel = createWalletClient({
account: privateKeyToAccount(`0x${channelPrivateKey}`),
chain: goerli,
transport: http(),
});
const channelAddress = signerChannel.account.address;
const signerChannel = channelPrivateKey
? createWalletClient({
account: privateKeyToAccount(`0x${channelPrivateKey}`),
chain: goerli,
transport: http(),
})
: undefined;
const channelAddress = signerChannel
? signerChannel.account.address
: undefined;
// Random Wallet Signers
const signer = createWalletClient({
account: privateKeyToAccount(generatePrivateKey()),
Expand All @@ -55,6 +59,18 @@ const randomWallet1 = privateKeyToAccount(generatePrivateKey()).address;
// const randomWallet1 = ethers.Wallet.createRandom().address;
/************************************************************* */

const skipExample = () => {
const requiredEnvVars = ['WALLET_PRIVATE_KEY'];

for (const envVar of requiredEnvVars) {
if (!process.env[envVar]) {
return true; // Skip the example if any of the required env vars is missing
}
}

return false; // All required env vars are present, don't skip the example
};

// Push Notification - Run Notifications Use cases
export const runNotificaitonsUseCases = async (): Promise<void> => {
console.log(`
Expand All @@ -73,40 +89,42 @@ export const runNotificaitonsUseCases = async (): Promise<void> => {
console.log('PushAPI.user.getSubscriptions');
await PushAPI_user_getSubscriptions();

console.log('PushAPI.channels.getChannel()');
await PushAPI_channels_getChannel();
if (!skipExample()) {
console.log('PushAPI.channels.getChannel()');
await PushAPI_channels_getChannel();

console.log('PushAPI.channels.search()');
await PushAPI_channels_search();
console.log('PushAPI.channels.search()');
await PushAPI_channels_search();

console.log('PushAPI.channels.subscribe()');
await PushAPI_channels_subscribe();
console.log('PushAPI.channels.subscribe()');
await PushAPI_channels_subscribe();

console.log('PushAPI.channels.unsubscribe()');
await PushAPI_channels_unsubscribe();
console.log('PushAPI.channels.unsubscribe()');
await PushAPI_channels_unsubscribe();

// IMPORTANT: VARIOUS OTHER NOTIFICATIONS FORMAT SUPPORTED
// EXAMPLES HERE: https://github.com/ethereum-push-notification-service/push-sdk/blob/main/packages/restapi/README.md
console.log(
'PushAPI.payloads.sendNotification() [Direct Payload, Single Recipient]'
);
await PushAPI_payloads_sendNotification__direct_payload_single_recipient();
// IMPORTANT: VARIOUS OTHER NOTIFICATIONS FORMAT SUPPORTED
// EXAMPLES HERE: https://github.com/ethereum-push-notification-service/push-sdk/blob/main/packages/restapi/README.md
console.log(
'PushAPI.payloads.sendNotification() [Direct Payload, Single Recipient]'
);
await PushAPI_payloads_sendNotification__direct_payload_single_recipient();

console.log(
'PushAPI.payloads.sendNotification() [Direct Payload, Batch of Recipients (Subset)]'
);
await PushAPI_payloads_sendNotification__direct_payload_group_of_recipient_subset();
console.log(
'PushAPI.payloads.sendNotification() [Direct Payload, Batch of Recipients (Subset)]'
);
await PushAPI_payloads_sendNotification__direct_payload_group_of_recipient_subset();

console.log(
'PushAPI.payloads.sendNotification() [Direct Payload, All Recipients (Broadcast)]'
);
await PushAPI_payloads_sendNotification__direct_payload_all_recipients_brodcast();
console.log(
'PushAPI.payloads.sendNotification() [Direct Payload, All Recipients (Broadcast)]'
);
await PushAPI_payloads_sendNotification__direct_payload_all_recipients_brodcast();

console.log('PushAPI.channels._getSubscribers()');
await PushAPI_channels_getSubscribers();
console.log('PushAPI.channels._getSubscribers()');
await PushAPI_channels_getSubscribers();

console.log('Push Notification - PushSDKSocket()');
await PushSDKSocket();
console.log('Push Notification - PushSDKSocket()');
await PushSDKSocket();
}
};

// Push Notification - PushAPI.user.getFeeds
Expand Down
Loading

0 comments on commit 5831caf

Please sign in to comment.