Skip to content

Commit

Permalink
Merge pull request #954 from Web3Auth/feat/loader
Browse files Browse the repository at this point in the history
Feat/loader
  • Loading branch information
chaitanyapotti authored Dec 6, 2022
2 parents 6e76c01 + 9eb1751 commit a71a7ca
Show file tree
Hide file tree
Showing 66 changed files with 26,367 additions and 20,282 deletions.
618 changes: 460 additions & 158 deletions demo/vue-app/package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion demo/vue-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"@solana/web3.js": "^1.66.1",
"@toruslabs/openlogin": "^2.10.0",
"@toruslabs/openlogin-ed25519": "^2.0.0",
"@walletconnect/qrcode-modal": "~1.8.0",
"@web3auth/base": "file:../../packages/base",
Expand All @@ -18,6 +19,7 @@
"@web3auth/coinbase-adapter": "file:../../packages/adapters/coinbase-adapter",
"@web3auth/core": "file:../../packages/core",
"@web3auth/metamask-adapter": "file:../../packages/adapters/metamask-adapter",
"@web3auth/modal": "file:../../packages/modal",
"@web3auth/openlogin-adapter": "file:../../packages/adapters/openlogin-adapter",
"@web3auth/phantom-adapter": "file:../../packages/adapters/phantom-adapter",
"@web3auth/slope-adapter": "file:../../packages/adapters/slope-adapter",
Expand All @@ -29,7 +31,6 @@
"@web3auth/torus-solana-adapter": "file:../../packages/adapters/torus-solana-adapter",
"@web3auth/torus-wallet-connector-plugin": "file:../../packages/plugins/torus-wallet-connector-plugin",
"@web3auth/wallet-connect-v1-adapter": "file:../../packages/adapters/wallet-connect-v1-adapter",
"@web3auth/modal": "file:../../packages/modal",
"lodash.merge": "^4.6.2",
"ts-custom-error": "^3.2.2",
"vue": "^2.6.14",
Expand Down
23 changes: 20 additions & 3 deletions demo/vue-app/src/chains/ethereum.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<button class="rpcBtn" v-if="provider" @click="getUserInfo" style="cursor: pointer">Get User Info</button>
<button class="rpcBtn" v-if="provider" @click="authenticateUser" style="cursor: pointer">Get Auth Id token</button>
<EthRpc :connectedAdapter="web3auth.connectedAdapterName" v-if="provider" :provider="provider" :console="console"></EthRpc>
<span>{{ connecting }}</span>

<!-- <button @click="showError" style="cursor: pointer">Show Error</button> -->
</section>
Expand Down Expand Up @@ -165,15 +164,33 @@ export default Vue.extend({
[WALLET_ADAPTERS.METAMASK]: {
showOnDesktop: true,
showOnModal: true,
showOnMobile: false,
showOnMobile: true,
label: "Metamask",
},
[WALLET_ADAPTERS.COINBASE]: {
showOnDesktop: true,
showOnModal: true,
showOnMobile: false,
showOnMobile: true,
label: "Coinbase",
},
[WALLET_ADAPTERS.WALLET_CONNECT_V1]: {
showOnDesktop: true,
showOnModal: true,
showOnMobile: true,
label: "Wallet Connect",
},
[WALLET_ADAPTERS.TORUS_EVM]: {
showOnDesktop: true,
showOnModal: true,
showOnMobile: true,
label: "Torus",
},
[WALLET_ADAPTERS.OPENLOGIN]: {
showOnDesktop: true,
showOnModal: true,
showOnMobile: true,
label: "OpenLogin",
},
},
});
} catch (error) {
Expand Down
13 changes: 11 additions & 2 deletions demo/vue-app/src/chains/solana.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ export default Vue.extend({
loading: false,
loginButtonStatus: "",
provider: undefined,
web3auth: new Web3Auth({ chainConfig: { chainNamespace: CHAIN_NAMESPACES.SOLANA }, clientId: config.clientId[this.openloginNetwork] }),
web3auth: new Web3Auth({
chainConfig: { chainNamespace: CHAIN_NAMESPACES.SOLANA },
clientId: config.clientId[this.openloginNetwork],
enableLogging: true,
}),
};
},
components: {
Expand Down Expand Up @@ -119,7 +123,12 @@ export default Vue.extend({
this.parseConfig();
this.loading = true;
this.web3auth = new Web3Auth({ chainConfig: solanaChainConfig, clientId: config.clientId[this.openloginNetwork], authMode: "DAPP" });
this.web3auth = new Web3Auth({
chainConfig: solanaChainConfig,
clientId: config.clientId[this.openloginNetwork],
authMode: "DAPP",
enableLogging: true,
});
const openloginAdapter = new OpenloginAdapter({
adapterSettings: {
network: this.openloginNetwork as OPENLOGIN_NETWORK_TYPE,
Expand Down
2 changes: 2 additions & 0 deletions demo/vue-app/src/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@
<label for="light">Light</label>
<input type="radio" id="dark" name="dark" value="dark" v-model="form.uiMode.whitelabel.theme" />
<label for="dark">Dark</label>
<input type="radio" id="auto" name="auto" value="auto" v-model="form.uiMode.whitelabel.theme" />
<label for="auto">Auto</label>
</span>
</div>
<div class="flex-vertical-center">
Expand Down
30 changes: 6 additions & 24 deletions demo/vue-app/vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
},

configureWebpack: (config) => {
config.devtool = "source-map";
config.resolve.fallback = {
crypto: require.resolve("crypto-browserify"),
stream: require.resolve("stream-browserify"),
Expand All @@ -26,30 +27,11 @@ module.exports = {
};
config.plugins.push(new ProvidePlugin({ Buffer: ["buffer", "Buffer"] }));
config.plugins.push(new ProvidePlugin({ process: ["process/browser"] }));
config.plugins.push(new BundleAnalyzerPlugin({
analyzerMode: "disabled"
}))
},
chainWebpack: (config) => {
if (process.env.NODE_ENV !== "production") {
config.module
.rule("sourcemap")
.test(/\.${js,ts}$/)
.enforce("pre")
.use("source-map-loader")
.loader("source-map-loader")
.end();
}
const svgRule = config.module.rule("svg");

svgRule.uses.clear();

svgRule
.use("vue-loader")
.loader("vue-loader") // or `vue-loader-v16` if you are using a preview support of Vue 3 in Vue CLI
.end()
.use("vue-svg-loader")
.loader("vue-svg-loader");
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: "disabled",
})
);
},
crossorigin: "anonymous",
productionSourceMap: true,
Expand Down
71 changes: 35 additions & 36 deletions locales/importLocales.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,58 @@
/* eslint-disable no-console */
/* eslint-disable promise/always-return */
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable promise/always-return */
const https = require("https");
const fetch = require("node-fetch");
const fs = require("fs");
const path = require("path");
const log = require("loglevel");

const localeUrl = "https://api.tor.us/locales/web3auth";
// const localeUrl = "http://localhost:2020/locales/web3auth";
const args = process.argv.slice(2);
const branch = args[0] || "main";
const repoUrl = `https://raw.githubusercontent.com/Web3Auth/web3auth-locales/${branch}/Web3Auth-locale`;
const localeGroups = ["locale-common"];
const promises = [];
const locales = {};

function getLocale() {
return new Promise((resolve, reject) => {
const request = https.get(`${localeUrl}`, (response) => {
let body = "";
response.on("data", (data) => {
body += data;
});
response.on("end", () => {
resolve(JSON.parse(body));
});
});
localeGroups.forEach((group) => {
const urlFetch = `${repoUrl}/${group}.json`;
promises.push(fetch(urlFetch).then((res) => res.json()));
});

request.on("error", (error) => {
reject(error);
function processRecords(items) {
Object.keys(items).forEach((groupKey) => {
Object.keys(items[groupKey]).forEach((wordKey) => {
Object.keys(items[groupKey][wordKey]).forEach((localeKey) => {
if (!locales[localeKey]) locales[localeKey] = {};
if (!locales[localeKey][groupKey]) locales[localeKey][groupKey] = {};
locales[localeKey][groupKey][wordKey] = items[groupKey][wordKey][localeKey];
});
});

request.end();
});
}

getLocale()
.then((result) => {
const locales = result.data;
const folders = ["./packages/ui/src/i18n/"];
folders.forEach((folder) => {
const folderPath = path.resolve(folder);

if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath);
}
Promise.all(promises)
.then((results) => {
results.forEach((set) => {
processRecords(set);
});

// Create json files
const folder = "./packages/ui/src/i18n/";
const folderPath = path.resolve(folder);
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath);
}

const keys = Object.keys(locales);
for (const localeKey of keys) {
if (Object.prototype.hasOwnProperty.call(locales, localeKey)) {
folders.forEach((folder) => {
const filePath = path.resolve(`${folder}${localeKey}.json`);
fs.writeFile(filePath, JSON.stringify(locales[localeKey], null, 2), { flag: "w" }, (error) => {
if (error) throw error;
});
const filePath = path.resolve(`${folder}${localeKey}.json`);
fs.writeFile(filePath, JSON.stringify(locales[localeKey], null, 2), { flag: "w" }, (error) => {
if (error) throw error;
});
}
}
})
.catch((error) => {
log.error(error);
console.error(error);
});
Loading

0 comments on commit a71a7ca

Please sign in to comment.