Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fb87d2a

Browse files
Merge branch 'master' of https://github.com/AlphaWallet/alpha-wallet-android into master
2 parents 27e39be + 39eaa6b commit fb87d2a

File tree

19 files changed

+175
-46
lines changed

19 files changed

+175
-46
lines changed

app/src/main/assets/dapps_list.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
{"name": "Gravity", "description": "Create your gravatar.", "url": "https://gravity.cool/", "category": "Property"},
2828
{"name": "Mokens", "description": "Create your own collectibles", "url": "https://mokens.io/", "category": "Property"},
2929
{"name": "TENZ-ID", "description": "TENZ-ID is a Decentralized Blockchain naming system", "url": "https://tenzorum.org/tenz_id/", "category": "Property"},
30+
{"name": "PHI Network", "description": "Decentralized Social Media, Earn, Entertain, Engage & Exchange", "url": "https://phi.network", "category": "Social Media"},
31+
{"name": "Phiswap", "description": "Swap, earn, and build on PHI Networks leading decentralized crypto trading protocol.", "url": "https://app.phiswap.com", "category": "Exchange"},
3032
{"name": "MonitorChain", "description": "Real-time surveillance", "url": "https://secure.monitorchain.com/", "category": "Security"},
3133
{"name": "Cent", "description": "Earn cryptocurrency sharing your wisdom and creativity.", "url": "https://beta.cent.co/", "category": "Social Media"},
3234
{"name": "Indorse", "description": "Professional Network", "url": "https://indorse.io/", "category": "Social Media"},
@@ -78,6 +80,7 @@
7880
{"name": "DASLA", "description": "A DAS (Decentralized Account System) account registration tool.", "url": "https://das.la", "category": "Tool"},
7981
{"name": ".bit (Previously DAS)", "description": "Your decentralized identity for Web3.0 life", "url": "https://did.id/", "category": "Tool"},
8082
{"name": "NFTSCAN", "description": "NFT Explorer.", "url": "https://nftscan.com/", "category": "Tool"},
83+
{"name": "AAG Staking", "description": "Stake your $1AAG or $1AAG-ONE LP Tokens on our staking website to earn huge rewards. Benefit from high APRs and Capital Boosts with our Genesis NFTs.", "url": "https://staking.aag.ventures/", "category": "Finance"},
8184
{"name": "MetaPath", "description": "Assets can be routed across different blockchains", "url": "https://dapp.path.finance?source=alpha", "category": "Exchange"},
8285
{"name": "SWFT", "description": "One Stop Cross-Chain swap, supporting 300+ tokens on 30+ chains", "url": "https://defi.swft.pro?sourceFlag=alpha", "category": "Exchange"},
8386
{"name": "Swapzone", "description": "Swapzone is a custody-free cryptocurrency exchange aggregator with no registration needed.", "url": "https://swapzone.io/", "category": "Exchange"}

app/src/main/java/com/alphawallet/app/C.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public abstract class C {
4343
public static final String MATIC_TEST_NETWORK = "Mumbai (Test)";
4444
public static final String OPTIMISTIC_NETWORK = "Optimistic";
4545
public static final String OPTIMISTIC_TEST_NETWORK = "Optimistic (Test)";
46+
public static final String CRONOS_MAIN_NETWORK = "Cronos";
4647
public static final String CRONOS_TEST_NETWORK = "Cronos (Test)";
4748
public static final String ARBITRUM_TEST_NETWORK = "Arbitrum (Test)";
4849
public static final String ARBITRUM_ONE_NETWORK = "Arbitrum One";
@@ -56,6 +57,7 @@ public abstract class C {
5657
public static final String AURORA_TESTNET_NAME = "Aurora (Test)";
5758
public static final String MILKOMEDA_NAME = "Milkomeda Cardano";
5859
public static final String MILKOMEDA_TESTNET_NAME = "Milkomeda Cardano (Test)";
60+
public static final String PHI_NETWORK_NAME = "PHI";
5961

6062
public static final String ETHEREUM_TICKER_NAME = "ethereum";
6163
public static final String CLASSIC_TICKER_NAME = "ethereum-classic";
@@ -79,14 +81,16 @@ public abstract class C {
7981
public static final String FANTOM_SYMBOL = "FTM";
8082
public static final String AVALANCHE_SYMBOL = "AVAX";
8183
public static final String MATIC_SYMBOL = "MATIC";
82-
public static final String CRONOS_SYMBOL = "tCRO";
84+
public static final String CRONOS_SYMBOL = "CRO";
85+
public static final String CRONOS_TEST_SYMBOL = "tCRO";
8386
public static final String ARBITRUM_SYMBOL = "AETH";
8487
public static final String ARBITRUM_TEST_SYMBOL = "ARETH";
8588
public static final String PALM_SYMBOL = "PALM";
8689
public static final String KLAYTN_SYMBOL = "KLAY";
8790
public static final String IOTEX_SYMBOL = "IOTX";
8891
public static final String MILKOMEDA_SYMBOL = "milkADA";
8992
public static final String MILKOMEDA_TEST_SYMBOL = "milktADA";
93+
public static final String PHI_NETWORK_SYMBOL = "\u03d5";
9094

9195
public static final String BURN_ADDRESS = "0x0000000000000000000000000000000000000000";
9296

app/src/main/java/com/alphawallet/app/entity/EventSync.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ else if ((maxLogReads - evReads) > maxLogReads*0.25)
362362
* Event Handling
363363
*/
364364

365-
public Pair<Integer, HashSet<BigInteger>> processTransferEvents(Web3j web3j, Event transferEvent, DefaultBlockParameter startBlock,
365+
public Pair<Integer, Pair<HashSet<BigInteger>, HashSet<BigInteger>>> processTransferEvents(Web3j web3j, Event transferEvent, DefaultBlockParameter startBlock,
366366
DefaultBlockParameter endBlock, Realm realm)
367367
throws IOException, LogOverflowException
368368
{
@@ -378,7 +378,7 @@ public Pair<Integer, HashSet<BigInteger>> processTransferEvents(Web3j web3j, Eve
378378

379379
int eventCount = receiveLogs.getLogs().size();
380380

381-
HashSet<BigInteger> tokenIds = new HashSet<>(token.processLogsAndStoreTransferEvents(receiveLogs, transferEvent, txHashes, realm));
381+
HashSet<BigInteger> rcvTokenIds = new HashSet<>(token.processLogsAndStoreTransferEvents(receiveLogs, transferEvent, txHashes, realm));
382382

383383
EthLog sentLogs = web3j.ethGetLogs(sendFilter).send();
384384

@@ -389,15 +389,15 @@ public Pair<Integer, HashSet<BigInteger>> processTransferEvents(Web3j web3j, Eve
389389

390390
if (sentLogs.getLogs().size() > eventCount) eventCount = sentLogs.getLogs().size();
391391

392-
token.processLogsAndStoreTransferEvents(sentLogs, transferEvent, txHashes, realm);
392+
HashSet<BigInteger> sendTokenIds = token.processLogsAndStoreTransferEvents(sentLogs, transferEvent, txHashes, realm);
393393

394394
//register Transaction fetches
395395
for (String txHash : txHashes)
396396
{
397397
TransactionsService.addTransactionHashFetch(txHash, token.tokenInfo.chainId, token.getWallet());
398398
}
399399

400-
return new Pair<>(eventCount, tokenIds);
400+
return new Pair<>(eventCount, new Pair<>(rcvTokenIds, sendTokenIds));
401401
}
402402

403403
public String getActivityName(String toAddress)

app/src/main/java/com/alphawallet/app/entity/TokensMapping.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ public void setContracts(List<ContractAddress> contracts) {
1818
this.contracts = contracts;
1919
}
2020

21+
public void setGroup(String group) {
22+
this.group = group;
23+
}
24+
2125
public TokenGroup getGroup() {
2226
if (group == null) return TokenGroup.ASSET;
2327

app/src/main/java/com/alphawallet/app/entity/tokens/ERC1155Token.java

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -387,13 +387,16 @@ private void updateRealmBalance(Realm realm, Set<BigInteger> tokenIds, List<Uint
387387
BigDecimal newBalance = new BigDecimal(balances.get(index).getValue());
388388
if (asset == null)
389389
{
390-
assets.put(tokenId, new NFTAsset(tokenId));
390+
NFTAsset newAsset = new NFTAsset(tokenId);
391+
newAsset.setBalance(newBalance);
392+
assets.put(tokenId, newAsset);
391393
updated = true;
392394
}
393-
if (assets.get(tokenId).setBalance(newBalance) && !updated) //set balance and check for change
395+
else if (asset.setBalance(newBalance))
394396
{
395397
updated = true;
396398
}
399+
397400
if (realm == null && newBalance.equals(BigDecimal.ZERO))
398401
{
399402
assets.remove(tokenId);
@@ -403,36 +406,40 @@ private void updateRealmBalance(Realm realm, Set<BigInteger> tokenIds, List<Uint
403406

404407
if (updated)
405408
{
406-
updateRealmBalances(realm, tokenIds);
409+
updateRealmBalances(realm);
407410
}
408411
}
409412
}
410413

411-
private void updateRealmBalances(Realm realm, Set<BigInteger> tokenIds)
414+
private void updateRealmBalances(Realm realm)
412415
{
413416
if (realm == null) return;
414417
realm.executeTransaction(r -> {
415-
for (BigInteger tokenId : tokenIds)
418+
for (Map.Entry<BigInteger, NFTAsset> entry : assets.entrySet())
416419
{
420+
BigInteger tokenId = entry.getKey();
421+
NFTAsset asset = entry.getValue();
417422
String key = RealmNFTAsset.databaseKey(this, tokenId);
418423
RealmNFTAsset realmAsset = realm.where(RealmNFTAsset.class)
419424
.equalTo("tokenIdAddr", key)
420425
.findFirst();
421426

427+
if (realmAsset == null && asset.getBalance().equals(BigDecimal.ZERO)) continue; // no recorded token, no balance, skip
428+
422429
if (realmAsset == null)
423430
{
424431
realmAsset = r.createObject(RealmNFTAsset.class, key); //create asset in realm
425-
realmAsset.setMetaData(assets.get(tokenId).jsonMetaData());
432+
realmAsset.setMetaData(asset.jsonMetaData());
426433
}
427434

428-
if (assets.get(tokenId).getBalance().equals(BigDecimal.ZERO)) //remove asset no longer in balance
435+
if (asset.getBalance().equals(BigDecimal.ZERO)) //remove asset no longer in balance
429436
{
430437
realmAsset.deleteFromRealm();
431438
assets.remove(tokenId);
432439
}
433440
else
434441
{
435-
realmAsset.setBalance(assets.get(tokenId).getBalance()); //update realm balance
442+
realmAsset.setBalance(entry.getValue().getBalance()); //update realm balance
436443
r.insertOrUpdate(realmAsset);
437444
}
438445
}
@@ -638,20 +645,24 @@ public BigDecimal updateBalance(Realm realm)
638645
{
639646
final Web3j web3j = TokenRepository.getWeb3jService(tokenInfo.chainId);
640647

641-
Pair<Integer, HashSet<BigInteger>> evRead = eventSync.processTransferEvents(web3j,
648+
Pair<Integer, Pair<HashSet<BigInteger>, HashSet<BigInteger>>> evRead = eventSync.processTransferEvents(web3j,
642649
getBalanceUpdateEvents(), startBlock, endBlock, realm);
643650

644-
Pair<Integer, HashSet<BigInteger>> batchRead = eventSync.processTransferEvents(web3j,
651+
Pair<Integer, Pair<HashSet<BigInteger>, HashSet<BigInteger>>> batchRead = eventSync.processTransferEvents(web3j,
645652
getBatchBalanceUpdateEvents(), startBlock, endBlock, realm);
646653

647-
evRead.second.addAll(batchRead.second);
654+
// All tokenIds which have passed through the owner address
655+
evRead.second.first.addAll(evRead.second.second);
656+
evRead.second.first.addAll(batchRead.second.first);
657+
evRead.second.first.addAll(batchRead.second.second);
658+
648659
//combine the tokenIds with existing assets
649-
evRead.second.addAll(assets.keySet());
660+
evRead.second.first.addAll(assets.keySet());
650661

651662
//update balances of all
652-
List<Uint256> balances = fetchBalances(evRead.second);
663+
List<Uint256> balances = fetchBalances(evRead.second.first);
653664
//update realm
654-
updateRealmBalance(realm, evRead.second, balances);
665+
updateRealmBalance(realm, evRead.second.first, balances);
655666

656667
//update read points
657668
eventSync.updateEventReads(realm, sync, currentBlock, evRead.first); //means our event read was fine

app/src/main/java/com/alphawallet/app/entity/tokens/ERC721Token.java

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,17 +340,21 @@ public BigDecimal updateBalance(Realm realm)
340340
try
341341
{
342342
final Web3j web3j = TokenRepository.getWeb3jService(tokenInfo.chainId);
343-
Pair<Integer, HashSet<BigInteger>> evRead = eventSync.processTransferEvents(web3j,
343+
Pair<Integer, Pair<HashSet<BigInteger>, HashSet<BigInteger>>> evRead = eventSync.processTransferEvents(web3j,
344344
getTransferEvents(), startBlock, endBlock, realm);
345345

346346
eventSync.updateEventReads(realm, sync, currentBlock, evRead.first); //means our event read was fine
347347

348-
HashSet<BigInteger> tokenIdsHeld = checkBalances(web3j, evRead.second);
348+
HashSet<BigInteger> allMovingTokens = new HashSet<>(evRead.second.first);
349+
allMovingTokens.addAll(evRead.second.second);
349350

350-
//should we check existing assets too?
351-
//add to realm
352-
updateRealmBalance(realm, tokenIdsHeld);
353-
return new BigDecimal(tokenIdsHeld.size());
351+
if (allMovingTokens.size() == 0 && balance.intValue() != tokenBalanceAssets.size()) //if there's a mismatch, check all current assets
352+
{
353+
allMovingTokens.addAll(tokenBalanceAssets.keySet());
354+
}
355+
356+
HashSet<BigInteger> tokenIdsHeld = checkBalances(web3j, allMovingTokens);
357+
updateRealmBalance(realm, tokenIdsHeld, allMovingTokens);
354358
}
355359
catch (LogOverflowException e)
356360
{
@@ -369,10 +373,11 @@ public BigDecimal updateBalance(Realm realm)
369373
return balance;
370374
}
371375

372-
private void updateRealmBalance(Realm realm, Set<BigInteger> tokenIds)
376+
private void updateRealmBalance(Realm realm, Set<BigInteger> tokenIds, Set<BigInteger> allMovingTokens)
373377
{
374378
boolean updated = false;
375379
//fill in balances
380+
HashSet<BigInteger> removedTokens = new HashSet<>(allMovingTokens);
376381
if (tokenIds != null && tokenIds.size() > 0)
377382
{
378383
for (BigInteger tokenId : tokenIds)
@@ -383,13 +388,35 @@ private void updateRealmBalance(Realm realm, Set<BigInteger> tokenIds)
383388
tokenBalanceAssets.put(tokenId, new NFTAsset(tokenId));
384389
updated = true;
385390
}
391+
removedTokens.remove(tokenId);
386392
}
387393

388394
if (updated)
389395
{
390396
updateRealmBalances(realm, tokenIds);
391397
}
392398
}
399+
400+
removeRealmBalance(realm, removedTokens);
401+
}
402+
403+
private void removeRealmBalance(Realm realm, HashSet<BigInteger> removedTokens)
404+
{
405+
if (removedTokens.size() == 0) return;
406+
realm.executeTransaction(r -> {
407+
for (BigInteger tokenId : removedTokens)
408+
{
409+
String key = RealmNFTAsset.databaseKey(this, tokenId);
410+
RealmNFTAsset realmAsset = realm.where(RealmNFTAsset.class)
411+
.equalTo("tokenIdAddr", key)
412+
.findFirst();
413+
414+
if (realmAsset != null)
415+
{
416+
realmAsset.deleteFromRealm();
417+
}
418+
}
419+
});
393420
}
394421

395422
private void updateRealmBalances(Realm realm, Set<BigInteger> tokenIds)

0 commit comments

Comments
 (0)