Skip to content

Commit

Permalink
Merge branch 'main' into tabbed-onboarding-existing-accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
jagodarybacka authored Mar 10, 2023
2 parents c3c1119 + 87db50f commit b4b1835
Show file tree
Hide file tree
Showing 25 changed files with 432 additions and 58 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/BUG.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ body:
label: Version
description: What version of the extension are you running?
options:
- v0.27.2
- v0.27.1
- v0.27.0
- v0.26.2
Expand Down
15 changes: 9 additions & 6 deletions background/constants/base-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ARBITRUM_ONE_ETH: NetworkBaseAsset = {
...ETH,
chainID: "42161",
metadata: {
coinGeckoID: "arbitrum-one",
coinGeckoID: "ethereum",
tokenLists: [],
},
}
Expand All @@ -24,7 +24,7 @@ const ARBITRUM_NOVA_ETH: NetworkBaseAsset = {
...ETH,
chainID: "42170",
metadata: {
coinGeckoID: "arbitrum-nova",
coinGeckoID: "ethereum",
tokenLists: [],
},
}
Expand All @@ -33,7 +33,7 @@ const OPTIMISTIC_ETH: NetworkBaseAsset = {
...ETH,
chainID: "10",
metadata: {
coinGeckoID: "optimistic-ethereum",
coinGeckoID: "ethereum",
tokenLists: [],
},
}
Expand Down Expand Up @@ -64,8 +64,9 @@ const MATIC: NetworkBaseAsset = {
symbol: "MATIC",
decimals: 18,
metadata: {
coinGeckoID: "polygon-pos",
coinGeckoID: "matic-network",
tokenLists: [],
websiteURL: "https://polygon.technology/",
},
}

Expand All @@ -75,8 +76,9 @@ const AVAX: NetworkBaseAsset = {
symbol: "AVAX",
decimals: 18,
metadata: {
coinGeckoID: "avalanche",
coinGeckoID: "avalanche-2",
tokenLists: [],
websiteURL: "https://avax.network/",
},
}

Expand All @@ -86,8 +88,9 @@ const BNB: NetworkBaseAsset = {
symbol: "BNB",
decimals: 18,
metadata: {
coinGeckoID: "binance-smart-chain",
coinGeckoID: "binancecoin",
tokenLists: [],
websiteURL: "https://bnbchain.org",
},
}

Expand Down
3 changes: 3 additions & 0 deletions background/lib/daylight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export type DaylightAbility = {
openAt: string | null
closeAt: string | null
isClosed: boolean | null
walletCompleted: boolean | null
createdAt: string
chain: string
sourceId: string
Expand Down Expand Up @@ -95,6 +96,8 @@ export const getDaylightAbilities = async (
// The limit needs to be set. It is set to the highest value.
requestURL.searchParams.set("limit", "1000")
requestURL.searchParams.set("deadline", "all")
requestURL.searchParams.set("showCompleted", "true")
requestURL.searchParams.set("markAsShown", "true")

try {
const response: AbilitiesResponse = await fetchJson({
Expand Down
30 changes: 18 additions & 12 deletions background/lib/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
MULTICALL_ABI,
MULTICALL_CONTRACT_ADDRESS,
} from "./multicall"
import logger from "./logger"

export const ERC20_FUNCTIONS = {
allowance: FunctionFragment.from(
Expand Down Expand Up @@ -93,19 +94,24 @@ export async function getMetadata(
provider
)

const [symbol, name, decimals] = await Promise.all(
[
ERC20_FUNCTIONS.symbol,
ERC20_FUNCTIONS.name,
ERC20_FUNCTIONS.decimals,
].map(({ name: functionName }) => token.callStatic[functionName]())
)
try {
const [symbol, name, decimals] = await Promise.all(
[
ERC20_FUNCTIONS.symbol,
ERC20_FUNCTIONS.name,
ERC20_FUNCTIONS.decimals,
].map(({ name: functionName }) => token.callStatic[functionName]())
)

return {
...tokenSmartContract,
symbol,
name,
decimals,
return {
...tokenSmartContract,
symbol,
name,
decimals,
}
} catch (error) {
logger.warn("Invalid metadata for token", tokenSmartContract)
throw new Error("Could not retrieve erc20 token metadata")
}
}

Expand Down
11 changes: 3 additions & 8 deletions background/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,8 @@ export default class Main extends BaseService<never> {
network,
}
await this.chainService.addAccountToTrack(addressNetwork)
this.abilitiesService.getNewAccountAbilities(address)

this.store.dispatch(loadAccount(addressNetwork))
})
)
Expand Down Expand Up @@ -1081,6 +1083,7 @@ export default class Main extends BaseService<never> {
address,
network,
})
this.abilitiesService.getNewAccountAbilities(address)
})
})

Expand Down Expand Up @@ -1566,14 +1569,6 @@ export default class Main extends BaseService<never> {
this.abilitiesService.emitter.on("deleteAccount", (address) => {
this.store.dispatch(deleteAccountFilter(address))
})

this.keyringService.emitter.on("address", (address) =>
this.abilitiesService.getNewAccountAbilities(address)
)

this.ledgerService.emitter.on("address", ({ address }) =>
this.abilitiesService.getNewAccountAbilities(address)
)
}

async unlockKeyrings(password: string): Promise<boolean> {
Expand Down
1 change: 0 additions & 1 deletion background/redux-slices/abilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const abilitiesSlice = createSlice({
immerState.abilities[address][ability.abilityId]
immerState.abilities[address][ability.abilityId] = {
...ability,
completed: existingAbility.completed,
removedFromUi: existingAbility.removedFromUi,
}
} else {
Expand Down
5 changes: 4 additions & 1 deletion background/services/abilities/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ export class AbilitiesDatabase extends Dexie {
id: number
}
if (JSON.stringify(correctAbility) !== JSON.stringify(ability)) {
const updateCompleted =
ability.completed === true && existingAbility.completed === false

await this.abilities.update(existingAbility, {
...ability,
completed: existingAbility.completed,
completed: updateCompleted ? true : existingAbility.completed,
removedFromUi: existingAbility.removedFromUi,
})
return true
Expand Down
2 changes: 1 addition & 1 deletion background/services/abilities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const normalizeDaylightAbilities = (
imageUrl: daylightAbility.imageUrl || undefined,
openAt: daylightAbility.openAt || undefined,
closeAt: daylightAbility.closeAt || undefined,
completed: false,
completed: daylightAbility.walletCompleted || false,
removedFromUi: false,
address: normalizeEVMAddress(address),
requirement: normalizeDaylightRequirements(
Expand Down
11 changes: 9 additions & 2 deletions background/services/enrichment/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,17 @@ export default async function resolveTransactionAnnotation(
(gasLimit ?? 0n) +
additionalL1Gas

txAnnotation.warnings ??= []

// If the wallet doesn't have enough base asset to cover gas, push a warning
if (gasFee + (transaction.value ?? 0n) > baseAssetBalance) {
txAnnotation.warnings ??= []
txAnnotation.warnings.push("insufficient-funds")
if (!txAnnotation.warnings.includes("insufficient-funds")) {
txAnnotation.warnings.push("insufficient-funds")
}
} else {
txAnnotation.warnings = txAnnotation.warnings.filter(
(warning) => warning !== "insufficient-funds"
)
}

// If the transaction has been mined, get the block and set the timestamp
Expand Down
42 changes: 42 additions & 0 deletions background/services/indexing/tests/index.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,47 @@ describe("IndexingService", () => {
).toEqual(["ETH", customAsset.symbol, "TEST"])
})

// Check that we're using proper token ids for built in network assets
// TODO: Remove once we add an e2e test for balances
it("should query builtin network asset prices", async () => {
const indexingDb = await getIndexingDB()

const smartContractAsset = createSmartContractAsset()

await indexingDb.saveTokenList(
"https://gateway.ipfs.io/ipns/tokens.uniswap.org",
tokenList
)

await indexingDb.addAssetToTrack(smartContractAsset)

const spy = getPrivateMethodSpy<IndexingService["handlePriceAlarm"]>(
indexingService,
"handlePriceAlarm"
)

await Promise.all([
chainService.startService(),
indexingService.startService(),
])

await indexingService.emitter.once("assets")

expect(spy).toHaveBeenCalled()

await spy.mock.results[0].value

expect(fetchJsonStub.getCalls()).toContainEqual(
expect.objectContaining({
args: [
expect.stringMatching(
/ethereum,matic-network,rootstock,avalanche-2,binancecoin/i
),
],
})
)
})

it("should not retrieve token prices for custom assets", async () => {
const indexingDb = await getIndexingDB()

Expand Down Expand Up @@ -296,6 +337,7 @@ describe("IndexingService", () => {
expect(spy).toHaveBeenCalled()

await spy.mock.results[0].value

expect(getTokenPricesSpy).toHaveBeenCalledWith(
[smartContractAsset.contractAddress],
{ name: "United States Dollar", symbol: "USD", decimals: 10 },
Expand Down
6 changes: 3 additions & 3 deletions manifest/manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "Taho",
"version": "0.27.1",
"version": "0.27.2",
"description": "The community owned and operated Web3 wallet.",
"homepage_url": "https://tally.cash",
"author": "https://tally.cash",
"homepage_url": "https://taho.xyz",
"author": "https://taho.xyz",
"manifest_version": 2,
"content_security_policy": "object-src 'self'; script-src 'self';",
"web_accessible_resources": ["*.js", "*.json"],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tallyho/tally-extension",
"private": true,
"version": "0.27.1",
"version": "0.27.2",
"description": "Taho, the community owned and operated Web3 wallet.",
"main": "index.js",
"repository": "[email protected]:thesis/tally-extension.git",
Expand Down
Loading

0 comments on commit b4b1835

Please sign in to comment.