-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
93 changed files
with
6,430 additions
and
2,211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
app/appstores/DataSource/NftCustomAssets/NftCustomAssets.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* @version 0.9 | ||
*/ | ||
import Database from '@app/appstores/DataSource/Database' | ||
|
||
let CACHE = {} | ||
class NftCustomAssets { | ||
|
||
saveCustomAsset = async (tmp) => { | ||
if (typeof CACHE[tmp.nftType] !== 'undefined' && typeof CACHE[tmp.nftType][tmp.nftAddress] !== 'undefined') { | ||
return false | ||
} | ||
await Database.setTableName('custom_nfts').setInsertData({ insertObjs: [tmp]}).insert() | ||
return true | ||
} | ||
|
||
getCustomAssets = async () => { | ||
const sql = `SELECT id, nft_code AS nftCode, nft_symbol AS nftSymbol, nft_name AS nftName, nft_type AS nftType, nft_address AS nftAddress FROM custom_nfts` | ||
const res = await Database.query(sql, true) | ||
if (!res || !res.array || res.array.length === 0) { | ||
return false | ||
} | ||
CACHE = {} | ||
for (const tmp of res.array) { | ||
tmp.nftName = Database.unEscapeString(tmp.nftName) | ||
if (typeof CACHE[tmp.nftType] === 'undefined') { | ||
CACHE[tmp.nftType] = {} | ||
} | ||
CACHE[tmp.nftType][tmp.nftAddress] = tmp | ||
} | ||
return CACHE | ||
} | ||
|
||
} | ||
|
||
export default new NftCustomAssets() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* @version 0.9 | ||
*/ | ||
import Database from '@app/appstores/DataSource/Database' | ||
|
||
import BlocksoftKeysUtils from '@crypto/actions/BlocksoftKeys/BlocksoftKeysUtils' | ||
import Log from '@app/services/Log/Log' | ||
import CashBackUtils from '@app/appstores/Stores/CashBack/CashBackUtils' | ||
import UpdateWalletsDaemon from '@app/daemons/back/UpdateWalletsDaemon' | ||
|
||
import store from '@app/store' | ||
|
||
|
||
const CACHE = { | ||
MATIC: {}, | ||
ETH: {}, | ||
ETH_ROPSTEN: {}, | ||
ETH_RINKEBY: {} | ||
} | ||
|
||
|
||
const CACHE_TIME = { | ||
MATIC: {}, | ||
ETH: {}, | ||
ETH_ROPSTEN: {}, | ||
ETH_RINKEBY: {} | ||
} | ||
|
||
const CACHE_VALID_TIME = 60000 // 1 minute | ||
|
||
class Nfts { | ||
|
||
saveNfts = async (tokenBlockchainCode, address, nfts) => { | ||
if (typeof CACHE[tokenBlockchainCode][address] !== 'undefined' && CACHE[tokenBlockchainCode][address] === nfts) return false | ||
CACHE[tokenBlockchainCode][address] = nfts | ||
CACHE_TIME[tokenBlockchainCode][address] = new Date().getTime() | ||
const sql1 = `DELETE FROM transactions_scanners_tmp WHERE currency_code='${tokenBlockchainCode}' AND address='${address}' AND tmp_key='nfts'` | ||
await Database.query(sql1, true) | ||
|
||
const sql = `INSERT INTO transactions_scanners_tmp ( | ||
currency_code, address, tmp_key, tmp_val | ||
) VALUES ( | ||
'${tokenBlockchainCode}', '${address}', 'nfts', '${Database.escapeString(JSON.stringify(nfts))}' | ||
)` | ||
await Database.query(sql, true) | ||
} | ||
|
||
getNfts = async (address) => { | ||
const sql = `SELECT currency_code, tmp_val FROM transactions_scanners_tmp WHERE address='${address}' AND tmp_key='nfts'` | ||
const res = await Database.query(sql, true) | ||
if (!res || !res.array || res.array.length === 0) { | ||
return false | ||
} | ||
for (const tmp of res.array) { | ||
try { | ||
CACHE[tmp.currency_code][address] = JSON.parse(Database.unEscapeString(tmp.tmp_val)) | ||
} catch (e) { | ||
// do nothing | ||
} | ||
} | ||
} | ||
|
||
getNftsCache = (tokenBlockchainCode, address) => { | ||
if (typeof CACHE[tokenBlockchainCode][address] === 'undefined') return false | ||
if (typeof CACHE_TIME[tokenBlockchainCode][address] !== 'undefined') { | ||
const now = new Date().getTime() | ||
const diff = now - CACHE_TIME[tokenBlockchainCode][address] | ||
if (diff < CACHE_VALID_TIME) { | ||
return false | ||
} | ||
} | ||
return CACHE[tokenBlockchainCode][address] | ||
} | ||
} | ||
|
||
export default new Nfts() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.