From cde52eb572706070758b288126b6f4ca659e7019 Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 1 Jan 2024 17:20:17 -0500 Subject: [PATCH 1/4] prototype env vars --- .env.example | 5 +++++ .gitignore | 1 + src/app/subscriptions.ts | 11 +++++++---- 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..caeb526b --- /dev/null +++ b/.env.example @@ -0,0 +1,5 @@ +NETWORK=stokenet +#Mainnet: 1 +#Stokenet: 2 +NETWORK_ID=2 +DAPP_DEFINITION=account_tdx_2_129kev9w27tsl7qjg0dlyze70kxnlzycs8v2c85kzec40gg8mt73f7y \ No newline at end of file diff --git a/.gitignore b/.gitignore index ea546958..411baa5a 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ next-env.d.ts /playwright/.cache/ localhost:3000/ +.env diff --git a/src/app/subscriptions.ts b/src/app/subscriptions.ts index 1acd6c8f..d69c0a7e 100644 --- a/src/app/subscriptions.ts +++ b/src/app/subscriptions.ts @@ -29,9 +29,12 @@ let subs: Subscription[] = []; export function initializeSubscriptions(store: AppStore) { rdtInstance = RadixDappToolkit({ - dAppDefinitionAddress: - "account_tdx_2_129kev9w27tsl7qjg0dlyze70kxnlzycs8v2c85kzec40gg8mt73f7y", - networkId: RadixNetwork.Stokenet, + dAppDefinitionAddress: process.env.DAPP_DEFINITION_ADDRESS + ? process.env.DAPP_DEFINITION_ADDRESS + : "", + networkId: process.env.NETWORK_ID + ? parseInt(process.env.NETWORK_ID) + : RadixNetwork.Stokenet, }); rdtInstance.walletApi.setRequestData( DataRequestBuilder.accounts().exactly(1) @@ -48,7 +51,7 @@ export function initializeSubscriptions(store: AppStore) { setRdt(rdtInstance); // TODO: "black" on the light theme rdtInstance.buttonApi.setTheme("white"); - adex.init("stokenet"); + adex.init(process.env.NETWORK ? process.env.NETWORK : "stokenet"); subs.push( adex.clientState.stateChanged$.subscribe((newState) => { const serializedState: adex.StaticState = JSON.parse( From e9e9a49440a8826a434123af80ac93cd86a34fb7 Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 8 Jan 2024 21:45:07 -0500 Subject: [PATCH 2/4] simplfication --- .env.example | 5 +---- src/app/subscriptions.ts | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.env.example b/.env.example index caeb526b..5e377e33 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,2 @@ -NETWORK=stokenet -#Mainnet: 1 -#Stokenet: 2 -NETWORK_ID=2 +NETWORK=stokenet # Options: mainnet or stokenet DAPP_DEFINITION=account_tdx_2_129kev9w27tsl7qjg0dlyze70kxnlzycs8v2c85kzec40gg8mt73f7y \ No newline at end of file diff --git a/src/app/subscriptions.ts b/src/app/subscriptions.ts index d69c0a7e..603b9b2c 100644 --- a/src/app/subscriptions.ts +++ b/src/app/subscriptions.ts @@ -28,13 +28,23 @@ function setRdt(rdt: RDT) { let subs: Subscription[] = []; export function initializeSubscriptions(store: AppStore) { + let networkId; + switch (process.env.NETWORK) { + case "mainnet": + networkId = RadixNetwork.Mainnet; + break; + case "stokenet": + networkId = RadixNetwork.Stokenet; + break; + default: + networkId = RadixNetwork.Stokenet; + } + rdtInstance = RadixDappToolkit({ dAppDefinitionAddress: process.env.DAPP_DEFINITION_ADDRESS ? process.env.DAPP_DEFINITION_ADDRESS : "", - networkId: process.env.NETWORK_ID - ? parseInt(process.env.NETWORK_ID) - : RadixNetwork.Stokenet, + networkId, }); rdtInstance.walletApi.setRequestData( DataRequestBuilder.accounts().exactly(1) @@ -51,7 +61,9 @@ export function initializeSubscriptions(store: AppStore) { setRdt(rdtInstance); // TODO: "black" on the light theme rdtInstance.buttonApi.setTheme("white"); - adex.init(process.env.NETWORK ? process.env.NETWORK : "stokenet"); + const network: string = process.env.NETWORK || "stokenet"; + + adex.init(adex.ApiNetworkOptions[network as any]); subs.push( adex.clientState.stateChanged$.subscribe((newState) => { const serializedState: adex.StaticState = JSON.parse( From e8963825dbd59cffd6647087e9781667c1df1763 Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 8 Jan 2024 22:25:05 -0500 Subject: [PATCH 3/4] fixed typos --- .env.example | 2 +- next.config.js | 4 ++++ src/app/subscriptions.ts | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 5e377e33..4817b94e 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,2 @@ NETWORK=stokenet # Options: mainnet or stokenet -DAPP_DEFINITION=account_tdx_2_129kev9w27tsl7qjg0dlyze70kxnlzycs8v2c85kzec40gg8mt73f7y \ No newline at end of file +DAPP_DEFINITION_ADDRESS=account_tdx_2_129kev9w27tsl7qjg0dlyze70kxnlzycs8v2c85kzec40gg8mt73f7y \ No newline at end of file diff --git a/next.config.js b/next.config.js index 809494eb..75d69ac6 100644 --- a/next.config.js +++ b/next.config.js @@ -10,6 +10,10 @@ const nextConfig = { reactStrictMode: false, pageExtensions: ["js", "jsx", "mdx", "ts", "tsx"], + env: { + NETWORK: process.env.NETWORK, + DAPP_DEFINITION_ADDRESS: process.env.DAPP_DEFINITION_ADDRESS, + }, }; module.exports = withMDX(nextConfig); diff --git a/src/app/subscriptions.ts b/src/app/subscriptions.ts index 603b9b2c..a5b6aa98 100644 --- a/src/app/subscriptions.ts +++ b/src/app/subscriptions.ts @@ -39,7 +39,6 @@ export function initializeSubscriptions(store: AppStore) { default: networkId = RadixNetwork.Stokenet; } - rdtInstance = RadixDappToolkit({ dAppDefinitionAddress: process.env.DAPP_DEFINITION_ADDRESS ? process.env.DAPP_DEFINITION_ADDRESS @@ -61,9 +60,19 @@ export function initializeSubscriptions(store: AppStore) { setRdt(rdtInstance); // TODO: "black" on the light theme rdtInstance.buttonApi.setTheme("white"); - const network: string = process.env.NETWORK || "stokenet"; + let network; + switch (process.env.NETWORK) { + case "mainnet": + network = adex.ApiNetworkOptions.indexOf("mainnet"); + break; + case "stokenet": + network = adex.ApiNetworkOptions.indexOf("stokenet"); + break; + default: + network = adex.ApiNetworkOptions.indexOf("stokenet"); + } - adex.init(adex.ApiNetworkOptions[network as any]); + adex.init(adex.ApiNetworkOptions[network]); subs.push( adex.clientState.stateChanged$.subscribe((newState) => { const serializedState: adex.StaticState = JSON.parse( From 1e8142dd66f3aedc0b9cdad31516a03b33b09243 Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 9 Jan 2024 21:05:51 -0500 Subject: [PATCH 4/4] updated env --- .env.example | 4 ++-- next.config.js | 4 ---- src/app/subscriptions.ts | 8 ++++---- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.env.example b/.env.example index 4817b94e..18aedf7d 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,2 @@ -NETWORK=stokenet # Options: mainnet or stokenet -DAPP_DEFINITION_ADDRESS=account_tdx_2_129kev9w27tsl7qjg0dlyze70kxnlzycs8v2c85kzec40gg8mt73f7y \ No newline at end of file +NEXT_PUBLIC_NETWORK=stokenet # Options: mainnet or stokenet +NEXT_PUBLIC_DAPP_DEFINITION_ADDRESS=account_tdx_2_129kev9w27tsl7qjg0dlyze70kxnlzycs8v2c85kzec40gg8mt73f7y \ No newline at end of file diff --git a/next.config.js b/next.config.js index 75d69ac6..809494eb 100644 --- a/next.config.js +++ b/next.config.js @@ -10,10 +10,6 @@ const nextConfig = { reactStrictMode: false, pageExtensions: ["js", "jsx", "mdx", "ts", "tsx"], - env: { - NETWORK: process.env.NETWORK, - DAPP_DEFINITION_ADDRESS: process.env.DAPP_DEFINITION_ADDRESS, - }, }; module.exports = withMDX(nextConfig); diff --git a/src/app/subscriptions.ts b/src/app/subscriptions.ts index a5b6aa98..d80445f4 100644 --- a/src/app/subscriptions.ts +++ b/src/app/subscriptions.ts @@ -29,7 +29,7 @@ let subs: Subscription[] = []; export function initializeSubscriptions(store: AppStore) { let networkId; - switch (process.env.NETWORK) { + switch (process.env.NEXT_PUBLIC_NETWORK) { case "mainnet": networkId = RadixNetwork.Mainnet; break; @@ -40,8 +40,8 @@ export function initializeSubscriptions(store: AppStore) { networkId = RadixNetwork.Stokenet; } rdtInstance = RadixDappToolkit({ - dAppDefinitionAddress: process.env.DAPP_DEFINITION_ADDRESS - ? process.env.DAPP_DEFINITION_ADDRESS + dAppDefinitionAddress: process.env.NEXT_PUBLIC_DAPP_DEFINITION_ADDRESS + ? process.env.NEXT_PUBLIC_DAPP_DEFINITION_ADDRESS : "", networkId, }); @@ -61,7 +61,7 @@ export function initializeSubscriptions(store: AppStore) { // TODO: "black" on the light theme rdtInstance.buttonApi.setTheme("white"); let network; - switch (process.env.NETWORK) { + switch (process.env.NEXT_PUBLIC_NETWORK) { case "mainnet": network = adex.ApiNetworkOptions.indexOf("mainnet"); break;