Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Caching for Collections #322

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,856 changes: 2,093 additions & 1,763 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
]
},
"dependencies": {
"@augment-vir/common": "^12.14.0",
"@dfinity/agent": "^0.10.2",
"@dfinity/auth-client": "^0.10.2",
"@dfinity/candid": "^0.10.2",
Expand All @@ -53,6 +54,7 @@
"bip39": "^3.0.4",
"buffer": "^6.0.3",
"crypto-browserify": "^3.12.0",
"dexie": "^3.2.3",
"ethereum-blockies-base64": "^1.0.2",
"https-browserify": "^1.0.0",
"ic-stoic-identity": "^4.0.0",
Expand Down
5 changes: 3 additions & 2 deletions public/trials.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const otMeta = document.createElement('meta');
otMeta.httpEquiv = 'origin-trial';
otMeta.content = 'Ayfl4fp/WFo5HSyGVliYl2bnpkL3Pa+wm2xyHbpTP5V0kHgpba2f8WZz0lOJnr0dDRk6PIpkOl4NIfhEyJSq7wUAAACYeyJvcmlnaW4iOiJodHRwczovL3d3dy5zdG9pY3dhbGxldC5jb206NDQzIiwiZmVhdHVyZSI6IkRpc2FibGVUaGlyZFBhcnR5U3RvcmFnZVBhcnRpdGlvbmluZyIsImV4cGlyeSI6MTcyNTQwNzk5OSwiaXNTdWJkb21haW4iOnRydWUsImlzVGhpcmRQYXJ0eSI6dHJ1ZX0=';
document.head.append(otMeta);
otMeta.content =
'Ayfl4fp/WFo5HSyGVliYl2bnpkL3Pa+wm2xyHbpTP5V0kHgpba2f8WZz0lOJnr0dDRk6PIpkOl4NIfhEyJSq7wUAAACYeyJvcmlnaW4iOiJodHRwczovL3d3dy5zdG9pY3dhbGxldC5jb206NDQzIiwiZmVhdHVyZSI6IkRpc2FibGVUaGlyZFBhcnR5U3RvcmFnZVBhcnRpdGlvbmluZyIsImV4cGlyeSI6MTcyNTQwNzk5OSwiaXNTdWJkb21haW4iOnRydWUsImlzVGhpcmRQYXJ0eSI6dHJ1ZX0=';
document.head.append(otMeta);
38 changes: 7 additions & 31 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import CircularProgress from '@material-ui/core/CircularProgress';
import {makeStyles} from '@material-ui/core/styles';
import AlertDialog from './components/AlertDialog';
import ConfirmDialog from './components/ConfirmDialog';
import {StoicIdentity} from './ic/stoic-identity';//'ic-stoic-identity';
import {StoicIdentity} from './ic/stoic-identity'; //'ic-stoic-identity';
import {Ed25519KeyIdentity} from '@dfinity/identity';
import OpenLogin from '@toruslabs/openlogin';
import {Route, Routes, useLocation} from 'react-router-dom';
Expand Down Expand Up @@ -44,6 +44,7 @@ import {MissingPage404} from './views/MissingPage404';
import {checkIfToniqEarnAllowed} from './location/geo-ip';
import {EarnFeaturesBlocked} from './views/EarnBlocked';
import {AngelInvestorDialog} from './components/AngelInvestorDialog';
import {getAllCollectionsWithCaching} from './local-cache/dexie/get-collections.js';

const api = extjs.connect('https://icp0.io/');

Expand Down Expand Up @@ -494,7 +495,7 @@ export default function App() {
return true;
};
const _processPaymentForCanister = async _collection => {
return;//This wont work now...
return; //This wont work now...
if (
typeof _collection == 'undefined' ||
!_collection ||
Expand Down Expand Up @@ -1010,34 +1011,10 @@ export default function App() {
}
};
const updateCollections = async () => {
var response;
//Remove dev marked canisters
if (isDevEnv() == false) {
response = await fetch(
'https://us-central1-entrepot-api.cloudfunctions.net/api/collections',
);
} else {
response = await fetch(
'https://us-central1-entrepot-api.cloudfunctions.net/api/collectionsDev',
);
}
var r2 = await response.json();
r2 = r2.map(a => ({...a, canister: a.id})).filter(a => _isCanister(a.canister));
if (collections.length == 0) {
setCollections(r2);
r2.filter(a => a?.nftv).forEach(a => getNri(a.canister));
} else {
for (var i = 0; i < r2.length; i++) {
var n = r2[i];
var o = collections.find(a => a.canister == n.id);
if (typeof o == 'undefined' || JSON.stringify(n) != JSON.stringify(o)) {
setCollections(r2);
r2.filter(a => a?.nftv).forEach(a => getNri(a.canister));
console.log('UPDATED');
break;
}
}
}
const collectionMap = await getAllCollectionsWithCaching();
const allCollectionsWithCaching = Object.values(collectionMap);
setCollections(allCollectionsWithCaching);
allCollectionsWithCaching.filter(a => a?.nftv).forEach(a => getNri(a.id));
if (isToniqEarnAllowed === undefined) {
setToniqEarnAllowed(await checkIfToniqEarnAllowed());
}
Expand Down Expand Up @@ -1340,7 +1317,6 @@ export default function App() {
alert={alert}
confirm={confirm}
loader={loader}
stats={stats}
balance={balance}
identity={identity}
account={
Expand Down
4 changes: 2 additions & 2 deletions src/components/Detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ const Detail = props => {
// }

if (index == 99 && canister == 'kss7i-hqaaa-aaaah-qbvmq-cai')
detailPage = 'interactive_nfts_or_videos';
detailPage = 'interactive_nfts_or_videos';

if (index >= 9 && index <= 19 && canister == 'yy7m6-daaaa-aaaag-qciqa-cai')
detailPage = 'interactive_nfts_or_videos';

Expand Down
20 changes: 10 additions & 10 deletions src/components/UserCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,18 +376,18 @@ export default function UserCollection(props) {
break;
case 'favorites':
// var r = await extjs
// .connect('https://icp0.io/', props.identity)
// .canister('6z5wo-yqaaa-aaaah-qcsfa-cai')
// .liked();
// .connect('https://icp0.io/', props.identity)
// .canister('6z5wo-yqaaa-aaaah-qcsfa-cai')
// .liked();
// data = r.filter((a, i) => r.indexOf(a) == i);
// data = data.map(a => ({
// id: a,
// token: a,
// price: 0,
// time: 0,
// owner: false,
// canister: extjs.decodeTokenId(a).canister,
// listing: null,
// id: a,
// token: a,
// price: 0,
// time: 0,
// owner: false,
// canister: extjs.decodeTokenId(a).canister,
// listing: null,
// }));
break;
case 'offers-made':
Expand Down
133 changes: 78 additions & 55 deletions src/components/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,64 +276,87 @@ export default function Wallet(props) {
<ListItemText primary="Logout" />
</MenuItem>
</Menu>
<ListItem style={{ display: 'flex', flexDirection: 'column', justifyContent: 'center', alignItems: 'center' }}>
<Typography style={{ width: '100%', textAlign: 'center' }}>
<PriceICP
volume={true}
loader={balance === false || (loadedAccount === 0 && loading === true)}
price={
balance === false
? false
: Number(balance) + (voltBalances && loadedAccount === 0 ? voltBalances[0] : 0)
}
/>
<br />
</Typography>

{/* Move the hr outside of Typography */}
{loadedAccount === 0 && balance !== false && loading === false && voltPrincipal ? (
<>
<hr style={{ width: '100%', borderBottom: '1px solid grey' }} />

<Typography style={{ width: '100%', textAlign: 'center' }}>
<ListItem
style={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Typography style={{width: '100%', textAlign: 'center'}}>
<PriceICP
bold={false}
volume={true}
text={
balance === false ? (
<ToniqIcon
className="toniq-icon-fit-icon"
style={{ height: '14px', width: '14px' }}
icon={LoaderAnimated24Icon}
/>
) : undefined
}
price={balance}
>
Wallet
</PriceICP>
<br />
<PriceICP bold={false} volume={true} loader={voltBalances === false} price={voltBalances[0] - voltBalances[2]}>
Volt
</PriceICP>
volume={true}
loader={
balance === false || (loadedAccount === 0 && loading === true)
}
price={
balance === false
? false
: Number(balance) +
(voltBalances && loadedAccount === 0
? voltBalances[0]
: 0)
}
/>
<br />
{voltBalances && voltBalances[2] > 0 ? (
<>
<PriceICP bold={false} volume={true} price={voltBalances[2]}>
Locked
</PriceICP>
<br />
</>
) : (
''
)}
</Typography>
</>
) : (
''
)}
</ListItem>
</Typography>

{/* Move the hr outside of Typography */}
{loadedAccount === 0 &&
balance !== false &&
loading === false &&
voltPrincipal ? (
<>
<hr style={{width: '100%', borderBottom: '1px solid grey'}} />

<Typography style={{width: '100%', textAlign: 'center'}}>
<PriceICP
bold={false}
volume={true}
text={
balance === false ? (
<ToniqIcon
className="toniq-icon-fit-icon"
style={{height: '14px', width: '14px'}}
icon={LoaderAnimated24Icon}
/>
) : undefined
}
price={balance}
>
Wallet
</PriceICP>
<br />
<PriceICP
bold={false}
volume={true}
loader={voltBalances === false}
price={voltBalances[0] - voltBalances[2]}
>
Volt
</PriceICP>
<br />
{voltBalances && voltBalances[2] > 0 ? (
<>
<PriceICP
bold={false}
volume={true}
price={voltBalances[2]}
>
Locked
</PriceICP>
<br />
</>
) : (
''
)}
</Typography>
</>
) : (
''
)}
</ListItem>

{loading == false && loadedAccount === 0 ? (
<ListItem>
Expand Down
8 changes: 4 additions & 4 deletions src/ic/extjs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global BigInt */
import {Actor, HttpAgent} from '@dfinity/agent';
import {Principal} from '@dfinity/principal';
import { IDL } from '@dfinity/candid';
import {IDL} from '@dfinity/candid';
import {
LEDGER_CANISTER_ID,
GOVERNANCE_CANISTER_ID,
Expand Down Expand Up @@ -153,7 +153,7 @@ for (const a in tokensToLoad) {
}
function isQueryCall(idlFactory, methodName) {
// Parse the IDL using the provided factory function
const idl = idlFactory({ IDL });
const idl = idlFactory({IDL});

// Retrieve the method definition by its name
const method = idl._fields.find(([name]) => name === methodName);
Expand All @@ -177,7 +177,7 @@ function createLoggingActor(actor, idl) {
// Check if the property is a function (i.e., a method call)
if (typeof origMethod === 'function') {
return async function (...args) {
const iqc = isQueryCall(idl, propKey);//propKey.startsWith("query");
const iqc = isQueryCall(idl, propKey); //propKey.startsWith("query");
//console.log(`Standard Actor: Calling ${iqc} method: ${propKey}`, 'with arguments:', args);
const result = await origMethod.apply(target, args);
//console.log(`Result from ${iqc} method: ${propKey}`, result);
Expand All @@ -187,7 +187,7 @@ function createLoggingActor(actor, idl) {

// If not a function, just return the original property
return origMethod;
}
},
});
}
class VirtualActor {
Expand Down
Loading
Loading