This repository has been archived by the owner on Jul 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Celo coin with Sync and Send features (#1536)
* Add Celo family with Sync and Send features * Remove Operation types related to staking * Add speculos bot specs * Display an error if receipient address is invalid * Add deviceTransactionConfig.ts to display send transaction confirmation data * Add CELO svg icon * Remove Method from transaction confirmation fields * Refactoring - code review feedback * Fix Celo Contractkit populate method bug, add send max spec * Use erc20 for Celo token to fix precision issues * Update Celo indexer/node API urls * Use Celo Gold contract for fee estimations * Fix estimating fee on sending max amount * Fix linting
- Loading branch information
1 parent
0f104e9
commit b9b4d7d
Showing
42 changed files
with
3,473 additions
and
137 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,4 +56,5 @@ setSupportedCurrencies([ | |
"crypto_org", | ||
"filecoin", | ||
"solana", | ||
"celo", | ||
]); |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { BigNumber } from "bignumber.js"; | ||
import network from "../../../network"; | ||
import { getEnv } from "../../../env"; | ||
import { Operation, OperationType } from "../../../types"; | ||
import { encodeOperationId } from "../../../operation"; | ||
|
||
const DEFAULT_TRANSACTIONS_LIMIT = 200; | ||
const getUrl = (route): string => `${getEnv("API_CELO_INDEXER")}${route || ""}`; | ||
|
||
// Indexer returns both account data and transactions in one call. | ||
// Transactions are just limited, there's no block height offset | ||
const fetchAccountDetails = async ( | ||
address: string, | ||
transactionsLimit: number = DEFAULT_TRANSACTIONS_LIMIT | ||
) => { | ||
const { data } = await network({ | ||
method: "GET", | ||
url: getUrl(`/account_details/${address}?limit=${transactionsLimit}`), | ||
}); | ||
return data; | ||
}; | ||
|
||
const fetchStatus = async () => { | ||
const { data } = await network({ | ||
method: "GET", | ||
url: getUrl(`/status`), | ||
}); | ||
return data; | ||
}; | ||
|
||
const getOperationType = (type: string): OperationType => { | ||
switch (type) { | ||
case "InternalTransferSent": | ||
return "OUT"; | ||
case "InternalTransferReceived": | ||
return "IN"; | ||
case "AccountSlashed": | ||
return "SLASH"; | ||
default: | ||
return "NONE"; | ||
} | ||
}; | ||
|
||
const transactionToOperation = ( | ||
address: string, | ||
accountId: string, | ||
transaction | ||
): Operation => { | ||
const type: OperationType = getOperationType(transaction.kind); | ||
const hasFailed = transaction.data.success | ||
? !transaction.data.success | ||
: false; | ||
const senders = transaction.data.from ? [transaction.data.from] : []; | ||
const recipients = transaction.data.to ? [transaction.data.to] : []; | ||
|
||
return { | ||
id: encodeOperationId(accountId, transaction.transaction_hash, type), | ||
hash: transaction.transaction_hash, | ||
accountId, | ||
fee: new BigNumber(0), | ||
value: new BigNumber(transaction.amount), | ||
type, | ||
blockHeight: transaction.height, | ||
date: new Date(transaction.time), | ||
senders, | ||
recipients, | ||
hasFailed, | ||
blockHash: null, | ||
extra: {}, | ||
}; | ||
}; | ||
|
||
export const getAccountDetails = async (address: string, accountId: string) => { | ||
const accountDetails = await fetchAccountDetails(address); | ||
const spendableBalance = new BigNumber(accountDetails.gold_balance); | ||
const lockedBalance = new BigNumber(accountDetails.total_locked_gold); | ||
const balance = spendableBalance.plus(lockedBalance); | ||
const indexerStatus = await fetchStatus(); | ||
|
||
const allTransactions = accountDetails.internal_transfers.concat( | ||
accountDetails.transactions | ||
); | ||
const operations = allTransactions.map((transaction) => | ||
transactionToOperation(address, accountId, transaction) | ||
); | ||
|
||
return { | ||
blockHeight: indexerStatus.last_indexed_height, | ||
balance, | ||
spendableBalance, | ||
operations, | ||
}; | ||
}; |
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 @@ | ||
export { getAccountDetails } from "./hubble"; |
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,8 @@ | ||
import { ContractKit, newKit } from "@celo/contractkit"; | ||
import { getEnv } from "../../../env"; | ||
|
||
let kit: ContractKit; | ||
export const celoKit = () => { | ||
if (!kit) kit = newKit(getEnv("API_CELO_NODE")); | ||
return kit; | ||
}; |
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,38 @@ | ||
import type { AccountBridge, CurrencyBridge } from "../../../types"; | ||
import type { Transaction } from "../types"; | ||
import { makeAccountBridgeReceive } from "../../../bridge/jsHelpers"; | ||
import { sync, scanAccounts } from "../js-synchronisation"; | ||
import signOperation from "../js-signOperation"; | ||
import getTransactionStatus from "../js-getTransactionStatus"; | ||
import broadcast from "../js-broadcast"; | ||
import estimateMaxSpendable from "../js-estimateMaxSpendable"; | ||
import prepareTransaction from "../js-prepareTransaction"; | ||
import createTransaction from "../js-createTransaction"; | ||
|
||
const updateTransaction = (t, patch) => ({ ...t, ...patch }); | ||
|
||
const receive = makeAccountBridgeReceive(); | ||
|
||
const preload = async () => Promise.resolve({}); | ||
const hydrate = (): void => {}; | ||
|
||
const currencyBridge: CurrencyBridge = { | ||
preload, | ||
hydrate, | ||
scanAccounts, | ||
}; | ||
const accountBridge: AccountBridge<Transaction> = { | ||
estimateMaxSpendable, | ||
createTransaction, | ||
updateTransaction, | ||
getTransactionStatus, | ||
prepareTransaction, | ||
sync, | ||
receive, | ||
signOperation, | ||
broadcast, | ||
}; | ||
export default { | ||
currencyBridge, | ||
accountBridge, | ||
}; |
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,41 @@ | ||
import invariant from "invariant"; | ||
import flatMap from "lodash/flatMap"; | ||
|
||
import type { | ||
Transaction, | ||
Account, | ||
AccountLike, | ||
AccountLikeArray, | ||
} from "../../types"; | ||
|
||
const options = []; | ||
|
||
function inferAccounts(account: Account): AccountLikeArray { | ||
invariant(account.currency.family === "celo", "celo family"); | ||
|
||
const accounts: Account[] = [account]; | ||
return accounts; | ||
} | ||
|
||
function inferTransactions( | ||
transactions: Array<{ | ||
account: AccountLike; | ||
transaction: Transaction; | ||
mainAccount: Account; | ||
}> | ||
): Transaction[] { | ||
return flatMap(transactions, ({ transaction }) => { | ||
invariant(transaction.family === "celo", "celo family"); | ||
|
||
return { | ||
...transaction, | ||
family: "celo", | ||
} as Transaction; | ||
}); | ||
} | ||
|
||
export default { | ||
options, | ||
inferAccounts, | ||
inferTransactions, | ||
}; |
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,20 @@ | ||
import type { CurrenciesData } from "../../../types"; | ||
import type { Transaction } from "../types"; | ||
|
||
const dataset: CurrenciesData<Transaction> = { | ||
scanAccounts: [ | ||
{ | ||
name: "celo seed 1", | ||
apdus: ` | ||
=> e002000009028000002c8000ce10 | ||
<= 41040106794f46b69e1ae56dff904510959e59074a37341f8cc740e9ce7a0b24421c42e7023481f5ef03926739baa6bb26cac7bf48f249a24793264711d48499499528433235323935323541463035434134313939633236413838623438393463383342303330433733399000 | ||
=> e002000015058000002c8000ce10800000000000000000000000 | ||
<= 41044f4998c3f81966645f25e95082f9fe7d104b1ba4286486a8ecd8fd11f79ef02bd8110f086b390a418ab619a650f3df59a3c84912ce1ea125386d7aa7732fcd0b28393634313334336638346535304143304334434133626644313244433063346231653732363544359000 | ||
=> e002000015058000002c8000ce10800000010000000000000000 | ||
<= 4104630b6447b0f690520a5612f1dc57da90b84f6b59dfeb375bed1113fb34a8d0f9181ec63e40f9fde05761084dbd022ba76711eb2b36442cf4b5d2bc19def9156428343435306565646238623532333931354534393639633239646241653944354563303646453837349000 | ||
`, | ||
}, | ||
], | ||
}; | ||
|
||
export default dataset; |
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,19 @@ | ||
import type { DeviceTransactionField } from "../../transaction"; | ||
|
||
function getDeviceTransactionConfig(): Array<DeviceTransactionField> { | ||
const fields: Array<DeviceTransactionField> = []; | ||
|
||
fields.push({ | ||
type: "amount", | ||
label: "Amount", | ||
}); | ||
|
||
fields.push({ | ||
type: "fees", | ||
label: "Fees", | ||
}); | ||
|
||
return fields; | ||
} | ||
|
||
export default getDeviceTransactionConfig; |
Oops, something went wrong.
b9b4d7d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: